Skip to content

Commit

Permalink
feat: passing params file to executor (#995)
Browse files Browse the repository at this point in the history
  • Loading branch information
exu authored Feb 21, 2022
1 parent 4a103be commit cd31bed
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
6 changes: 6 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,9 @@ components:
example:
users: "3"
prefix: "some-"
paramsFile:
type: string
description: params file content - need to be in format for particular executor (e.g. postman envs file)
content:
$ref: "#/components/schemas/TestContent"

Expand Down Expand Up @@ -1440,6 +1443,9 @@ components:
type: string
description: test kubernetes namespace ("testkube" when not set)
example: testkube
paramsFile:
type: string
description: params file content - need to be in format for particular executor (e.g. postman envs file)
params:
type: object
description: "execution params passed to executor"
Expand Down
12 changes: 10 additions & 2 deletions cmd/kubectl-testkube/commands/tests/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tests

import (
"fmt"
"io/ioutil"
"os"
"time"

Expand All @@ -20,7 +21,7 @@ func NewRunTestCmd() *cobra.Command {
watchEnabled bool
binaryArgs []string
params map[string]string
paramsFileContent string
paramsFile string
downloadArtifactsEnabled bool
downloadDir string
)
Expand All @@ -39,6 +40,13 @@ func NewRunTestCmd() *cobra.Command {
client, namespace := common.GetClient(cmd)
namespacedName := fmt.Sprintf("%s/%s", namespace, testName)

paramsFileContent := ""
if paramsFile != "" {
b, err := ioutil.ReadFile(paramsFile)
ui.ExitOnError("reading params file", err)
paramsFileContent = string(b)
}

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

Expand All @@ -63,7 +71,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().StringVarP(&paramsFile, "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")
Expand Down
11 changes: 6 additions & 5 deletions pkg/api/v1/client/direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,12 @@ func (c DirectAPIClient) ExecuteTest(id, namespace, executionName string, execut
}

request := testkube.ExecutionRequest{
Name: executionName,
Namespace: namespace,
Params: executionParams,
Tags: test.Tags,
Args: args,
Name: executionName,
Namespace: namespace,
ParamsFile: executionParamsFileContent,
Params: executionParams,
Tags: test.Tags,
Args: args,
}

body, err := json.Marshal(request)
Expand Down
11 changes: 6 additions & 5 deletions pkg/api/v1/client/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,12 @@ func (c ProxyAPIClient) ExecuteTest(id, namespace, executionName string, executi
}

request := testkube.ExecutionRequest{
Name: executionName,
Namespace: namespace,
Params: executionParams,
Tags: test.Tags,
Args: args,
Name: executionName,
Namespace: namespace,
ParamsFile: executionParamsFileContent,
Params: executionParams,
Tags: test.Tags,
Args: args,
}

body, err := json.Marshal(request)
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1/testkube/model_execution_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type ExecutionRequest struct {
Name string `json:"name,omitempty"`
// test kubernetes namespace (\"testkube\" when not set)
Namespace string `json:"namespace,omitempty"`
// params file content - need to be in format for particular executor (e.g. postman envs file)
ParamsFile string `json:"paramsFile,omitempty"`
// execution params passed to executor
Params map[string]string `json:"params,omitempty"`
// additional executor binary arguments
Expand Down
6 changes: 4 additions & 2 deletions pkg/api/v1/testkube/model_executor_start_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type ExecutorStartRequest struct {
// test execution custom name
Name string `json:"name,omitempty"`
// execution params passed to executor
Params map[string]string `json:"params,omitempty"`
Content *TestContent `json:"content,omitempty"`
Params map[string]string `json:"params,omitempty"`
// params file content - need to be in format for particular executor (e.g. postman envs file)
ParamsFile string `json:"paramsFile,omitempty"`
Content *TestContent `json:"content,omitempty"`
}

0 comments on commit cd31bed

Please sign in to comment.