Skip to content

Commit 42a1894

Browse files
jimmidysondkoshkin
authored andcommitted
test: Add workerconfig variable tests
1 parent 75171a6 commit 42a1894

File tree

7 files changed

+94
-23
lines changed

7 files changed

+94
-23
lines changed

api/v1alpha1/workerconfig_types.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"maps"
88

99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10-
1110
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1211
)
1312

@@ -32,7 +31,7 @@ type WorkerConfigSpec struct {
3231
Docker *DockerWorkerSpec `json:"docker,omitempty"`
3332
}
3433

35-
func (s WorkerConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
34+
func (s WorkerConfigSpec) VariableSchema() clusterv1.VariableSchema {
3635
workerConfigProps := GenericWorkerConfig{}.VariableSchema()
3736

3837
switch {
@@ -65,8 +64,7 @@ func (s WorkerConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:g
6564
return workerConfigProps
6665
}
6766

68-
type GenericWorkerConfig struct {
69-
}
67+
type GenericWorkerConfig struct{}
7068

7169
func (GenericWorkerConfig) VariableSchema() clusterv1.VariableSchema {
7270
return clusterv1.VariableSchema{

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/pkg/testutils/capitest/variables.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,32 @@ func ValidateDiscoverVariables[T mutation.DiscoverVariables](
3737

3838
t.Parallel()
3939

40+
g := gomega.NewWithT(t)
41+
h := handlerCreator()
42+
resp := &runtimehooksv1.DiscoverVariablesResponse{}
43+
h.DiscoverVariables(
44+
context.Background(),
45+
&runtimehooksv1.DiscoverVariablesRequest{},
46+
resp,
47+
)
48+
49+
g.Expect(resp.Status).To(gomega.Equal(runtimehooksv1.ResponseStatusSuccess))
50+
g.Expect(resp.Variables).To(gomega.HaveLen(1))
51+
52+
variable := resp.Variables[0]
53+
g.Expect(variable).To(gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
54+
"Name": gomega.Equal(variableName),
55+
"Required": gomega.Equal(variableRequired),
56+
"Schema": gomega.Equal(*variableSchema),
57+
}))
58+
4059
for idx := range variableTestDefs {
4160
tt := variableTestDefs[idx]
4261

4362
t.Run(tt.Name, func(t *testing.T) {
4463
t.Parallel()
4564

4665
g := gomega.NewWithT(t)
47-
h := handlerCreator()
48-
resp := &runtimehooksv1.DiscoverVariablesResponse{}
49-
h.DiscoverVariables(
50-
context.Background(),
51-
&runtimehooksv1.DiscoverVariablesRequest{},
52-
resp,
53-
)
54-
55-
g.Expect(resp.Status).To(gomega.Equal(runtimehooksv1.ResponseStatusSuccess))
56-
g.Expect(resp.Variables).To(gomega.HaveLen(1))
57-
58-
variable := resp.Variables[0]
59-
g.Expect(variable).To(gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
60-
"Name": gomega.Equal(variableName),
61-
"Required": gomega.Equal(variableRequired),
62-
"Schema": gomega.Equal(*variableSchema),
63-
}))
6466

6567
encodedVals, err := json.Marshal(tt.Vals)
6668
g.Expect(err).NotTo(gomega.HaveOccurred())

pkg/handlers/aws/workerconfig/variables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2023 D2iQ, Inc. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package clusterconfig
4+
package workerconfig
55

66
import (
77
"context"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package workerconfig
5+
6+
import (
7+
"testing"
8+
9+
"k8s.io/utils/ptr"
10+
11+
"github.com/d2iq-labs/capi-runtime-extensions/api/v1alpha1"
12+
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/testutils/capitest"
13+
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/workerconfig"
14+
)
15+
16+
func TestVariableValidation(t *testing.T) {
17+
capitest.ValidateDiscoverVariables(
18+
t,
19+
workerconfig.MetaVariableName,
20+
ptr.To(v1alpha1.WorkerConfigSpec{AWS: &v1alpha1.AWSWorkerSpec{}}.VariableSchema()),
21+
false,
22+
NewVariable,
23+
)
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package workerconfig
5+
6+
import (
7+
"testing"
8+
9+
"k8s.io/utils/ptr"
10+
11+
"github.com/d2iq-labs/capi-runtime-extensions/api/v1alpha1"
12+
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/testutils/capitest"
13+
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/workerconfig"
14+
)
15+
16+
func TestVariableValidation(t *testing.T) {
17+
capitest.ValidateDiscoverVariables(
18+
t,
19+
workerconfig.MetaVariableName,
20+
ptr.To(v1alpha1.WorkerConfigSpec{Docker: &v1alpha1.DockerWorkerSpec{}}.VariableSchema()),
21+
false,
22+
NewVariable,
23+
)
24+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package workerconfig
5+
6+
import (
7+
"testing"
8+
9+
"k8s.io/utils/ptr"
10+
11+
"github.com/d2iq-labs/capi-runtime-extensions/api/v1alpha1"
12+
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/testutils/capitest"
13+
)
14+
15+
func TestVariableValidation(t *testing.T) {
16+
capitest.ValidateDiscoverVariables(
17+
t,
18+
MetaVariableName,
19+
ptr.To(v1alpha1.GenericWorkerConfig{}.VariableSchema()),
20+
false,
21+
NewVariable,
22+
)
23+
}

0 commit comments

Comments
 (0)