Skip to content

Commit

Permalink
feat(cli): fixing deprecated environment flag (#3039)
Browse files Browse the repository at this point in the history
* feat(cli): fixing deprecated environment flag

* feat(cli): fixing deprecated environment flag
  • Loading branch information
xoscar authored and danielbdias committed Aug 11, 2023
1 parent ba94952 commit ec1e5d5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cli/cmd/resource_run_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func init() {
runCmd.Flags().StringSliceVar(&runParams.RequriedGates, "required-gates", []string{}, "override default required gate. "+validRequiredGatesMsg())

//deprecated
runCmd.Flags().StringVarP(&runParams.EnvID, "env", "e", "", "environment file or ID to be used")
runCmd.Flags().MarkDeprecated("env", "use --vars instead")
runCmd.Flags().StringVarP(&runParams.EnvID, "environment", "e", "", "environment file or ID to be used")
runCmd.Flags().MarkDeprecated("environment", "use --vars instead")
runCmd.Flags().MarkShorthandDeprecated("e", "use --vars instead")

rootCmd.AddCommand(runCmd)
Expand Down
36 changes: 35 additions & 1 deletion testing/cli-e2etest/testscenarios/test/run_test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestRunTestWithHttpTriggerAndVariableSetFile(t *testing.T) {
environmentFile := env.GetTestResourcePath(t, "deprecated-environment")
testFile := env.GetTestResourcePath(t, "http-trigger-with-environment-file")

command := fmt.Sprintf("run test -f %s --env %s", testFile, environmentFile)
command := fmt.Sprintf("run test -f %s --environment %s", testFile, environmentFile)
result = tracetestcli.Exec(t, command, tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)
require.Contains(result.StdOut, "✔ It should add a Pokemon correctly")
Expand Down Expand Up @@ -145,6 +145,40 @@ func TestRunTestWithHttpTriggerAndVariableSetFile(t *testing.T) {
require.Contains(result.StdOut, "✔ It should add a Pokemon correctly")
require.Contains(result.StdOut, "✔ It should save the correct data")
})

t.Run("should pass when using variable set id but using the old environment flag", func(t *testing.T) {
// Given I am a Tracetest CLI user
// And I have my server recently created
// And the datasource is already set

// When I create a variable set
// Then it should be created correctly
environmentFile := env.GetTestResourcePath(t, "variableSet-file")

result := tracetestcli.Exec(t, fmt.Sprintf("apply variableset --file %s", environmentFile), tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)

environmentVars := helpers.UnmarshalYAML[types.VariableSetResource](t, result.StdOut)
require.Equal("VariableSet", environmentVars.Type)
require.Equal("pokeapi-env", environmentVars.Spec.ID)
require.Equal("pokeapi-env", environmentVars.Spec.Name)
require.Len(environmentVars.Spec.Values, 2)
require.Equal("POKEMON_NAME", environmentVars.Spec.Values[0].Key)
require.Equal("snorlax", environmentVars.Spec.Values[0].Value)
require.Equal("POKEMON_URL", environmentVars.Spec.Values[1].Key)
require.Equal("https://assets.pokemon.com/assets/cms2/img/pokedex/full/143.png", environmentVars.Spec.Values[1].Value)

// When I try to run a test with a http trigger and a variable set id
// Then it should pass

testFile := env.GetTestResourcePath(t, "http-trigger-with-environment-file")

command := fmt.Sprintf("run test -f %s --environment pokeapi-env", testFile)
result = tracetestcli.Exec(t, command, tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)
require.Contains(result.StdOut, "✔ It should add a Pokemon correctly")
require.Contains(result.StdOut, "✔ It should save the correct data")
})
}

func TestRunTestWithGrpcTrigger(t *testing.T) {
Expand Down

0 comments on commit ec1e5d5

Please sign in to comment.