-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(cli): Adding support for Variable Sets #3018
chore(cli): Adding support for Variable Sets #3018
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overall PR is ok, but I'm missing one CLI e2e test: we should have a scenario to run a test using vars in the old format and the new one, just to guarantee that we are not breaking existing tests for our customers.
One example of test that does that is here: https://github.com/kubeshop/tracetest/blob/main/testing/cli-e2etest/testscenarios/test/run_test_test.go#L40
@@ -63,7 +63,7 @@ func init() { | |||
|
|||
runCmd.Flags().StringVarP(&runParams.DefinitionFile, "file", "f", "", "path to the definition file") | |||
runCmd.Flags().StringVar(&runParams.ID, "id", "", "id of the resource to run") | |||
runCmd.Flags().StringVarP(&runParams.EnvID, "environment", "e", "", "environment file or ID to be used") | |||
runCmd.Flags().StringVarP(&runParams.VarsID, "vars", "", "", "variable set file or ID to be used") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to be variableset
here?
runCmd.Flags().StringVarP(&runParams.VarsID, "vars", "", "", "variable set file or ID to be used") | |
runCmd.Flags().StringVarP(&runParams.VarsID, "variableset", "", "", "variable set file or ID to be used") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we were using a shorthand for environments, I thought we could continue using the same approach
@@ -84,8 +82,8 @@ func (p *resourceParameters) Validate(cmd *cobra.Command, args []string) []error | |||
|
|||
p.ResourceName = args[0] | |||
|
|||
_, err := resources.Get(p.ResourceName) | |||
if errors.Is(err, resourcemanager.ErrResourceNotFound) { | |||
exists := resources.Exists(p.ResourceName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to use a different function because Get
now writes the warning to the console if deprecated
@@ -63,7 +63,7 @@ func init() { | |||
|
|||
runCmd.Flags().StringVarP(&runParams.DefinitionFile, "file", "f", "", "path to the definition file") | |||
runCmd.Flags().StringVar(&runParams.ID, "id", "", "id of the resource to run") | |||
runCmd.Flags().StringVarP(&runParams.EnvID, "environment", "e", "", "environment file or ID to be used") | |||
runCmd.Flags().StringVarP(&runParams.VarsID, "vars", "", "", "variable set file or ID to be used") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we were using a shorthand for environments, I thought we could continue using the same approach
runCmd.Flags().BoolVarP(&runParams.SkipResultWait, "skip-result-wait", "W", false, "do not wait for results. exit immediately after test run started") | ||
runCmd.Flags().StringVarP(&runParams.JUnitOuptutFile, "junit", "j", "", "file path to save test results in junit format") | ||
runCmd.Flags().StringSliceVar(&runParams.RequriedGates, "required-gates", []string{}, "override default required gate. "+validRequiredGatesMsg()) | ||
|
||
//deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still supporting this in case users need it
resourcemanager.WithTableConfig(resourcemanager.TableConfig{ | ||
Cells: []resourcemanager.TableCellConfig{ | ||
{Header: "ID", Path: "spec.id"}, | ||
{Header: "NAME", Path: "spec.name"}, | ||
{Header: "DESCRIPTION", Path: "spec.description"}, | ||
}, | ||
}), | ||
resourcemanager.WithResourceType("VariableSet"), | ||
resourcemanager.WithApplyPreProcessor(variableSetPreprocessor.Preprocess), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preprocessor to switch Environment
to VariableSet
and DeprecatedAlias to pass the resourceType
validations
deprecatedEnvironmentClient = resourcemanager.NewClient( | ||
httpClient, cliLogger, | ||
"environment", "environments", | ||
resourcemanager.WithProxyResource("variableset"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used to create an entry in the registry that will point to the variable set client
@@ -30,13 +31,33 @@ func (r *Registry) Get(resourceName string) (Client, error) { | |||
return Client{}, ErrResourceNotFound | |||
} | |||
|
|||
if c.options.proxyResource != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If proxy, check if the proxied resource exists
for k := range r.resources { | ||
resources = append(resources, k) | ||
for k, c := range r.resources { | ||
if c.options.proxyResource == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleting the proxy resources from the list
return input, fmt.Errorf("could not unmarshal test yaml: %w", err) | ||
} | ||
|
||
if resource.Type == "Environment" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updates Environment to VariableSet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to add a //TODO
comment saying that this mapping will be removed in future versions?
@@ -17,6 +18,14 @@ test: # run tests for this application | |||
go clean -testcache; \ | |||
go test -v -timeout 300s -p 1 ./...; | |||
|
|||
test/scenario: # run tests for this application |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will allows us execute a single testscenario
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! 🎉
@@ -85,20 +85,47 @@ func TestRunTestWithHttpTriggerAndEnvironmentFile(t *testing.T) { | |||
require.Equal("https://assets.pokemon.com/assets/cms2/img/pokedex/full/143.png", environmentVars.Spec.Values[1].Value) | |||
}) | |||
|
|||
t.Run("should pass when using environment id", func(t *testing.T) { | |||
t.Run("should pass when using the deprecated environment definition file", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a test to validate that the old way still works as expected
@danielbdias I added this test To validate that the old way of using envs works as expected |
return input, fmt.Errorf("could not unmarshal test yaml: %w", err) | ||
} | ||
|
||
if resource.Type == "Environment" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to add a //TODO
comment saying that this mapping will be removed in future versions?
@@ -17,6 +18,14 @@ test: # run tests for this application | |||
go clean -testcache; \ | |||
go test -v -timeout 300s -p 1 ./...; | |||
|
|||
test/scenario: # run tests for this application |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can we name these files with smallcaps? (variableset instead of variableSet)
7dbc458
into
3000-rename-environments-to-variables
* chore(backend) Updating Environment to Variable Set (#3007) * chore(backend) Updating Environment to Variable Set * Updating open api * chore(frotend): Updating Environment to Variable Set (#3012) * chore(backend) Updating Environment to Variable Set * chore(frotend): Updating Environment to Variable Set * PR comments * chore(cli): Adding support for Variable Sets (#3018) * chore(cli): Adding support for Variable Sets * chore(cli): Fixing automated tests * chore(cli): Updating UI * adding environment backwards compability and tests * adding environment backwards compability and tests * PR review update
This PR updates the CLI and fixes all of the automated tests to work with the new variable set changes
Changes
Fixes
Checklist
https://www.loom.com/share/ccd34203368e4b9ba921ce8530cfb258