Skip to content

Commit 60f7f99

Browse files
committed
test: add suite and initializer tests for conflicting markers analysis
1 parent 994e70e commit 60f7f99

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package conflictingmarkers_test
18+
19+
import (
20+
"testing"
21+
22+
. "github.com/onsi/ginkgo/v2"
23+
. "github.com/onsi/gomega"
24+
)
25+
26+
func TestConflictingMarkers(t *testing.T) {
27+
RegisterFailHandler(Fail)
28+
RunSpecs(t, "conflictingmarkers")
29+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package conflictingmarkers_test
18+
19+
import (
20+
. "github.com/onsi/ginkgo/v2"
21+
. "github.com/onsi/gomega"
22+
23+
"k8s.io/apimachinery/pkg/util/validation/field"
24+
"sigs.k8s.io/kube-api-linter/pkg/analysis/conflictingmarkers"
25+
"sigs.k8s.io/kube-api-linter/pkg/analysis/initializer"
26+
)
27+
28+
var _ = Describe("conflictingmarkers initializer", func() {
29+
Context("config validation", func() {
30+
type testCase struct {
31+
config conflictingmarkers.ConflictingMarkersConfig
32+
expectedErr string
33+
}
34+
35+
DescribeTable("should validate the provided config", func(in testCase) {
36+
ci, ok := conflictingmarkers.Initializer().(initializer.ConfigurableAnalyzerInitializer)
37+
Expect(ok).To(BeTrue())
38+
39+
errs := ci.ValidateConfig(&in.config, field.NewPath("conflictingmarkers"))
40+
if len(in.expectedErr) > 0 {
41+
Expect(errs.ToAggregate()).To(MatchError(in.expectedErr))
42+
} else {
43+
Expect(errs).To(HaveLen(0), "No errors were expected")
44+
}
45+
},
46+
Entry("With a valid empty config", testCase{
47+
config: conflictingmarkers.ConflictingMarkersConfig{
48+
Conflicts: []conflictingmarkers.ConflictSet{},
49+
},
50+
expectedErr: "",
51+
}),
52+
Entry("With a valid conflict", testCase{
53+
config: conflictingmarkers.ConflictingMarkersConfig{
54+
Conflicts: []conflictingmarkers.ConflictSet{
55+
{
56+
Name: "test_conflict",
57+
SetA: []string{"marker1"},
58+
SetB: []string{"marker2"},
59+
Description: "Test conflict",
60+
},
61+
},
62+
},
63+
expectedErr: "",
64+
}),
65+
Entry("With missing name", testCase{
66+
config: conflictingmarkers.ConflictingMarkersConfig{
67+
Conflicts: []conflictingmarkers.ConflictSet{
68+
{
69+
Name: "",
70+
SetA: []string{"marker1"},
71+
SetB: []string{"marker2"},
72+
Description: "Test conflict",
73+
},
74+
},
75+
},
76+
expectedErr: "conflictingmarkers.conflicts[0].name: Required value: name is required",
77+
}),
78+
Entry("With overlapping markers", testCase{
79+
config: conflictingmarkers.ConflictingMarkersConfig{
80+
Conflicts: []conflictingmarkers.ConflictSet{
81+
{
82+
Name: "test_conflict",
83+
SetA: []string{"marker1", "marker2"},
84+
SetB: []string{"marker2", "marker3"},
85+
Description: "Test conflict",
86+
},
87+
},
88+
},
89+
expectedErr: "conflictingmarkers.conflicts[0]: Invalid value: conflictingmarkers.ConflictSet{Name:\"test_conflict\", SetA:[]string{\"marker1\", \"marker2\"}, SetB:[]string{\"marker2\", \"marker3\"}, Description:\"Test conflict\"}: sets cannot contain overlapping markers",
90+
}),
91+
Entry("With missing description", testCase{
92+
config: conflictingmarkers.ConflictingMarkersConfig{
93+
Conflicts: []conflictingmarkers.ConflictSet{
94+
{
95+
Name: "test_conflict",
96+
SetA: []string{"marker1"},
97+
SetB: []string{"marker2"},
98+
},
99+
},
100+
},
101+
expectedErr: "conflictingmarkers.conflicts[0].description: Required value: description is required",
102+
}),
103+
)
104+
})
105+
})

0 commit comments

Comments
 (0)