Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: openapi spec for test executions #631

Merged
merged 15 commits into from
Dec 15, 2021
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ install-swagger-codegen-mac:

openapi-generate-model: openapi-generate-model-testkube

# we need to remove model_test_step to mimic inheritance
# look at https://github.com/swagger-api/swagger-codegen/issues/11292
openapi-generate-model-testkube:
swagger-codegen generate -i api/v1/testkube.yaml -l go -o tmp/api/testkube
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" {} \;
go fmt pkg/api/v1/testkube/*.go
rm pkg/api/v1/testkube/model_test_step.go


test:
Expand Down
204 changes: 203 additions & 1 deletion api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,74 @@ tags:
description: "Script operations"
- name: executions
description: "Execution operations"
- name: tests
description: "Scripts orchestration operations"

paths:

/tests:
get:
tags:
- tests
- api
summary: "Get all tests"
description: "Returns array of tests"
operationId: listTests
parameters:
- $ref: "#/components/parameters/ExecutionsTextSearch"
- $ref: "#/components/parameters/ExecutionsPageSize"
- $ref: "#/components/parameters/ExecutionsPageIndex"
- $ref: "#/components/parameters/ExecutionsStatusFilter"
- $ref: "#/components/parameters/ExecutionsStartDateFilter"
- $ref: "#/components/parameters/ExecutionsEndDateFilter"
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/Test"
500:
description: "problem with getting script executions from storage"
content:
application/problem+json:
schema:
type: array
items:
$ref: "#/components/schemas/Problem"

/tests/{id}:
get:
parameters:
- in: path
name: id
schema:
type: string
required: true
description: ID of the test
tags:
- tests
- api
summary: "Get script execution by ID"
description: "Returns execution with given executionID"
operationId: getExecutionByID
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/Execution"
500:
description: "problem with getting test from storage"
content:
application/problem+json:
schema:
type: array
items:
$ref: "#/components/schemas/Problem"


/executions:
get:
tags:
Expand All @@ -32,6 +98,9 @@ paths:
description: "Returns array of scripts executions"
operationId: listExecutions
parameters:

- $ref: "#/components/parameters/ExecutionsTest"
- $ref: "#/components/parameters/ExecutionsTextSearch"
- $ref: "#/components/parameters/ExecutionsPageSize"
- $ref: "#/components/parameters/ExecutionsPageIndex"
- $ref: "#/components/parameters/ExecutionsStatusFilter"
Expand Down Expand Up @@ -649,6 +718,129 @@ paths:

components:
schemas:

ObjectRef:
type: object
properties:
namespace:
type: string
name:
type: string


Test:
type: object
properties:
exu marked this conversation as resolved.
Show resolved Hide resolved
before:
$ref: "#/components/schemas/TestStep"
description: Run this step before whole suite
steps:
type: array
items:
$ref: "#/components/schemas/TestStep"
description: Steps to run
after:
$ref: "#/components/schemas/TestStep"
description: Run this step after whole suite
repeats:
type: integer
default: 1

TestStep:
type: object
required:
- name
properties:
name:
type: string
description: step name (in case of script it'll be script name)

TestStepExecuteScript:
allOf: # Combines the BasicErrorModel and the inline model
- $ref: '#/components/schemas/TestStep'
- type: object
required:
- namepace
- name
properties:
namespace:
type: string
name:
type: string
stopOnFailure:
exu marked this conversation as resolved.
Show resolved Hide resolved
type: boolean
default: true

TestStepDelay:
allOf: # Combines the TestStep and the inline model
- $ref: '#/components/schemas/TestStep'
- type: object
required:
- duration
exu marked this conversation as resolved.
Show resolved Hide resolved
properties:
delay:
type: integer
default: 0
description: delay in milliseconds


TestExecution:
type: object
description: API server test scripts executions container
properties:
id:
type: string
description: execution id
format: bson objectId
name:
type: string
description: "execution name"
envs:
type: object
description: "environment variables passed to executor"
additionalProperties:
type: string
example:
record: "true"
prefix: "some-"
params:
type: object
description: "execution params passed to executor converted to vars for usage in tests"
additionalProperties:
type: string
example:
users: "3"
prefix: "some-"
startTime:
type: string
description: 'test start time'
format: date-time
endTime:
type: string
description: 'test end time'
format: date-time
executionsResults:
exu marked this conversation as resolved.
Show resolved Hide resolved
type: array
description: "executions restults"
items:
$ref: "#/components/schemas/TestExecutionResult"
description: list of scripts executions


TestExecutionResult:
exu marked this conversation as resolved.
Show resolved Hide resolved
description: execution result returned from executor
type: object
required:
- status
properties:
script:
$ref: "#/components/schemas/ObjectRef"
description: name and namespace of script in object reference
result:
$ref: "#/components/schemas/ExecutionResult"
description: execution results of connected test script


Script:
type: object
properties:
Expand Down Expand Up @@ -795,6 +987,8 @@ components:
- success
- error



ExecutionResult:
exu marked this conversation as resolved.
Show resolved Hide resolved
description: execution result returned from executor
type: object
Expand Down Expand Up @@ -1155,7 +1349,15 @@ components:
#

parameters:
ExecutionTextSearch:
ExecutionsTest:
in: query
name: test
schema:
type: string
default: ""
description: test namespaced name to filter
required: false
ExecutionsTextSearch:
in: query
name: textSearch
schema:
Expand Down
15 changes: 15 additions & 0 deletions pkg/api/v1/testkube/model_object_ref.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* TestKube API
*
* TestKube provides a Kubernetes-native framework for test definition, execution and results
*
* API version: 1.0.0
* Contact: testkube@kubeshop.io
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package testkube

type ObjectRef struct {
Namespace string `json:"namespace,omitempty"`
Name string `json:"name,omitempty"`
}
18 changes: 18 additions & 0 deletions pkg/api/v1/testkube/model_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* TestKube API
*
* TestKube provides a Kubernetes-native framework for test definition, execution and results
*
* API version: 1.0.0
* Contact: testkube@kubeshop.io
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package testkube

type Test struct {
Before *TestStep `json:"before,omitempty"`
// Steps to run
Steps []TestStep `json:"steps,omitempty"`
After *TestStep `json:"after,omitempty"`
Repeats int32 `json:"repeats,omitempty"`
}
32 changes: 32 additions & 0 deletions pkg/api/v1/testkube/model_test_execution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* TestKube API
*
* TestKube provides a Kubernetes-native framework for test definition, execution and results
*
* API version: 1.0.0
* Contact: testkube@kubeshop.io
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package testkube

import (
"time"
)

// API server test scripts executions container
type TestExecution struct {
// execution id
Id string `json:"id,omitempty"`
// execution name
Name string `json:"name,omitempty"`
// environment variables passed to executor
Envs map[string]string `json:"envs,omitempty"`
// execution params passed to executor converted to vars for usage in tests
Params map[string]string `json:"params,omitempty"`
// test start time
StartTime time.Time `json:"startTime,omitempty"`
// test end time
EndTime time.Time `json:"endTime,omitempty"`
// executions restults
ExecutionsResults []TestExecutionResult `json:"executionsResults,omitempty"`
}
16 changes: 16 additions & 0 deletions pkg/api/v1/testkube/model_test_execution_result.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* TestKube API
*
* TestKube provides a Kubernetes-native framework for test definition, execution and results
*
* API version: 1.0.0
* Contact: testkube@kubeshop.io
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package testkube

// execution result returned from executor
type TestExecutionResult struct {
Script *ObjectRef `json:"script,omitempty"`
Result *ExecutionResult `json:"result,omitempty"`
}
17 changes: 17 additions & 0 deletions pkg/api/v1/testkube/model_test_step_delay.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* TestKube API
*
* TestKube provides a Kubernetes-native framework for test definition, execution and results
*
* API version: 1.0.0
* Contact: testkube@kubeshop.io
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package testkube

type TestStepDelay struct {
// step name (in case of script it'll be script name)
Name string `json:"name"`
// delay in milliseconds
Delay int32 `json:"delay,omitempty"`
}
18 changes: 18 additions & 0 deletions pkg/api/v1/testkube/model_test_step_delay_extended.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* TestKube API
*
* TestKube provides a Kubernetes-native framework for test definition, execution and results
*
* API version: 1.0.0
* Contact: testkube@kubeshop.io
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package testkube

import (
"fmt"
)

func (s TestStepDelay) FullName() string {
return fmt.Sprintf("Delay %dms", s.Delay)
}
16 changes: 16 additions & 0 deletions pkg/api/v1/testkube/model_test_step_execute_script.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* TestKube API
*
* TestKube provides a Kubernetes-native framework for test definition, execution and results
*
* API version: 1.0.0
* Contact: testkube@kubeshop.io
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package testkube

type TestStepExecuteScript struct {
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
StopOnFailure bool `json:"stopOnFailure,omitempty"`
}
Loading