Skip to content

Commit

Permalink
api client refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
exu committed Feb 10, 2022
1 parent 0b9513d commit 2a7f814
Show file tree
Hide file tree
Showing 38 changed files with 183 additions and 183 deletions.
4 changes: 2 additions & 2 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,11 @@ components:
type: boolean
default: true
execute:
$ref: "#/components/schemas/TestSuiteStepExecuteScript"
$ref: "#/components/schemas/TestSuiteStepExecuteTest"
delay:
$ref: "#/components/schemas/TestSuiteStepDelay"

TestSuiteStepExecuteScript:
TestSuiteStepExecuteTest:
allOf:
- $ref: "#/components/schemas/ObjectRef"

Expand Down
10 changes: 5 additions & 5 deletions cmd/kubectl-testkube/commands/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ func NewScriptsCmd() *cobra.Command {
cmd.PersistentFlags().StringP("go-template", "", "{{ . | printf \"%+v\" }}", "in case of choosing output==go pass golang template")

cmd.AddCommand(scripts.NewAbortExecutionCmd())
cmd.AddCommand(scripts.NewListScriptsCmd())
cmd.AddCommand(scripts.NewGetScriptsCmd())
cmd.AddCommand(scripts.NewListTestsCmd())
cmd.AddCommand(scripts.NewGetTestsCmd())
cmd.AddCommand(scripts.NewStartScriptCmd())
cmd.AddCommand(scripts.NewGetExecutionCmd())
cmd.AddCommand(scripts.NewWatchExecutionCmd())
cmd.AddCommand(scripts.NewListExecutionsCmd())
cmd.AddCommand(scripts.NewCreateScriptsCmd())
cmd.AddCommand(scripts.NewUpdateScriptsCmd())
cmd.AddCommand(scripts.NewDeleteScriptsCmd())
cmd.AddCommand(scripts.NewCreateTestsCmd())
cmd.AddCommand(scripts.NewUpdateTestsCmd())
cmd.AddCommand(scripts.NewDeleteTestsCmd())
cmd.AddCommand(scripts.NewDeleteAllScriptsCmd())
return cmd
}
8 changes: 4 additions & 4 deletions cmd/kubectl-testkube/commands/scripts/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/spf13/cobra"
)

