From 04827688fb2fb51a191a8d8a1dbb0cdb29b70b90 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Mon, 4 Mar 2024 09:38:32 +0100 Subject: [PATCH] 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. --- bundle/run/pipeline_options.go | 8 ++++++++ bundle/run/pipeline_options_test.go | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/bundle/run/pipeline_options.go b/bundle/run/pipeline_options.go index 4917f9db..6c8c1e8c 100644 --- a/bundle/run/pipeline_options.go +++ b/bundle/run/pipeline_options.go @@ -22,6 +22,9 @@ 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) { @@ -29,6 +32,7 @@ func (o *PipelineOptions) Define(fs *flag.FlagSet) { 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. @@ -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, ", ")) } @@ -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 } diff --git a/bundle/run/pipeline_options_test.go b/bundle/run/pipeline_options_test.go index 3048a4d8..b42de8c0 100644 --- a/bundle/run/pipeline_options_test.go +++ b/bundle/run/pipeline_options_test.go @@ -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) @@ -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 {