Skip to content

Commit

Permalink
Add --validate-only flag to run validate-only pipeline update (#1251)
Browse files Browse the repository at this point in the history
## Changes

This flag starts a "validation-only" update.

## Tests

Unit and manual confirmation it does what it should.
  • Loading branch information
pietern authored Mar 4, 2024
1 parent 58e1db5 commit 0482768
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bundle/run/pipeline_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ type PipelineOptions struct {

// List of tables to reset and recompute.
FullRefresh []string

// Perform an update to validate graph correctness.
ValidateOnly bool
}

func (o *PipelineOptions) Define(fs *flag.FlagSet) {
fs.BoolVar(&o.RefreshAll, "refresh-all", false, "Perform a full graph 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.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.
Expand All @@ -46,6 +50,9 @@ func (o *PipelineOptions) Validate(pipeline *resources.Pipeline) error {
if len(o.FullRefresh) > 0 {
set = append(set, "--full-refresh")
}
if o.ValidateOnly {
set = append(set, "--validate-only")
}
if len(set) > 1 {
return fmt.Errorf("pipeline run arguments are mutually exclusive (got %s)", strings.Join(set, ", "))
}
Expand All @@ -63,6 +70,7 @@ func (o *PipelineOptions) toPayload(pipeline *resources.Pipeline, pipelineID str
RefreshSelection: o.Refresh,
FullRefresh: o.FullRefreshAll,
FullRefreshSelection: o.FullRefresh,
ValidateOnly: o.ValidateOnly,
}
return payload, nil
}
9 changes: 9 additions & 0 deletions bundle/run/pipeline_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@ func TestPipelineOptionsFullRefresh(t *testing.T) {
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) {
args := []string{
`--refresh-all`,
`--refresh=arg1,arg2,arg3`,
`--full-refresh-all`,
`--full-refresh=arg1,arg2,arg3`,
`--validate-only`,
}
for _, arg := range args {
fs, opts := setupPipelineOptions(t)
Expand All @@ -65,6 +73,7 @@ func TestPipelineOptionsValidateFailureWithMultipleOptions(t *testing.T) {
`--refresh=arg1,arg2,arg3`,
`--full-refresh-all`,
`--full-refresh=arg1,arg2,arg3`,
`--validate-only`,
}
for i := range args {
for j := range args {
Expand Down

0 comments on commit 0482768

Please sign in to comment.