Skip to content

Commit

Permalink
Added testcases to CRDGenerator
Browse files Browse the repository at this point in the history
Signed-off-by: MichaelMorris <michael.morris@est.tech>
  • Loading branch information
MichaelMorrisEst committed Jan 8, 2025
1 parent 8e273c0 commit 77020ea
Showing 1 changed file with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,6 +104,7 @@ void choosingCRDVersionsShouldWork() {
@Test
void addingCustomResourceInfosShouldWork() {
CRDGenerator generator = newCRDGenerator();

assertTrue(generator.getCustomResourceInfos().isEmpty());

generator.customResourceClasses();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 77020ea

Please sign in to comment.