-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add test triggers client for external use (#5771)
* add test triggers client for external use * add test triggers client for external use
- Loading branch information
Showing
17 changed files
with
243 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package client | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/kubeshop/testkube/pkg/api/v1/testkube" | ||
) | ||
|
||
// NewTestTriggerClient creates new TestTrigger client | ||
func NewTestTriggerClient(triggerTransport Transport[testkube.TestTrigger]) TestTriggerClient { | ||
return TestTriggerClient{ | ||
triggerTransport: triggerTransport, | ||
} | ||
} | ||
|
||
// TestTriggerClient is a client for triggers | ||
type TestTriggerClient struct { | ||
triggerTransport Transport[testkube.TestTrigger] | ||
} | ||
|
||
// GetTestTrigger gets trigger by name | ||
func (c TestTriggerClient) GetTestTrigger(name string) (trigger testkube.TestTrigger, err error) { | ||
uri := c.triggerTransport.GetURI("/triggers/%s", name) | ||
return c.triggerTransport.Execute(http.MethodGet, uri, nil, nil) | ||
} | ||
|
||
// ListTestTriggers list all triggers | ||
func (c TestTriggerClient) ListTestTriggers(selector string) (triggers []testkube.TestTrigger, err error) { | ||
uri := c.triggerTransport.GetURI("/triggers") | ||
params := map[string]string{ | ||
"selector": selector, | ||
} | ||
|
||
return c.triggerTransport.ExecuteMultiple(http.MethodGet, uri, nil, params) | ||
} | ||
|
||
// CreateTestTrigger creates new TestTrigger Custom Resource | ||
func (c TestTriggerClient) CreateTestTrigger(options CreateTestTriggerOptions) (trigger testkube.TestTrigger, err error) { | ||
uri := c.triggerTransport.GetURI("/triggers") | ||
request := testkube.TestTriggerUpsertRequest(options) | ||
|
||
body, err := json.Marshal(request) | ||
if err != nil { | ||
return trigger, err | ||
} | ||
|
||
return c.triggerTransport.Execute(http.MethodPost, uri, body, nil) | ||
} | ||
|
||
// UpdateTestTrigger updates TestTrigger Custom Resource | ||
func (c TestTriggerClient) UpdateTestTrigger(options UpdateTestTriggerOptions) (trigger testkube.TestTrigger, err error) { | ||
name := "" | ||
if options.Name != "" { | ||
name = options.Name | ||
} | ||
|
||
uri := c.triggerTransport.GetURI("/triggers/%s", name) | ||
request := testkube.TestTriggerUpsertRequest(options) | ||
|
||
body, err := json.Marshal(request) | ||
if err != nil { | ||
return trigger, err | ||
} | ||
|
||
return c.triggerTransport.Execute(http.MethodPatch, uri, body, nil) | ||
} | ||
|
||
// DeleteTestTriggers deletes all triggers | ||
func (c TestTriggerClient) DeleteTestTriggers(selector string) (err error) { | ||
uri := c.triggerTransport.GetURI("/triggers") | ||
return c.triggerTransport.Delete(uri, selector, true) | ||
} | ||
|
||
// DeleteTestTrigger deletes single trigger by name | ||
func (c TestTriggerClient) DeleteTestTrigger(name string) (err error) { | ||
uri := c.triggerTransport.GetURI("/triggers/%s", name) | ||
return c.triggerTransport.Delete(uri, "", true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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 | ||
|
||
func (t TestTrigger) GetName() string { | ||
return t.Name | ||
} | ||
|
||
func (t TestTrigger) GetNamespace() string { | ||
return t.Namespace | ||
} | ||
|
||
func (t TestTrigger) GetLabels() map[string]string { | ||
return t.Labels | ||
} | ||
|
||
func (t TestTrigger) GetAnnotations() map[string]string { | ||
return t.Annotations | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
pkg/api/v1/testkube/model_test_workflow_with_execution_summary_extended.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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 | ||
|
||
func (w TestWorkflowWithExecutionSummary) GetName() string { | ||
return w.Workflow.Name | ||
} | ||
|
||
func (w TestWorkflowWithExecutionSummary) GetNamespace() string { | ||
return w.Workflow.Namespace | ||
} | ||
|
||
func (w TestWorkflowWithExecutionSummary) GetLabels() map[string]string { | ||
return w.Workflow.Labels | ||
} | ||
|
||
func (w TestWorkflowWithExecutionSummary) GetAnnotations() map[string]string { | ||
return w.Workflow.Annotations | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.