-
Notifications
You must be signed in to change notification settings - Fork 69
/
resource_run_cmd.go
104 lines (85 loc) 路 3.4 KB
/
resource_run_cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package cmd
import (
"context"
"fmt"
"strings"
"github.com/kubeshop/tracetest/cli/cmdutil"
"github.com/kubeshop/tracetest/cli/config"
"github.com/kubeshop/tracetest/cli/openapi"
"github.com/kubeshop/tracetest/cli/runner"
"github.com/spf13/cobra"
cloudCmd "github.com/kubeshop/tracetest/cli/cloud/cmd"
)
var (
runParams = &cmdutil.RunParameters{}
runCmd *cobra.Command
)
func init() {
runCmd = &cobra.Command{
GroupID: cmdGroupResources.ID,
Use: fmt.Sprintf("run [%s]", runnableResourceList()),
Short: "Run tests and test suites",
Long: "Run tests and test suites",
PreRun: setupCommand(WithOptionalResourceName()),
Run: WithResourceMiddleware(func(ctx context.Context, _ *cobra.Command, args []string) (string, error) {
runParams.ResourceName = resourceParams.ResourceName
if cliConfig.Jwt != "" {
exitCode, err := cloudCmd.RunMultipleFiles(ctx, httpClient, runParams, &cliConfig, runnerRegistry, output)
ExitCLI(exitCode)
return "", err
}
return runSingleFile(ctx)
}, runParams),
PostRun: teardownCommand,
}
runCmd.Flags().StringSliceVarP(&runParams.DefinitionFiles, "file", "f", []string{}, "path to the definition file (can be defined multiple times)")
runCmd.Flags().StringSliceVarP(&runParams.IDs, "id", "", []string{}, "id of the resource to run (can be defined multiple times)")
runCmd.Flags().StringVarP(&runParams.VarsID, "vars", "", "", "variable set file or ID to be used")
runCmd.Flags().StringVarP(&runParams.RunGroupID, "group", "g", "", "Sets the Run Group ID for the run. This is used to group multiple runs together.")
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.RequiredGates, "required-gates", []string{}, "override default required gate. "+validRequiredGatesMsg())
//deprecated
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)
}
func runSingleFile(ctx context.Context) (string, error) {
orchestrator := runner.Orchestrator(
cliLogger,
config.GetAPIClient(cliConfig),
variableSetClient,
runnerRegistry,
)
if runParams.EnvID != "" {
runParams.VarsID = runParams.EnvID
}
var definitionFile string
if len(runParams.DefinitionFiles) > 0 {
definitionFile = runParams.DefinitionFiles[0]
}
ID := ""
if len(runParams.IDs) > 0 {
ID = runParams.IDs[0]
}
runParams := runner.RunOptions{
ID: ID,
DefinitionFile: definitionFile,
VarsID: runParams.VarsID,
SkipResultWait: runParams.SkipResultWait,
JUnitOuptutFile: runParams.JUnitOuptutFile,
RequiredGates: runParams.RequiredGates,
}
exitCode, err := orchestrator.Run(ctx, runParams, output)
ExitCLI(exitCode)
// ExitCLI will exit the process, so this return is just to satisfy the compiler
return "", err
}
func validRequiredGatesMsg() string {
opts := make([]string, 0, len(openapi.AllowedSupportedGatesEnumValues))
for _, v := range openapi.AllowedSupportedGatesEnumValues {
opts = append(opts, string(v))
}
return "valid options: " + strings.Join(opts, ", ")
}