Skip to content

Commit

Permalink
Adding validation to verify that refresh state is not present with co…
Browse files Browse the repository at this point in the history
…nfig or destroy in a test step (#1069)
  • Loading branch information
bendbennett committed Oct 11, 2022
1 parent 0f220c8 commit 4be309c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions helper/resource/teststep_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func (s TestStep) hasProviders(_ context.Context) bool {
// validate ensures the TestStep is valid based on the following criteria:
//
// - Config or ImportState or RefreshState is set.
// - Config and RefreshState are not both set.
// - RefreshState and Destroy are not both set.
// - RefreshState is not the first TestStep.
// - Providers are not specified (ExternalProviders,
// ProtoV5ProviderFactories, ProtoV6ProviderFactories, ProviderFactories)
Expand All @@ -65,6 +67,18 @@ func (s TestStep) validate(ctx context.Context, req testStepValidateRequest) err
return err
}

if s.Config != "" && s.RefreshState {
err := fmt.Errorf("TestStep cannot have Config and RefreshState")
logging.HelperResourceError(ctx, "TestStep validation error", map[string]interface{}{logging.KeyError: err})
return err
}

if s.RefreshState && s.Destroy {
err := fmt.Errorf("TestStep cannot have RefreshState and Destroy")
logging.HelperResourceError(ctx, "TestStep validation error", map[string]interface{}{logging.KeyError: err})
return err
}

if s.RefreshState && req.StepNumber == 1 {
err := fmt.Errorf("TestStep cannot have RefreshState as first step")
logging.HelperResourceError(ctx, "TestStep validation error", map[string]interface{}{logging.KeyError: err})
Expand Down

0 comments on commit 4be309c

Please sign in to comment.