// NewCreateScriptsCmd is a command tp create new scriptcustom resource
func NewCreateScriptsCmd() *cobra.Command {
// NewCreateTestsCmd is a command tp create new scriptcustom resource
func NewCreateTestsCmd() *cobra.Command {

var (
testName string
Expand All @@ -33,15 +33,15 @@ func NewCreateScriptsCmd() *cobra.Command {
ui.Logo()

client, _ := common.GetClient(cmd)
script, _ := client.GetScript(testName, testNamespace)
script, _ := client.GetTest(testName, testNamespace)
if testName == script.Name {
ui.Failf("Script with name '%s' already exists in namespace %s", testName, testNamespace)
}

options, err := NewUpsertScriptOptionsFromFlags(cmd, script)
ui.ExitOnError("getting script options", err)

script, err = client.CreateScript(options)
script, err = client.CreateTest(options)
ui.ExitOnError("creating script "+testName+" in namespace "+testNamespace, err)

ui.Success("Script created", testNamespace, "/", testName)
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/scripts/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
)

func NewDeleteScriptsCmd() *cobra.Command {
func NewDeleteTestsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "delete <testName>",
Short: "Delete scripts",
Expand All @@ -19,7 +19,7 @@ func NewDeleteScriptsCmd() *cobra.Command {
namespace := cmd.Flag("namespace").Value.String()
name := args[0]

err := client.DeleteScript(name, namespace)
err := client.DeleteTest(name, namespace)
ui.ExitOnError("delete script "+name+" from namespace "+namespace, err)

ui.Success("Succesfully deleted", name)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/scripts/deleteall.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NewDeleteAllScriptsCmd() *cobra.Command {

client, _ := common.GetClient(cmd)

err := client.DeleteScripts(namespace)
err := client.DeleteTests(namespace)
ui.ExitOnError("delete all scripts from namespace "+namespace, err)

ui.Success("Succesfully deleted all scripts in namespace", namespace)
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/scripts/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"gopkg.in/yaml.v2"
)

func NewGetScriptsCmd() *cobra.Command {
func NewGetTestsCmd() *cobra.Command {
return &cobra.Command{
Use: "get <testName>",
Aliases: []string{"g"},
Expand All @@ -24,7 +24,7 @@ func NewGetScriptsCmd() *cobra.Command {
namespace := cmd.Flag("namespace").Value.String()

client, _ := common.GetClient(cmd)
script, err := client.GetScript(name, namespace)
script, err := client.GetTest(name, namespace)
ui.ExitOnError("getting script "+name, err)

out, err := yaml.Marshal(script)
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/scripts/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"
)

func NewListScriptsCmd() *cobra.Command {
func NewListTestsCmd() *cobra.Command {
var tags []string

cmd := &cobra.Command{
Expand All @@ -20,7 +20,7 @@ func NewListScriptsCmd() *cobra.Command {
namespace := cmd.Flag("namespace").Value.String()

client, _ := common.GetClient(cmd)
scripts, err := client.ListScripts(namespace, tags)
scripts, err := client.ListTests(namespace, tags)
ui.ExitOnError("getting all scripts in namespace "+namespace, err)

ui.Table(scripts, os.Stdout)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/scripts/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewStartScriptCmd() *cobra.Command {
client, namespace := common.GetClient(cmd)
namespacedName := fmt.Sprintf("%s/%s", namespace, testName)

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

printExecutionDetails(execution)
Expand Down
6 changes: 3 additions & 3 deletions cmd/kubectl-testkube/commands/scripts/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
)

func NewUpdateScriptsCmd() *cobra.Command {
func NewUpdateTestsCmd() *cobra.Command {

var (
testName string
Expand All @@ -32,15 +32,15 @@ func NewUpdateScriptsCmd() *cobra.Command {
var err error

client, _ := common.GetClient(cmd)
script, _ := client.GetScript(testName, testNamespace)
script, _ := client.GetTest(testName, testNamespace)
if testName != script.Name {
ui.Failf("Script with name '%s' not exists in namespace %s", testName, testNamespace)
}

options, err := NewUpsertScriptOptionsFromFlags(cmd, script)
ui.ExitOnError("getting script options", err)

script, err = client.UpdateScript(options)
script, err = client.UpdateTest(options)
ui.ExitOnError("updating script "+testName+" in namespace "+testNamespace, err)

ui.Success("Script updated", testNamespace, "/", testName)
Expand Down
12 changes: 6 additions & 6 deletions cmd/kubectl-testkube/commands/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func NewTestsCmd() *cobra.Command {
cmd.PersistentFlags().StringP("output", "o", "raw", "output type one of raw|json|go ")
cmd.PersistentFlags().StringP("go-template", "", "{{ . | printf \"%+v\" }}", "in case of choosing output==go pass golang template")

cmd.AddCommand(tests.NewListTestsCmd())
cmd.AddCommand(tests.NewGetTestCmd())
cmd.AddCommand(tests.NewListTestSuitesCmd())
cmd.AddCommand(tests.NewGetTestSuiteCmd())
cmd.AddCommand(tests.NewStartTestCmd())
cmd.AddCommand(tests.NewCreateTestsCmd())
cmd.AddCommand(tests.NewUpdateTestsCmd())
cmd.AddCommand(tests.NewDeleteTestCmd())
cmd.AddCommand(tests.NewDeleteTestsCmd())
cmd.AddCommand(tests.NewCreateTestSuitesCmd())
cmd.AddCommand(tests.NewUpdateTestSuitesCmd())
cmd.AddCommand(tests.NewDeleteTestSuiteCmd())
cmd.AddCommand(tests.NewDeleteTestSuitesCmd())
cmd.AddCommand(tests.NewTestExecutionCmd())
cmd.AddCommand(tests.NewWatchTestExecutionCmd())
cmd.AddCommand(tests.NewTestExecutionsCmd())
Expand Down
6 changes: 3 additions & 3 deletions cmd/kubectl-testkube/commands/tests/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/spf13/cobra"
)

func NewCreateTestsCmd() *cobra.Command {
func NewCreateTestSuitesCmd() *cobra.Command {

var (
name string
Expand Down Expand Up @@ -51,14 +51,14 @@ func NewCreateTestsCmd() *cobra.Command {

client, _ := common.GetClient(cmd)

test, _ := client.GetTest(options.Name, options.Namespace)
test, _ := client.GetTestSuite(options.Name, options.Namespace)
if options.Name == test.Name {
ui.Failf("Test with name '%s' already exists in namespace %s", options.Name, options.Namespace)
}

options.Tags = tags

test, err = client.CreateTest((apiClient.UpsertTestOptions(options)))
test, err = client.CreateTestSuite((apiClient.UpsertTestOptions(options)))
ui.ExitOnError("creating test "+options.Name+" in namespace "+options.Namespace, err)
ui.Success("Test created", options.Name)
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/tests/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
)

func NewDeleteTestCmd() *cobra.Command {
func NewDeleteTestSuiteCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "delete <testSuiteName>",
Short: "Delete tests",
Expand All @@ -19,7 +19,7 @@ func NewDeleteTestCmd() *cobra.Command {
client, namespace := common.GetClient(cmd)

name := args[0]
err := client.DeleteTest(name, namespace)
err := client.DeleteTestSuite(name, namespace)
ui.ExitOnError("delete test "+name+" from namespace "+namespace, err)
ui.Success("Succesfully deleted", name)
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/tests/deleteall.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
)

func NewDeleteTestsCmd() *cobra.Command {
func NewDeleteTestSuitesCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "delete-all",
Short: "Delete all tests in namespace",
Expand All @@ -15,7 +15,7 @@ func NewDeleteTestsCmd() *cobra.Command {

client, namespace := common.GetClient(cmd)

err := client.DeleteTests(namespace)
err := client.DeleteTestSuites(namespace)
ui.ExitOnError("delete all tests from namespace "+namespace, err)
ui.Success("Succesfully deleted all tests in namespace", namespace)
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/tests/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewTestExecutionCmd() *cobra.Command {
client, _ := common.GetClient(cmd)

executionID := args[0]
execution, err := client.GetTestExecution(executionID)
execution, err := client.GetTestSuiteExecution(executionID)
ui.ExitOnError("getting recent execution data id:"+execution.Id, err)

printTestExecutionDetails(execution, startTime)
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/tests/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"gopkg.in/yaml.v2"
)

func NewGetTestCmd() *cobra.Command {
func NewGetTestSuiteCmd() *cobra.Command {
return &cobra.Command{
Use: "get <testSuiteName>",
Aliases: []string{"g"},
Expand All @@ -23,7 +23,7 @@ func NewGetTestCmd() *cobra.Command {

name := args[0]
client, _ := common.GetClient(cmd)
test, err := client.GetTest(name, namespace)
test, err := client.GetTestSuite(name, namespace)
ui.ExitOnError("getting test "+name, err)

out, err := yaml.Marshal(test)
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/tests/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"
)

func NewListTestsCmd() *cobra.Command {
func NewListTestSuitesCmd() *cobra.Command {
var tags []string

cmd := &cobra.Command{
Expand All @@ -20,7 +20,7 @@ func NewListTestsCmd() *cobra.Command {
namespace := cmd.Flag("namespace").Value.String()

client, _ := common.GetClient(cmd)
tests, err := client.ListTests(namespace, tags)
tests, err := client.ListTestSuites(namespace, tags)

ui.ExitOnError("getting all tests in namespace "+namespace, err)

Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/tests/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewStartTestCmd() *cobra.Command {
client, namespace := common.GetClient(cmd)
namespacedName := fmt.Sprintf("%s/%s", namespace, testSuiteName)

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

if watchEnabled {
Expand All @@ -47,7 +47,7 @@ func NewStartTestCmd() *cobra.Command {
}
}

execution, err = client.GetTestExecution(execution.Id)
execution, err = client.GetTestSuiteExecution(execution.Id)
printTestExecutionDetails(execution, startTime)
ui.ExitOnError("getting recent execution data id:"+execution.Id, err)

Expand Down
6 changes: 3 additions & 3 deletions cmd/kubectl-testkube/commands/tests/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/spf13/cobra"
)

func NewUpdateTestsCmd() *cobra.Command {
func NewUpdateTestSuitesCmd() *cobra.Command {

var (
file string
Expand Down Expand Up @@ -44,7 +44,7 @@ func NewUpdateTestsCmd() *cobra.Command {

client, _ := common.GetClient(cmd)

test, _ := client.GetTest(options.Name, options.Namespace)
test, _ := client.GetTestSuite(options.Name, options.Namespace)
if options.Name == test.Name {
ui.Failf("Test with name '%s' already exists in namespace %s", options.Name, options.Namespace)
}
Expand All @@ -62,7 +62,7 @@ func NewUpdateTestsCmd() *cobra.Command {
options.Tags = tags
}

test, err = client.UpdateTest(options)
test, err = client.UpdateTestSuite(options)
ui.ExitOnError("updating 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/tests/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewWatchTestExecutionCmd() *cobra.Command {
printTestExecutionDetails(execution, startTime)
}

execution, err := client.GetTestExecution(executionID)
execution, err := client.GetTestSuiteExecution(executionID)
ui.ExitOnError("getting test excecution", err)
printTestExecutionDetails(execution, startTime)
ui.ExitOnError("getting recent execution data id:"+execution.Id, err)
Expand Down
4 changes: 2 additions & 2 deletions internal/app/api/v1/executions.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"github.com/kubeshop/testkube/pkg/secret"
)

// ExecuteScriptHandler calls particular executor based on execution request content and type
func (s TestkubeAPI) ExecuteScriptHandler() fiber.Handler {
// ExecuteTestHandler calls particular executor based on execution request content and type
func (s TestkubeAPI) ExecuteTestHandler() fiber.Handler {
return func(c *fiber.Ctx) error {
ctx := c.Context()

Expand Down
4 changes: 2 additions & 2 deletions internal/app/api/v1/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (m Metrics) IncExecution(execution testkube.Execution) {
}).Inc()
}

func (m Metrics) IncUpdateScript(scriptType string, err error) {
func (m Metrics) IncUpdateTest(scriptType string, err error) {
result := "updated"
if err != nil {
result = "error"
Expand All @@ -62,7 +62,7 @@ func (m Metrics) IncUpdateScript(scriptType string, err error) {
}).Inc()
}

func (m Metrics) IncCreateScript(scriptType string, err error) {
func (m Metrics) IncCreateTest(scriptType string, err error) {
result := "created"
if err != nil {
result = "error"
Expand Down

0 comments on commit 2a7f814

Please sign in to comment.