Skip to content

Commit 4eed4e5

Browse files
committed
test: update e2e tests for optional feature gate infrastructure
Updated feature gate tests to reflect the new optional behavior: - Added test to verify feature gates are NOT generated by default - Updated existing tests to use --with-feature-gates flag when needed - Fixed test expectations for auto-detection scenarios - Ensured tests properly validate both opt-in and discovery behavior Tests now correctly validate: 1. Default behavior: no feature gate infrastructure generated 2. Explicit flag: infrastructure generated when requested 3. Auto-detection: infrastructure generated when markers discovered
1 parent cc56232 commit 4eed4e5

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

test/e2e/v4/featuregates_test.go

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ var _ = Describe("Feature Gates", func() {
5858
By("initializing a project")
5959
err := kbc.Init(
6060
"--domain", kbc.Domain,
61+
"--with-feature-gates",
6162
)
6263
Expect(err).NotTo(HaveOccurred())
6364

@@ -91,6 +92,43 @@ var _ = Describe("Feature Gates", func() {
9192
Expect(string(typesContent)).To(ContainSubstring("+feature-gate"))
9293
})
9394

95+
It("should NOT scaffold feature gates by default", func() {
96+
By("initializing a project without feature gates flag")
97+
err := kbc.Init(
98+
"--domain", kbc.Domain,
99+
)
100+
Expect(err).NotTo(HaveOccurred())
101+
102+
By("creating API without feature gates flag")
103+
err = kbc.CreateAPI(
104+
"--group", kbc.Group,
105+
"--version", kbc.Version,
106+
"--kind", kbc.Kind,
107+
"--resource", "--controller",
108+
"--make=false",
109+
)
110+
Expect(err).NotTo(HaveOccurred())
111+
112+
By("verifying feature gates file was NOT generated")
113+
featureGatesFile := filepath.Join(kbc.Dir, "internal", "featuregates", "featuregates.go")
114+
Expect(featureGatesFile).NotTo(BeAnExistingFile())
115+
116+
By("verifying main.go does NOT have feature gates flag")
117+
mainFile := filepath.Join(kbc.Dir, "cmd", "main.go")
118+
Expect(mainFile).To(BeAnExistingFile())
119+
mainContent, err := os.ReadFile(mainFile)
120+
Expect(err).NotTo(HaveOccurred())
121+
Expect(string(mainContent)).NotTo(ContainSubstring("--feature-gates"))
122+
Expect(string(mainContent)).NotTo(ContainSubstring("featuregates"))
123+
124+
By("verifying API types do NOT have feature gate example")
125+
typesFile := filepath.Join(kbc.Dir, "api", kbc.Version, strings.ToLower(kbc.Kind)+"_types.go")
126+
Expect(typesFile).To(BeAnExistingFile())
127+
typesContent, err := os.ReadFile(typesFile)
128+
Expect(err).NotTo(HaveOccurred())
129+
Expect(string(typesContent)).NotTo(ContainSubstring("+feature-gate"))
130+
})
131+
94132
It("should discover feature gates from API types", func() {
95133
By("initializing a project")
96134
err := kbc.Init(
@@ -120,7 +158,7 @@ var _ = Describe("Feature Gates", func() {
120158

121159
err = pluginutil.InsertCode(
122160
typesFile,
123-
"Bar *string `json:\"bar,omitempty\"`",
161+
"Foo *string `json:\"foo,omitempty\"`",
124162
newField,
125163
)
126164
Expect(err).NotTo(HaveOccurred())
@@ -145,9 +183,10 @@ var _ = Describe("Feature Gates", func() {
145183
})
146184

147185
It("should build project with feature gates", func() {
148-
By("initializing a project")
186+
By("initializing a project with feature gates")
149187
err := kbc.Init(
150188
"--domain", kbc.Domain,
189+
"--with-feature-gates",
151190
)
152191
Expect(err).NotTo(HaveOccurred())
153192

@@ -171,9 +210,10 @@ var _ = Describe("Feature Gates", func() {
171210
})
172211

173212
It("should generate manifests with feature gates", func() {
174-
By("initializing a project")
213+
By("initializing a project with feature gates")
175214
err := kbc.Init(
176215
"--domain", kbc.Domain,
216+
"--with-feature-gates",
177217
)
178218
Expect(err).NotTo(HaveOccurred())
179219

0 commit comments

Comments
 (0)