Skip to content

Commit bcefcd9

Browse files
committed
feat: improve test coverage for skipCrds
1 parent 5339ae8 commit bcefcd9

File tree

9 files changed

+190
-3
lines changed

9 files changed

+190
-3
lines changed

helm-java/src/main/java/com/marcnuri/helm/InstallCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* @author Miriam Schmidt
3434
* @author Kevin J. Mckernan
3535
* @author Christian Gebhard
36+
* @author Antonio Fernandez Alhambra
3637
*/
3738
public class InstallCommand extends HelmCommand<Release> {
3839

helm-java/src/main/java/com/marcnuri/helm/TemplateCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
/**
2929
* @author Marc Nuri
3030
* @author Andres F. Vallecilla
31+
* @author Antonio Fernandez Alhambra
3132
*/
3233
public class TemplateCommand extends HelmCommand<String> {
3334

helm-java/src/main/java/com/marcnuri/helm/UpgradeCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* @author Miriam Schmidt
3434
* @author Kevin J. Mckernan
3535
* @author Christian Gebhard
36+
* @author Antonio Fernandez Alhambra
3637
*/
3738
public class UpgradeCommand extends HelmCommand<Release> {
3839

helm-java/src/test/java/com/marcnuri/helm/HelmInstallTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
/**
3838
* @author Marc Nuri
3939
* @author Kevin J. Mckernan
40+
* @author Antonio Fernandez Alhambra
4041
*/
4142
class HelmInstallTest {
4243

@@ -230,7 +231,7 @@ void withDisableOpenApiValidation() {
230231
}
231232

232233
@Test
233-
void skipCrds() {
234+
void skipCrdsWithoutCrdsInChart() {
234235
final Release result = helm.install()
235236
.clientOnly()
236237
.debug()

helm-java/src/test/java/com/marcnuri/helm/HelmKubernetesTest.java

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
/**
4343
* @author Marc Nuri
4444
* @author Miriam Schmidt
45+
* @author Antonio Fernandez Alhambra
4546
*/
4647
@EnabledOnOs(OS.LINUX)
4748
class HelmKubernetesTest {
@@ -166,6 +167,67 @@ void withNamespaceAndCreateNamespace() {
166167
// TODO: Add withDescription test when we can check the status (status command implementation)
167168
}
168169

170+
@Nested
171+
class WithCrds {
172+
173+
@TempDir
174+
private Path crdTempDir;
175+
private Helm helmWithCrds;
176+
177+
@BeforeEach
178+
void setUp() throws IOException {
179+
helmWithCrds = Helm.create().withName("install-crd-chart").withDir(crdTempDir).call();
180+
Files.write(Files.createDirectories(crdTempDir.resolve("install-crd-chart").resolve("crds")).resolve("crd.yaml"),
181+
("apiVersion: apiextensions.k8s.io/v1\n" +
182+
"kind: CustomResourceDefinition\n" +
183+
"metadata:\n" +
184+
" name: installwidgets.helm-java.example.com\n" +
185+
"spec:\n" +
186+
" group: helm-java.example.com\n" +
187+
" names:\n" +
188+
" kind: InstallWidget\n" +
189+
" plural: installwidgets\n" +
190+
" scope: Namespaced\n" +
191+
" versions:\n" +
192+
" - name: v1\n" +
193+
" served: true\n" +
194+
" storage: true\n" +
195+
" schema:\n" +
196+
" openAPIV3Schema:\n" +
197+
" type: object\n").getBytes(StandardCharsets.UTF_8),
198+
StandardOpenOption.CREATE);
199+
}
200+
201+
@Test
202+
void withoutSkipCrdsInstallsCrds() {
203+
final Release result = helmWithCrds.install()
204+
.withKubeConfig(kubeConfigFile)
205+
.withName("helm-install-with-crds")
206+
.debug()
207+
.call();
208+
assertThat(result)
209+
.returns("helm-install-with-crds", Release::getName)
210+
.returns("deployed", Release::getStatus)
211+
.extracting(Release::getOutput).asString()
212+
.contains("installwidgets.helm-java.example.com");
213+
}
214+
215+
@Test
216+
void skipCrdsDoesNotInstallCrds() {
217+
final Release result = helmWithCrds.install()
218+
.withKubeConfig(kubeConfigFile)
219+
.withName("helm-install-skip-crds")
220+
.skipCrds()
221+
.debug()
222+
.call();
223+
assertThat(result)
224+
.returns("helm-install-skip-crds", Release::getName)
225+
.returns("deployed", Release::getStatus)
226+
.extracting(Release::getOutput).asString()
227+
.doesNotContain("installwidgets.helm-java.example.com");
228+
}
229+
}
230+
169231
@Nested
170232
class Invalid {
171233

@@ -557,7 +619,7 @@ void withWaitAndCustomTimeout() {
557619
}
558620

559621
@Test
560-
void skipCrds() {
622+
void skipCrdsWithoutCrdsInChart() {
561623
helm.install().withName("upgrade-skip-crds").withKubeConfig(kubeConfigFile).call();
562624
final Release result = helm.upgrade()
563625
.withKubeConfig(kubeConfigFile)
@@ -570,6 +632,70 @@ void skipCrds() {
570632
}
571633
}
572634

635+
@Nested
636+
class WithCrds {
637+
638+
@TempDir
639+
private Path crdTempDir;
640+
private Helm helmWithCrds;
641+
642+
@BeforeEach
643+
void setUp() throws IOException {
644+
helmWithCrds = Helm.create().withName("upgrade-crd-chart").withDir(crdTempDir).call();
645+
Files.write(Files.createDirectories(crdTempDir.resolve("upgrade-crd-chart").resolve("crds")).resolve("crd.yaml"),
646+
("apiVersion: apiextensions.k8s.io/v1\n" +
647+
"kind: CustomResourceDefinition\n" +
648+
"metadata:\n" +
649+
" name: upgradewidgets.helm-java.example.com\n" +
650+
"spec:\n" +
651+
" group: helm-java.example.com\n" +
652+
" names:\n" +
653+
" kind: UpgradeWidget\n" +
654+
" plural: upgradewidgets\n" +
655+
" scope: Namespaced\n" +
656+
" versions:\n" +
657+
" - name: v1\n" +
658+
" served: true\n" +
659+
" storage: true\n" +
660+
" schema:\n" +
661+
" openAPIV3Schema:\n" +
662+
" type: object\n").getBytes(StandardCharsets.UTF_8),
663+
StandardOpenOption.CREATE);
664+
// Install the chart first to have a release to upgrade
665+
helmWithCrds.install()
666+
.withKubeConfig(kubeConfigFile)
667+
.withName("upgrade-crd-release")
668+
.call();
669+
}
670+
671+
@Test
672+
void withoutSkipCrdsIncludesCrds() {
673+
final Release result = helmWithCrds.upgrade()
674+
.withKubeConfig(kubeConfigFile)
675+
.withName("upgrade-crd-release")
676+
.debug()
677+
.call();
678+
assertThat(result)
679+
.returns("2", Release::getRevision)
680+
.returns("deployed", Release::getStatus);
681+
}
682+
683+
@Test
684+
void skipCrdsExcludesCrds() {
685+
final Release result = helmWithCrds.upgrade()
686+
.withKubeConfig(kubeConfigFile)
687+
.withName("upgrade-crd-release")
688+
.skipCrds()
689+
.debug()
690+
.call();
691+
assertThat(result)
692+
.returns("2", Release::getRevision)
693+
.returns("deployed", Release::getStatus)
694+
.extracting(Release::getOutput).asString()
695+
.doesNotContain("upgradewidgets.helm-java.example.com");
696+
}
697+
}
698+
573699
@Nested
574700
class Invalid {
575701
@Test

helm-java/src/test/java/com/marcnuri/helm/HelmTemplateTest.java

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
/**
3535
* @author Marc Nuri
3636
* @author Andres F. Vallecilla
37+
* @author Antonio Fernandez Alhambra
3738
*/
3839
class HelmTemplateTest {
3940

@@ -109,7 +110,7 @@ void withInvalidValuesAndDebug() {
109110
}
110111

111112
@Test
112-
void skipCrds() {
113+
void skipCrdsWithoutCrdsInChart() {
113114
final String result = helm.template()
114115
.skipCrds()
115116
.call();
@@ -118,6 +119,59 @@ void skipCrds() {
118119
}
119120
}
120121

122+
@Nested
123+
class FromLocalChartWithCrds {
124+
125+
@TempDir
126+
private Path tempDir;
127+
private Helm helm;
128+
129+
@BeforeEach
130+
void setUp() throws IOException {
131+
helm = Helm.create().withName("chart-with-crds").withDir(tempDir).call();
132+
Files.write(Files.createDirectories(tempDir.resolve("chart-with-crds").resolve("crds")).resolve("crd.yaml"),
133+
("apiVersion: apiextensions.k8s.io/v1\n" +
134+
"kind: CustomResourceDefinition\n" +
135+
"metadata:\n" +
136+
" name: widgets.example.com\n" +
137+
"spec:\n" +
138+
" group: example.com\n" +
139+
" names:\n" +
140+
" kind: Widget\n" +
141+
" plural: widgets\n" +
142+
" scope: Namespaced\n" +
143+
" versions:\n" +
144+
" - name: v1\n" +
145+
" served: true\n" +
146+
" storage: true\n" +
147+
" schema:\n" +
148+
" openAPIV3Schema:\n" +
149+
" type: object\n").getBytes(StandardCharsets.UTF_8),
150+
StandardOpenOption.CREATE);
151+
}
152+
153+
@Test
154+
void withDefaultsDoesNotIncludeCrds() {
155+
// Helm template by default does not include CRDs from the crds/ directory
156+
final String result = helm.template().call();
157+
assertThat(result)
158+
.doesNotContain("kind: CustomResourceDefinition")
159+
.contains("name: release-name-chart-with-crds");
160+
}
161+
162+
@Test
163+
void skipCrdsWithCrdsInChartWorks() {
164+
// skipCrds ensures CRDs are not included even when the chart contains them
165+
final String result = helm.template()
166+
.skipCrds()
167+
.call();
168+
assertThat(result)
169+
.doesNotContain("kind: CustomResourceDefinition")
170+
.doesNotContain("name: widgets.example.com")
171+
.contains("name: release-name-chart-with-crds");
172+
}
173+
}
174+
121175
@Nested
122176
class FromRepo {
123177

lib/api/src/main/java/com/marcnuri/helm/jni/InstallOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* @author Miriam Schmidt
2424
* @author Kevin J. Mckernan
2525
* @author Christian Gebhard
26+
* @author Antonio Fernandez Alhambra
2627
*/
2728
@Structure.FieldOrder({
2829
"name",

lib/api/src/main/java/com/marcnuri/helm/jni/TemplateOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
/**
2222
* @author Marc Nuri
2323
* @author Andres F. Vallecilla
24+
* @author Antonio Fernandez Alhambra
2425
*/
2526
@Structure.FieldOrder({
2627
"name",

lib/api/src/main/java/com/marcnuri/helm/jni/UpgradeOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* @author Miriam Schmidt
2424
* @author Kevin J. Mckernan
2525
* @author Christian Gebhard
26+
* @author Antonio Fernandez Alhambra
2627
*/
2728
@Structure.FieldOrder({
2829
"name",

0 commit comments

Comments
 (0)