Skip to content

Commit

Permalink
feat: passing binary args (#993)
Browse files Browse the repository at this point in the history
  • Loading branch information
exu authored Feb 21, 2022
1 parent 60cdaf4 commit 4a103be
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 8 deletions.
9 changes: 9 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,15 @@ components:
example:
users: "3"
prefix: "some-"
args:
type: array
description: "additional executor binary arguments"
items:
type: string
example:
- "--repeats"
- "5"
- "--insecure"
tags:
type: array
items:
Expand Down
4 changes: 3 additions & 1 deletion cmd/kubectl-testkube/commands/tests/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func NewRunTestCmd() *cobra.Command {
var (
name string
watchEnabled bool
binaryArgs []string
params map[string]string
paramsFileContent string
downloadArtifactsEnabled bool
Expand All @@ -38,7 +39,7 @@ func NewRunTestCmd() *cobra.Command {
client, namespace := common.GetClient(cmd)
namespacedName := fmt.Sprintf("%s/%s", namespace, testName)

execution, err := client.ExecuteTest(testName, namespace, name, params, paramsFileContent)
execution, err := client.ExecuteTest(testName, namespace, name, params, paramsFileContent, binaryArgs)
ui.ExitOnError("starting test execution "+namespacedName, err)

printExecutionDetails(execution)
Expand All @@ -64,6 +65,7 @@ func NewRunTestCmd() *cobra.Command {
cmd.Flags().StringVarP(&name, "name", "n", "", "execution name, if empty will be autogenerated")
cmd.Flags().StringVarP(&paramsFileContent, "params-file", "", "", "params file path, e.g. postman env file - will be passed to executor if supported")
cmd.Flags().StringToStringVarP(&params, "param", "p", map[string]string{}, "execution envs passed to executor")
cmd.Flags().StringArrayVarP(&binaryArgs, "args", "a", []string{}, "executor binary additional arguments")
cmd.Flags().BoolVarP(&watchEnabled, "watch", "f", false, "watch for changes after start")
cmd.Flags().StringVar(&downloadDir, "download-dir", "artifacts", "download dir")
cmd.Flags().BoolVarP(&downloadArtifactsEnabled, "download-artifacts", "a", false, "downlaod artifacts automatically")
Expand Down
2 changes: 2 additions & 0 deletions internal/app/api/v1/executions.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ func newExecutionFromExecutionOptions(options client.ExecuteOptions) testkube.Ex
options.Request.Tags,
)

execution.Args = options.Request.Args

return execution
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/api/v1/client/direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (c DirectAPIClient) UpdateTest(options UpsertTestOptions) (test testkube.Te

// ExecuteTest starts new external test execution, reads data and returns ID
// Execution is started asynchronously client can check later for results
func (c DirectAPIClient) ExecuteTest(id, namespace, executionName string, executionParams map[string]string, executionParamsFileContent string) (execution testkube.Execution, err error) {
func (c DirectAPIClient) ExecuteTest(id, namespace, executionName string, executionParams map[string]string, executionParamsFileContent string, args []string) (execution testkube.Execution, err error) {
uri := c.getURI("/tests/%s/executions", id)

// get test to get test tags
Expand All @@ -193,6 +193,7 @@ func (c DirectAPIClient) ExecuteTest(id, namespace, executionName string, execut
Namespace: namespace,
Params: executionParams,
Tags: test.Tags,
Args: args,
}

body, err := json.Marshal(request)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1/client/direct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestAPIClient(t *testing.T) {
client.URI = srv.URL

// when
execution, err := client.ExecuteTest("test", "testkube", "some name", map[string]string{}, "")
execution, err := client.ExecuteTest("test", "testkube", "some name", map[string]string{}, "", []string{})

// then
assert.Equal(t, "1", execution.Id)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Client interface {
DeleteTest(name string, namespace string) error
DeleteTests(namespace string) error
ListTests(namespace string, tags []string) (tests testkube.Tests, err error)
ExecuteTest(id, namespace, executionName string, executionParams map[string]string, executionParamsFileContent string) (execution testkube.Execution, err error)
ExecuteTest(id, namespace, executionName string, executionParams map[string]string, executionParamsFileContent string, args []string) (execution testkube.Execution, err error)
Logs(id string) (logs chan output.Output, err error)

CreateExecutor(options CreateExecutorOptions) (executor testkube.ExecutorDetails, err error)
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/v1/client/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (c ProxyAPIClient) UpdateTest(options UpsertTestOptions) (test testkube.Tes

// ExecuteTest starts test execution, reads data and returns ID
// Execution is started asynchronously client can check later for results
func (c ProxyAPIClient) ExecuteTest(id, namespace, executionName string, executionParams map[string]string, executionParamsFileContent string) (execution testkube.Execution, err error) {
func (c ProxyAPIClient) ExecuteTest(id, namespace, executionName string, executionParams map[string]string, executionParamsFileContent string, args []string) (execution testkube.Execution, err error) {
uri := c.getURI("/tests/%s/executions", id)

// get test to get test tags
Expand All @@ -196,6 +196,7 @@ func (c ProxyAPIClient) ExecuteTest(id, namespace, executionName string, executi
Namespace: namespace,
Params: executionParams,
Tags: test.Tags,
Args: args,
}

body, err := json.Marshal(request)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1/client/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestDefaultDirectAPIClient(t *testing.T) {
defer srv.Close()

// when
execution, err := client.ExecuteTest("test", "testkube", "some name", map[string]string{}, "")
execution, err := client.ExecuteTest("test", "testkube", "some name", map[string]string{}, "", []string{})

// then
assert.Equal(t, "1", execution.Id)
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/v1/testkube/model_execution_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ type ExecutionRequest struct {
Namespace string `json:"namespace,omitempty"`
// execution params passed to executor
Params map[string]string `json:"params,omitempty"`
Tags []string `json:"tags,omitempty"`
// additional executor binary arguments
Args []string `json:"args,omitempty"`
Tags []string `json:"tags,omitempty"`
}
2 changes: 1 addition & 1 deletion pkg/api/v1/testkube/model_test_suite_execution_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
package testkube

// test execution request body
// test suite execution request body
type TestSuiteExecutionRequest struct {
// test execution custom name
Name string `json:"name,omitempty"`
Expand Down

0 comments on commit 4a103be

Please sign in to comment.