Skip to content

Commit

Permalink
fix: more scripts to tests renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
exu committed Feb 11, 2022
1 parent 04624f4 commit a309433
Show file tree
Hide file tree
Showing 60 changed files with 188 additions and 183 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ openapi-generate-model: openapi-generate-model-testkube
openapi-generate-model-testkube:
swagger-codegen generate --model-package testkube -i api/v1/testkube.yaml -l go -o tmp/api/testkube
mv tmp/api/testkube/model_test.go tmp/api/testkube/model_test_base.go || true
mv tmp/api/testkube/model_test_suite_step_execute_test.go tmp/api/testkube/model_test_suite_step_execute_test_base.go || true
mv tmp/api/testkube/model_*.go pkg/api/v1/testkube/
rm -rf tmp
find ./pkg/api/v1/testkube -type f -exec sed -i '' -e "s/package swagger/package testkube/g" {} \;
Expand Down
8 changes: 4 additions & 4 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ components:
TestSuiteStepType:
type: string
enum:
- executeScript
- executeTest
- delay

TestSuiteStep:
Expand Down Expand Up @@ -942,7 +942,7 @@ components:
name:
type: string
description: "execution name"
test:
testSuite:
$ref: "#/components/schemas/ObjectRef"
description: object name and namespace
status:
Expand Down Expand Up @@ -1137,7 +1137,7 @@ components:
format: bson objectId
testName:
type: string
description: unique test name (CRD Script name)
description: unique test name (CRD Test name)
testNamespace:
type: string
description: test namespace
Expand Down Expand Up @@ -1277,7 +1277,7 @@ components:
$ref: "#/components/schemas/ExecutionStatus"
output:
type: string
description: "RAW Script execution output, depends of reporter used in particular tool"
description: "RAW Test execution output, depends of reporter used in particular tool"
outputType:
type: string
description: "output type depends of reporter used in partucular tool"
Expand Down
12 changes: 7 additions & 5 deletions cmd/kubectl-testkube/commands/crds/tests_crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewCRDTestsCmd() *cobra.Command {

var ErrTypeNotDetected = fmt.Errorf("type not detected")

type Script struct {
type Test struct {
Name string
Namespace string
Content string
Expand All @@ -77,12 +77,14 @@ func GenerateCRD(namespace, path string) (string, error) {
var testType string

tpl := `apiVersion: tests.testkube.io/v1
kind: Script
kind: Test
metadata:
name: {{ .Name }}
namespace: {{ .Namespace }}
spec:
content: {{ .Content }}
content:
type: string
data: {{ .Content }}
type: {{ .Type }}
`

Expand All @@ -93,7 +95,7 @@ spec:

// try to detect type if none passed
d := detector.NewDefaultDetector()
if detectedType, ok := d.Detect(client.UpsertScriptOptions{Content: &testkube.TestContent{Data: string(content)}}); ok {
if detectedType, ok := d.Detect(client.UpsertTestOptions{Content: &testkube.TestContent{Data: string(content)}}); ok {
ui.Debug("Detected test type", detectedType)
testType = detectedType
} else {
Expand All @@ -104,7 +106,7 @@ spec:

t := template.Must(template.New("test").Parse(tpl))
b := bytes.NewBuffer([]byte{})
err = t.Execute(b, Script{
err = t.Execute(b, Test{
Name: SanitizeName(name),
Namespace: namespace,
Content: fmt.Sprintf("%q", strings.TrimSpace(string(content))),
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/tests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func newContentFromFlags(cmd *cobra.Command) (content *testkube.TestContent, err
return content, nil
}

func NewUpsertTestOptionsFromFlags(cmd *cobra.Command, test testkube.Test) (options apiclientv1.UpsertScriptOptions, err error) {
func NewUpsertTestOptionsFromFlags(cmd *cobra.Command, test testkube.Test) (options apiclientv1.UpsertTestOptions, err error) {
content, err := newContentFromFlags(cmd)

ui.ExitOnError("creating content from passed parameters", err)
Expand All @@ -172,7 +172,7 @@ func NewUpsertTestOptionsFromFlags(cmd *cobra.Command, test testkube.Test) (opti
return options, err
}

options = apiclientv1.UpsertScriptOptions{
options = apiclientv1.UpsertTestOptions{
Name: name,
Type_: executorType,
Content: content,
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/tests/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
)

// NewCreateTestsCmd is a command tp create new Script Custom Resource
// NewCreateTestsCmd is a command tp create new Test Custom Resource
func NewCreateTestsCmd() *cobra.Command {

var (
Expand Down
8 changes: 4 additions & 4 deletions cmd/kubectl-testkube/commands/tests/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewRunTestCmd() *cobra.Command {
Use: "run <testName>",
Aliases: []string{"start", "r"},
Short: "Starts new test",
Long: `Starts new test based on Script Custom Resource name, returns results to console`,
Long: `Starts new test based on Test Custom Resource name, returns results to console`,
Args: validator.TestName,
Run: func(cmd *cobra.Command, args []string) {
ui.Logo()
Expand Down Expand Up @@ -78,15 +78,15 @@ func uiPrintStatus(execution testkube.Execution) {

switch true {
case result.IsQueued():
ui.Warn("Script queued for execution")
ui.Warn("Test queued for execution")

case result.IsPending():
ui.Warn("Script execution started")
ui.Warn("Test execution started")

case result.IsSuccesful():
ui.Info(result.Output)
duration := execution.EndTime.Sub(execution.StartTime)
ui.Success("Script execution completed with sucess in " + duration.String())
ui.Success("Test execution completed with sucess in " + duration.String())

case result.IsFailed():
ui.Warn("Test test execution failed:\n")
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/testsuites/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewCreateTestSuitesCmd() *cobra.Command {

options.Tags = tags

test, err = client.CreateTestSuite((apiClient.UpsertTestOptions(options)))
test, err = client.CreateTestSuite((apiClient.UpsertTestSuiteOptions(options)))
ui.ExitOnError("creating test "+options.Name+" in namespace "+options.Namespace, err)
ui.Success("Test created", options.Name)
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/testsuites/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewUpdateTestSuitesCmd() *cobra.Command {
ui.ExitOnError("reading stdin", err)
}

var options apiClient.UpsertTestOptions
var options apiClient.UpsertTestSuiteOptions

json.Unmarshal(content, &options)

Expand Down
2 changes: 1 addition & 1 deletion docs/cli/testkube_tests_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Starts new test

### Synopsis

Starts new test based on Script Custom Resource name, returns results to console
Starts new test based on Test Custom Resource name, returns results to console

```
testkube tests run <testName> [flags]
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/testkube_tests_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Starts new test

### Synopsis

Starts new test based on Script Custom Resource name, returns results to console
Starts new test based on Test Custom Resource name, returns results to console

```sh
testkube scripts start [flags]
Expand Down
2 changes: 1 addition & 1 deletion docs/executor-curl.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Test can be run using `kubectl testkube tests start curl-test` which gives the o
██ ███████ ███████ ██ ██ ██ ██████ ██████ ███████
/tɛst kjub/ by Kubeshop

Script queued for execution
Test queued for execution

Use following command to get test execution details:
$ kubectl testkube tests execution 613a2d7056499e6e3d5b9c3e
Expand Down
8 changes: 4 additions & 4 deletions docs/executor-cypress.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Name : kubeshop-cypress
Execution ID : 615d5265b046f8fbd3d955d0
Execution name: wildly-popular-worm

Script queued for execution
Test queued for execution
Use following command to get test execution details:
$ kubectl testkube tests execution 615d5265b046f8fbd3d955d0

Expand Down Expand Up @@ -175,7 +175,7 @@ output:
Script execution completed in 1m17s
Test execution completed in 1m17s
```
Expand Down Expand Up @@ -207,7 +207,7 @@ Name : kubeshop-cypress
Execution ID : 615d5372b046f8fbd3d955d2
Execution name: nominally-able-glider
Script queued for execution
Test queued for execution
Use following command to get test execution details:
$ kubectl testkube tests execution 615d5372b046f8fbd3d955d2
Expand Down Expand Up @@ -279,7 +279,7 @@ Name: nominally-able-glider, Status: success, Duration: 2562047h47m16.854775807s
Use following command to get test execution details:
$ kubectl testkube tests execution 615d5372b046f8fbd3d955d2
Script execution completed in 1m45.405939s
Test execution completed in 1m45.405939s
```
## Summary
Expand Down
8 changes: 4 additions & 4 deletions docs/executor-postman.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ Output:
/tɛst kjub/ by Kubeshop


Script created 🥇
Test created 🥇
```

Script created! Now we can run as many times as we want
Test created! Now we can run as many times as we want

## Running test

Expand All @@ -76,7 +76,7 @@ Name : api-incluster-test
Execution ID : 615d6398b046f8fbd3d955d4
Execution name: openly-full-bream

Script queued for execution
Test queued for execution
Use following command to get test execution details:
$ kubectl testkube tests execution 615d6398b046f8fbd3d955d4

Expand Down Expand Up @@ -135,7 +135,7 @@ API-Health
├──────────────────────────────────────────────────────────────────┤
│ average response time: 297ms [min: 297ms, max: 297ms, s.d.: 0µs] │
└──────────────────────────────────────────────────────────────────┘
Script execution completed in 598ms
Test execution completed in 598ms
```
## Summary
Expand Down
2 changes: 1 addition & 1 deletion docs/tests-getting-results.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Name : api-incluster-test
Execution ID : 615d6398b046f8fbd3d955d4
Execution name: openly-full-bream

Script queued for execution
Test queued for execution
Use following command to get test execution details:
$ kubectl testkube tests execution 615d6398b046f8fbd3d955d4

Expand Down
10 changes: 5 additions & 5 deletions docs/tests-running.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Name : api-incluster-test
Execution ID : 615d6398b046f8fbd3d955d4
Execution name: openly-full-bream

Script queued for execution
Test queued for execution
Use following command to get test execution details:
$ kubectl testkube tests execution 615d6398b046f8fbd3d955d4

Expand Down Expand Up @@ -69,7 +69,7 @@ Name : api-incluster-test
Execution ID : 615d7e1ab046f8fbd3d955d6
Execution name: monthly-sure-finch
Script queued for execution
Test queued for execution
Use following command to get test execution details:
$ kubectl testkube tests execution 615d7e1ab046f8fbd3d955d6
Expand Down Expand Up @@ -116,7 +116,7 @@ API-Health
Use following command to get test execution details:
$ kubectl testkube tests execution 615d7e1ab046f8fbd3d955d6
Script execution completed in 595ms
Test execution completed in 595ms
```
As we can see command will wait until test execution completes with error or success
Expand Down Expand Up @@ -149,7 +149,7 @@ Name : kubeshop-cypress
Execution ID : 615d5372b046f8fbd3d955d2
Execution name: nominally-able-glider
Script queued for execution
Test queued for execution
Use following command to get test execution details:
$ kubectl testkube tests execution 615d5372b046f8fbd3d955d2
Expand Down Expand Up @@ -221,7 +221,7 @@ Name: nominally-able-glider, Status: success, Duration: 2562047h47m16.854775807s
Use following command to get test execution details:
$ kubectl testkube tests execution 615d5372b046f8fbd3d955d2
Script execution completed in 1m45.405939s
Test execution completed in 1m45.405939s
```
## Summary
Expand Down
4 changes: 2 additions & 2 deletions docs/testsuites-creating.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ echo '
"namespace": "testkube",
"description": "Example simple test orchestration",
"steps": [
{"type": "executeScript", "namespace": "testkube", "name": "test1"},
{"type": "executeTest", "namespace": "testkube", "name": "test1"},
{"type": "delay", "duration": 5000},
{"type": "executeScript", "namespace": "testkube", "name": "test1"}
{"type": "executeTest", "namespace": "testkube", "name": "test1"}
]
}' | kubectl testkube testsuites create
```
Expand Down
8 changes: 4 additions & 4 deletions internal/app/api/v1/executions.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s TestkubeAPI) ExecuteTestHandler() fiber.Handler {
}

// test name + test execution name should be unique
execution, _ := s.ExecutionResults.GetByNameAndScript(c.Context(), request.Name, scriptID)
execution, _ := s.ExecutionResults.GetByNameAndTest(c.Context(), request.Name, scriptID)
if execution.Name == request.Name {
return s.Error(c, http.StatusBadRequest, fmt.Errorf("test execution with name %s already exists", request.Name))
}
Expand All @@ -54,7 +54,7 @@ func (s TestkubeAPI) ExecuteTestHandler() fiber.Handler {
return s.Error(c, http.StatusInternalServerError, fmt.Errorf("can't create valid execution options: %w", err))
}

execution = s.executeScript(ctx, options)
execution = s.executeTest(ctx, options)
if execution.ExecutionResult.IsFailed() {
return s.Error(c, http.StatusInternalServerError, fmt.Errorf(execution.ExecutionResult.ErrorMessage))
}
Expand All @@ -63,7 +63,7 @@ func (s TestkubeAPI) ExecuteTestHandler() fiber.Handler {
}
}

func (s TestkubeAPI) executeScript(ctx context.Context, options client.ExecuteOptions) (execution testkube.Execution) {
func (s TestkubeAPI) executeTest(ctx context.Context, options client.ExecuteOptions) (execution testkube.Execution) {
// store execution in storage, can be get from API now
execution = newExecutionFromExecutionOptions(options)
options.ID = execution.Id
Expand Down Expand Up @@ -218,7 +218,7 @@ func (s TestkubeAPI) GetExecutionHandler() fiber.Handler {
return s.Error(c, http.StatusInternalServerError, err)
}
} else {
execution, err = s.ExecutionResults.GetByNameAndScript(ctx, executionID, scriptID)
execution, err = s.ExecutionResults.GetByNameAndTest(ctx, executionID, scriptID)
if err == mongo.ErrNoDocuments {
return s.Error(c, http.StatusNotFound, fmt.Errorf("test %s/%s not found", scriptID, executionID))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/app/api/v1/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (m Metrics) IncCreateTest(scriptType string, err error) {
}).Inc()
}

func (m Metrics) IncAbortScript(scriptType string, err error) {
func (m Metrics) IncAbortTest(scriptType string, err error) {
status := "aborted"
if err != nil {
status = "error"
Expand Down

0 comments on commit a309433

Please sign in to comment.