diff --git a/crd-generator/api-v2/src/test/java/io/fabric8/crdv2/generator/CRDGeneratorTest.java b/crd-generator/api-v2/src/test/java/io/fabric8/crdv2/generator/CRDGeneratorTest.java index 7873234759..849ad21446 100644 --- a/crd-generator/api-v2/src/test/java/io/fabric8/crdv2/generator/CRDGeneratorTest.java +++ b/crd-generator/api-v2/src/test/java/io/fabric8/crdv2/generator/CRDGeneratorTest.java @@ -60,6 +60,7 @@ import static io.fabric8.crdv2.generator.CRDGeneratorAssertions.assertFileEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -103,6 +104,7 @@ void choosingCRDVersionsShouldWork() { @Test void addingCustomResourceInfosShouldWork() { CRDGenerator generator = newCRDGenerator(); + assertTrue(generator.getCustomResourceInfos().isEmpty()); generator.customResourceClasses(); @@ -477,6 +479,66 @@ void checkGenerationIsDeterministic() throws Exception { assertTrue(outputDir.delete()); } + @Test + void checkMinQuotesDefault() throws Exception { + final File outputDir = Files.createTempDirectory("crd-").toFile(); + final String crdName = CustomResourceInfo.fromClass(Complex.class).crdName(); + CRDGenerationInfo crdInfo = newCRDGenerator() + .inOutputDir(outputDir) + .forCRDVersions("v1") + .customResourceClasses(Complex.class) + .detailedGenerate(); + + File crdFile = new File(crdInfo.getCRDInfos(crdName).get("v1").getFilePath()); + String crd = Files.readString(crdFile.toPath()); + assertTrue(crd.contains("\"complexkinds.example.com\"")); + + // only delete the generated files if the test is successful + assertTrue(crdFile.delete()); + assertTrue(outputDir.delete()); + } + + @Test + void checkMinQuotesFalse() throws Exception { + final File outputDir = Files.createTempDirectory("crd-").toFile(); + final String crdName = CustomResourceInfo.fromClass(Complex.class).crdName(); + CRDGenerationInfo crdInfo = newCRDGenerator() + .inOutputDir(outputDir) + .forCRDVersions("v1") + .customResourceClasses(Complex.class) + .withMinQuotes(false) + .detailedGenerate(); + + File crdFile = new File(crdInfo.getCRDInfos(crdName).get("v1").getFilePath()); + String crd = Files.readString(crdFile.toPath()); + assertTrue(crd.contains("\"complexkinds.example.com\"")); + + // only delete the generated files if the test is successful + assertTrue(crdFile.delete()); + assertTrue(outputDir.delete()); + } + + @Test + void checkMinQuotesTrue() throws Exception { + final File outputDir = Files.createTempDirectory("crd-").toFile(); + final String crdName = CustomResourceInfo.fromClass(Complex.class).crdName(); + CRDGenerationInfo crdInfo = newCRDGenerator() + .inOutputDir(outputDir) + .forCRDVersions("v1") + .customResourceClasses(Complex.class) + .withMinQuotes(true) + .detailedGenerate(); + + File crdFile = new File(crdInfo.getCRDInfos(crdName).get("v1").getFilePath()); + String crd = Files.readString(crdFile.toPath()); + assertTrue(crd.contains("complexkinds.example.com")); + assertFalse(crd.contains("\"complexkinds.example.com\"")); + + // only delete the generated files if the test is successful + assertTrue(crdFile.delete()); + assertTrue(outputDir.delete()); + } + @RepeatedTest(value = 10) void checkGenerationMultipleVersionsOfCRDsIsDeterministic() throws Exception { // generated CRD