Add `--validate-only` flag to run validate-only pipeline update (#1251)

## Changes

This flag starts a "validation-only" update.

## Tests

Unit and manual confirmation it does what it should.
This commit is contained in:
Pieter Noordhuis 2024-03-04 09:38:32 +01:00 committed by GitHub
parent 58e1db58b1
commit 04827688fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -22,6 +22,9 @@ type PipelineOptions struct {
// List of tables to reset and recompute. // List of tables to reset and recompute.
FullRefresh []string FullRefresh []string
// Perform an update to validate graph correctness.
ValidateOnly bool
} }
func (o *PipelineOptions) Define(fs *flag.FlagSet) { func (o *PipelineOptions) Define(fs *flag.FlagSet) {
@ -29,6 +32,7 @@ func (o *PipelineOptions) Define(fs *flag.FlagSet) {
fs.StringSliceVar(&o.Refresh, "refresh", nil, "List of tables to update.") fs.StringSliceVar(&o.Refresh, "refresh", nil, "List of tables to update.")
fs.BoolVar(&o.FullRefreshAll, "full-refresh-all", false, "Perform a full graph reset and recompute.") fs.BoolVar(&o.FullRefreshAll, "full-refresh-all", false, "Perform a full graph reset and recompute.")
fs.StringSliceVar(&o.FullRefresh, "full-refresh", nil, "List of tables to reset and recompute.") fs.StringSliceVar(&o.FullRefresh, "full-refresh", nil, "List of tables to reset and recompute.")
fs.BoolVar(&o.ValidateOnly, "validate-only", false, "Perform an update to validate graph correctness.")
} }
// Validate returns if the combination of options is valid. // Validate returns if the combination of options is valid.
@ -46,6 +50,9 @@ func (o *PipelineOptions) Validate(pipeline *resources.Pipeline) error {
if len(o.FullRefresh) > 0 { if len(o.FullRefresh) > 0 {
set = append(set, "--full-refresh") set = append(set, "--full-refresh")
} }
if o.ValidateOnly {
set = append(set, "--validate-only")
}
if len(set) > 1 { if len(set) > 1 {
return fmt.Errorf("pipeline run arguments are mutually exclusive (got %s)", strings.Join(set, ", ")) return fmt.Errorf("pipeline run arguments are mutually exclusive (got %s)", strings.Join(set, ", "))
} }
@ -63,6 +70,7 @@ func (o *PipelineOptions) toPayload(pipeline *resources.Pipeline, pipelineID str
RefreshSelection: o.Refresh, RefreshSelection: o.Refresh,
FullRefresh: o.FullRefreshAll, FullRefresh: o.FullRefreshAll,
FullRefreshSelection: o.FullRefresh, FullRefreshSelection: o.FullRefresh,
ValidateOnly: o.ValidateOnly,
} }
return payload, nil return payload, nil
} }

View File

@ -43,12 +43,20 @@ func TestPipelineOptionsFullRefresh(t *testing.T) {
assert.Equal(t, []string{"arg1", "arg2", "arg3"}, opts.FullRefresh) assert.Equal(t, []string{"arg1", "arg2", "arg3"}, opts.FullRefresh)
} }
func TestPipelineOptionsValidateOnly(t *testing.T) {
fs, opts := setupPipelineOptions(t)
err := fs.Parse([]string{`--validate-only`})
require.NoError(t, err)
assert.True(t, opts.ValidateOnly)
}
func TestPipelineOptionsValidateSuccessWithSingleOption(t *testing.T) { func TestPipelineOptionsValidateSuccessWithSingleOption(t *testing.T) {
args := []string{ args := []string{
`--refresh-all`, `--refresh-all`,
`--refresh=arg1,arg2,arg3`, `--refresh=arg1,arg2,arg3`,
`--full-refresh-all`, `--full-refresh-all`,
`--full-refresh=arg1,arg2,arg3`, `--full-refresh=arg1,arg2,arg3`,
`--validate-only`,
} }
for _, arg := range args { for _, arg := range args {
fs, opts := setupPipelineOptions(t) fs, opts := setupPipelineOptions(t)
@ -65,6 +73,7 @@ func TestPipelineOptionsValidateFailureWithMultipleOptions(t *testing.T) {
`--refresh=arg1,arg2,arg3`, `--refresh=arg1,arg2,arg3`,
`--full-refresh-all`, `--full-refresh-all`,
`--full-refresh=arg1,arg2,arg3`, `--full-refresh=arg1,arg2,arg3`,
`--validate-only`,
} }
for i := range args { for i := range args {
for j := range args { for j := range args {