Skip to content

Commit ecf1391

Browse files
authored
feat: git auth type (#127)
* feat: git auth type * fix: add enums * fix: client * fix: unit test * fix: strict type for enum * feat: test trigger types * feat: test trigger types * fix: enum typo * fix: test trigger type usage * fix: spelling
1 parent 3ccbf30 commit ecf1391

21 files changed

+293
-65
lines changed

apis/executor/v1/executor_types.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type ExecutorSpec struct {
3333

3434
// ExecutorType one of "rest" for rest openapi based executors or "job" which will be default runners for testkube
3535
// or "container" for container executors
36-
ExecutorType string `json:"executor_type,omitempty"`
36+
ExecutorType ExecutorType `json:"executor_type,omitempty"`
3737

3838
// URI for rest based executors
3939
URI string `json:"uri,omitempty"`
@@ -68,6 +68,14 @@ const (
6868
FeatureJUnitReport Feature = "junit-report"
6969
)
7070

71+
// +kubebuilder:validation:Enum=job;container
72+
type ExecutorType string
73+
74+
const (
75+
ExecutorTypeJob ExecutorType = "job"
76+
ExecutorTypeContainer ExecutorType = "container"
77+
)
78+
7179
// +kubebuilder:validation:Enum=string;file-uri;git-file;git-dir;git
7280
type ScriptContentType string
7381

apis/executor/v1/webhook_types.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,30 @@ type WebhookSpec struct {
3131
// Uri is address where webhook should be made
3232
Uri string `json:"uri,omitempty"`
3333
// Events declare list if events on which webhook should be called
34-
Events []string `json:"events,omitempty"`
34+
Events []EventType `json:"events,omitempty"`
3535
// Labels to filter for tests and test suites
3636
Selector string `json:"selector,omitempty"`
3737
// will load the generated payload for notification inside the object
3838
PayloadObjectField string `json:"payloadObjectField,omitempty"`
3939
}
4040

41+
// +kubebuilder:validation:Enum=start-test;end-test-success;end-test-failed;end-test-aborted;end-test-timeout;start-testsuite;end-testsuite-success;end-testsuite-failed;end-testsuite-aborted;end-testsuite-timeout
42+
type EventType string
43+
44+
// List of EventType
45+
const (
46+
START_TEST_EventType EventType = "start-test"
47+
END_TEST_SUCCESS_EventType EventType = "end-test-success"
48+
END_TEST_FAILED_EventType EventType = "end-test-failed"
49+
END_TEST_ABORTED_EventType EventType = "end-test-aborted"
50+
END_TEST_TIMEOUT_EventType EventType = "end-test-timeout"
51+
START_TESTSUITE_EventType EventType = "start-testsuite"
52+
END_TESTSUITE_SUCCESS_EventType EventType = "end-testsuite-success"
53+
END_TESTSUITE_FAILED_EventType EventType = "end-testsuite-failed"
54+
END_TESTSUITE_ABORTED_EventType EventType = "end-testsuite-aborted"
55+
END_TESTSUITE_TIMEOUT_EventType EventType = "end-testsuite-timeout"
56+
)
57+
4158
// WebhookStatus defines the observed state of Webhook
4259
type WebhookStatus struct {
4360
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster

apis/executor/v1/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/tests/v3/test_conversion.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (src *Test) ConvertTo(dstRaw conversion.Hub) error {
5252
if src.Spec.Content != nil {
5353
dst.Spec.Content = &testkubev2.TestContent{
5454
Data: src.Spec.Content.Data,
55-
Type_: src.Spec.Content.Type_,
55+
Type_: string(src.Spec.Content.Type_),
5656
Uri: src.Spec.Content.Uri,
5757
}
5858
}
@@ -112,7 +112,7 @@ func (dst *Test) ConvertFrom(srcRaw conversion.Hub) error {
112112
if src.Spec.Content != nil {
113113
dst.Spec.Content = &TestContent{
114114
Data: src.Spec.Content.Data,
115-
Type_: src.Spec.Content.Type_,
115+
Type_: TestContentType(src.Spec.Content.Type_),
116116
Uri: src.Spec.Content.Uri,
117117
}
118118
}

apis/tests/v3/test_types.go

+45-17
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type Variable commonv1.Variable
5050
// TestContent defines test content
5151
type TestContent struct {
5252
// test type
53-
Type_ string `json:"type,omitempty"`
53+
Type_ TestContentType `json:"type,omitempty"`
5454
// repository of test content
5555
Repository *Repository `json:"repository,omitempty"`
5656
// test content body
@@ -59,6 +59,19 @@ type TestContent struct {
5959
Uri string `json:"uri,omitempty"`
6060
}
6161

62+
// +kubebuilder:validation:Enum=string;file-uri;git-file;git-dir;git
63+
type TestContentType string
64+
65+
const (
66+
TestContentTypeString TestContentType = "string"
67+
TestContentTypeFileURI TestContentType = "file-uri"
68+
// Deprecated: use git instead
69+
TestContentTypeGitFile TestContentType = "git-file"
70+
// Deprecated: use git instead
71+
TestContentTypeGitDir TestContentType = "git-dir"
72+
TestContentTypeGit TestContentType = "git"
73+
)
74+
6275
// Testkube internal reference for secret storage in Kubernetes secrets
6376
type SecretRef struct {
6477
// object kubernetes namespace
@@ -80,14 +93,28 @@ type Repository struct {
8093
// commit id (sha) for checkout
8194
Commit string `json:"commit,omitempty"`
8295
// if needed we can checkout particular path (dir or file) in case of BIG/mono repositories
83-
Path string `json:"path,omitempty"`
84-
UsernameSecret *SecretRef `json:"usernameSecret,omitempty"`
85-
TokenSecret *SecretRef `json:"tokenSecret,omitempty"`
86-
CertificateSecret string `json:"certificateSecret,omitempty"`
96+
Path string `json:"path,omitempty"`
97+
UsernameSecret *SecretRef `json:"usernameSecret,omitempty"`
98+
TokenSecret *SecretRef `json:"tokenSecret,omitempty"`
99+
// git auth certificate secret for private repositories
100+
CertificateSecret string `json:"certificateSecret,omitempty"`
87101
// if provided we checkout the whole repository and run test from this directory
88102
WorkingDir string `json:"workingDir,omitempty"`
103+
// auth type for git requests
104+
AuthType GitAuthType `json:"authType,omitempty"`
89105
}
90106

107+
// GitAuthType defines git auth type
108+
// +kubebuilder:validation:Enum=basic;header
109+
type GitAuthType string
110+
111+
const (
112+
// GitAuthTypeBasic for git basic auth requests
113+
GitAuthTypeBasic GitAuthType = "basic"
114+
// GitAuthTypeHeader for git header auth requests
115+
GitAuthTypeHeader GitAuthType = "header"
116+
)
117+
91118
// artifact request body for container executors with test artifacts
92119
type ArtifactRequest struct {
93120
// artifact storage class name
@@ -101,11 +128,22 @@ type ArtifactRequest struct {
101128
// running context for test or test suite execution
102129
type RunningContext struct {
103130
// One of possible context types
104-
Type_ string `json:"type"`
131+
Type_ RunningContextType `json:"type"`
105132
// Context value depending from its type
106133
Context string `json:"context,omitempty"`
107134
}
108135

136+
type RunningContextType string
137+
138+
const (
139+
RunningContextTypeUserCLI RunningContextType = "user-cli"
140+
RunningContextTypeUserUI RunningContextType = "user-ui"
141+
RunningContextTypeTestSuite RunningContextType = "testsuite"
142+
RunningContextTypeTestTrigger RunningContextType = "testtrigger"
143+
RunningContextTypeScheduler RunningContextType = "scheduler"
144+
RunningContextTypeEmpty RunningContextType = ""
145+
)
146+
109147
// test execution request body
110148
type ExecutionRequest struct {
111149
// test execution custom name
@@ -165,17 +203,6 @@ type ExecutionRequest struct {
165203
RunningContext *RunningContext `json:"runningContext,omitempty"`
166204
}
167205

168-
type RunningContextType string
169-
170-
const (
171-
RunningContextTypeUserCLI RunningContextType = "user-cli"
172-
RunningContextTypeUserUI RunningContextType = "user-ui"
173-
RunningContextTypeTestSuite RunningContextType = "testsuite"
174-
RunningContextTypeTestTrigger RunningContextType = "testtrigger"
175-
RunningContextTypeScheduler RunningContextType = "scheduler"
176-
RunningContextTypeEmpty RunningContextType = ""
177-
)
178-
179206
// Reference to env resource
180207
type EnvReference struct {
181208
v1.LocalObjectReference `json:"reference"`
@@ -187,6 +214,7 @@ type EnvReference struct {
187214
MapToVariables bool `json:"mapToVariables,omitempty"`
188215
}
189216

217+
// +kubebuilder:validation:Enum=queued;running;passed;failed;aborted;timeout
190218
type ExecutionStatus string
191219

192220
// List of ExecutionStatus

apis/testsource/v1/testsource_types.go

+32-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type TestSourceSpec struct {
2828
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
2929
// Important: Run "make" to regenerate code after modifying this file
3030

31-
Type_ string `json:"type,omitempty"`
31+
Type_ TestSourceType `json:"type,omitempty"`
3232
// repository of test content
3333
Repository *Repository `json:"repository,omitempty"`
3434
// test content body
@@ -37,6 +37,19 @@ type TestSourceSpec struct {
3737
Uri string `json:"uri,omitempty"`
3838
}
3939

40+
// +kubebuilder:validation:Enum=string;file-uri;git-file;git-dir;git
41+
type TestSourceType string
42+
43+
const (
44+
TestSourceTypeString TestSourceType = "string"
45+
TestSourceTypeFileURI TestSourceType = "file-uri"
46+
// Deprecated: use git instead
47+
TestSourceTypeGitFile TestSourceType = "git-file"
48+
// Deprecated: use git instead
49+
TestSourceTypeGitDir TestSourceType = "git-dir"
50+
TestSourceTypeGit TestSourceType = "git"
51+
)
52+
4053
// Testkube internal reference for secret storage in Kubernetes secrets
4154
type SecretRef struct {
4255
// object kubernetes namespace
@@ -58,14 +71,28 @@ type Repository struct {
5871
// commit id (sha) for checkout
5972
Commit string `json:"commit,omitempty"`
6073
// if needed we can checkout particular path (dir or file) in case of BIG/mono repositories
61-
Path string `json:"path,omitempty"`
62-
UsernameSecret *SecretRef `json:"usernameSecret,omitempty"`
63-
TokenSecret *SecretRef `json:"tokenSecret,omitempty"`
64-
CertificateSecret string `json:"certificateSecret,omitempty"`
74+
Path string `json:"path,omitempty"`
75+
UsernameSecret *SecretRef `json:"usernameSecret,omitempty"`
76+
TokenSecret *SecretRef `json:"tokenSecret,omitempty"`
77+
// git auth certificate secret for private repositories
78+
CertificateSecret string `json:"certificateSecret,omitempty"`
6579
// if provided we checkout the whole repository and run test from this directory
6680
WorkingDir string `json:"workingDir,omitempty"`
81+
// auth type for git requests
82+
AuthType GitAuthType `json:"authType,omitempty"`
6783
}
6884

85+
// GitAuthType defines git auth type
86+
// +kubebuilder:validation:Enum=basic;header
87+
type GitAuthType string
88+
89+
const (
90+
// GitAuthTypeBasic for git basic auth requests
91+
GitAuthTypeBasic GitAuthType = "basic"
92+
// GitAuthTypeHeader for git header auth requests
93+
GitAuthTypeHeader GitAuthType = "header"
94+
)
95+
6996
// TestSourceStatus defines the observed state of TestSource
7097
type TestSourceStatus struct {
7198
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster

apis/testsuite/v1/testsuite_types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type TestSuiteStepSpec struct {
5656
Delay *TestSuiteStepDelay `json:"delay,omitempty"`
5757
}
5858

59-
// TestSuiteStepType deines different type of test suite steps
59+
// TestSuiteStepType defines different type of test suite steps
6060
type TestSuiteStepType string
6161

6262
const (

apis/testsuite/v2/testsuite_conversion.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (src *TestSuite) ConvertTo(dstRaw conversion.Hub) error {
5858
for i := range stepType.Source {
5959
value := stepType.Source[i]
6060
step := testkubev1.TestSuiteStepSpec{
61-
Type: value.Type,
61+
Type: string(value.Type),
6262
}
6363

6464
if value.Delay != nil {
@@ -132,7 +132,7 @@ func (dst *TestSuite) ConvertFrom(srcRaw conversion.Hub) error {
132132
for i := range stepType.source {
133133
value := stepType.source[i]
134134
step := TestSuiteStepSpec{
135-
Type: value.Type,
135+
Type: TestSuiteStepType(value.Type),
136136
}
137137

138138
if value.Delay != nil {

apis/testsuite/v2/testsuite_types.go

+16-14
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ type Variable commonv1.Variable
4747

4848
// TestSuiteStepSpec for particular type will have config for possible step types
4949
type TestSuiteStepSpec struct {
50-
Type string `json:"type,omitempty"`
50+
Type TestSuiteStepType `json:"type,omitempty"`
5151
Execute *TestSuiteStepExecute `json:"execute,omitempty"`
5252
Delay *TestSuiteStepDelay `json:"delay,omitempty"`
5353
}
5454

55-
// TestSuiteStepType deines different type of test suite steps
55+
// TestSuiteStepType defines different type of test suite steps
56+
// +kubebuilder:validation:Enum=execute;delay
5657
type TestSuiteStepType string
5758

5859
const (
@@ -76,11 +77,22 @@ type TestSuiteStepDelay struct {
7677
// running context for test or test suite execution
7778
type RunningContext struct {
7879
// One of possible context types
79-
Type_ string `json:"type"`
80+
Type_ RunningContextType `json:"type"`
8081
// Context value depending from its type
8182
Context string `json:"context,omitempty"`
8283
}
8384

85+
type RunningContextType string
86+
87+
const (
88+
RunningContextTypeUserCLI RunningContextType = "user-cli"
89+
RunningContextTypeUserUI RunningContextType = "user-ui"
90+
RunningContextTypeTestSuite RunningContextType = "testsuite"
91+
RunningContextTypeTestTrigger RunningContextType = "testtrigger"
92+
RunningContextTypeScheduler RunningContextType = "scheduler"
93+
RunningContextTypeEmpty RunningContextType = ""
94+
)
95+
8496
// test suite execution request body
8597
type TestSuiteExecutionRequest struct {
8698
// test execution custom name
@@ -105,17 +117,7 @@ type TestSuiteExecutionRequest struct {
105117
RunningContext *RunningContext `json:"runningContext,omitempty"`
106118
}
107119

108-
type RunningContextType string
109-
110-
const (
111-
RunningContextTypeUserCLI RunningContextType = "user-cli"
112-
RunningContextTypeUserUI RunningContextType = "user-ui"
113-
RunningContextTypeTestSuite RunningContextType = "testsuite"
114-
RunningContextTypeTestTrigger RunningContextType = "testtrigger"
115-
RunningContextTypeScheduler RunningContextType = "scheduler"
116-
RunningContextTypeEmpty RunningContextType = ""
117-
)
118-
120+
// +kubebuilder:validation:Enum=queued;running;passed;failed;aborting;aborted;timeout
119121
type TestSuiteExecutionStatus string
120122

121123
// List of TestSuiteExecutionStatus

0 commit comments

Comments
 (0)