diff --git a/crd-generator/test/pom.xml b/crd-generator/test/pom.xml index c00c3847d1e..f6517b92546 100644 --- a/crd-generator/test/pom.xml +++ b/crd-generator/test/pom.xml @@ -38,6 +38,10 @@ io.fabric8 crd-generator-api + + io.fabric8 + crd-generator-api-v2 + org.projectlombok lombok diff --git a/crd-generator/test/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.java b/crd-generator/test/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.java index 8d05c1cb7de..e2727a7cb10 100644 --- a/crd-generator/test/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.java +++ b/crd-generator/test/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.java @@ -72,7 +72,7 @@ void tearDown() { @ParameterizedTest(name = "{1}.{2} parallel={3}") @MethodSource("crdApprovalTests") @DisplayName("CRD Generator V1 Approval Tests") - void v1ApprovalTest( + void apiV1ApprovalTest( Class>[] crClasses, String expectedCrd, String version, boolean parallel) { final Map> result = new CRDGenerator() .withParallelGenerationEnabled(parallel) @@ -94,23 +94,58 @@ void v1ApprovalTest( new Namer(expectedCrd, version)); } + @ParameterizedTest(name = "{1}.{2} parallel={3}") + @MethodSource("crdV1ApprovalTests") + @DisplayName("CRD Generator V2 Approval Tests") + void apiV2ApprovalTest( + Class>[] crClasses, String expectedCrd, String version, boolean parallel) { + Approvals.settings().allowMultipleVerifyCallsForThisMethod(); + final Map> result = new io.fabric8.crdv2.generator.CRDGenerator() + .withParallelGenerationEnabled(parallel) + .inOutputDir(tempDir) + .customResourceClasses(crClasses) + .forCRDVersions(version) + .detailedGenerate() + .getCRDDetailsPerNameAndVersion(); + + assertThat(result) + .withFailMessage(() -> "Could not find expected CRD " + expectedCrd + + " in results. Found instead: " + result.keySet()) + .containsKey(expectedCrd) + .extractingByKey(expectedCrd) + .isNotNull(); + + Approvals.verify( + new FileApprovalWriter(new File(result.get(expectedCrd).get(version).getFilePath())), + new Namer(expectedCrd, version)); + } + static Stream crdApprovalTests() { + return Stream.concat( + crdApprovalBaseCases("v1"), + crdApprovalBaseCases("v1beta1")).map(tc -> Arguments.of(tc.crClasses, tc.expectedCrd, tc.version, tc.parallel)); + } + + static Stream crdV1ApprovalTests() { + return crdApprovalBaseCases("v1") + .map(tc -> Arguments.of(tc.crClasses, tc.expectedCrd, tc.version, tc.parallel)); + } + + static Stream crdApprovalBaseCases(String crdVersion) { final List cases = new ArrayList<>(); - for (String crdVersion : new String[] { "v1", "v1beta1" }) { - for (boolean parallel : new boolean[] { false, true }) { - cases.add(new TestCase("annotateds.samples.fabric8.io", crdVersion, parallel, Annotated.class)); - cases.add(new TestCase("complexkinds.samples.fabric8.io", crdVersion, parallel, Complex.class)); - cases.add(new TestCase("children.sample.fabric8.io", crdVersion, parallel, Child.class)); - cases.add(new TestCase("containingjsons.sample.fabric8.io", crdVersion, parallel, ContainingJson.class)); - cases.add(new TestCase("k8svalidations.samples.fabric8.io", crdVersion, parallel, K8sValidation.class)); - cases.add(new TestCase("containingmaps.sample.fabric8.io", crdVersion, parallel, ContainingMaps.class)); - cases.add(new TestCase("multiples.sample.fabric8.io", crdVersion, parallel, - io.fabric8.crd.generator.approvaltests.multipleversions.v1.Multiple.class, - io.fabric8.crd.generator.approvaltests.multipleversions.v2.Multiple.class)); - cases.add(new TestCase("nocyclics.sample.fabric8.io", crdVersion, parallel, NoCyclic.class)); - } + for (boolean parallel : new boolean[] { false, true }) { + cases.add(new TestCase("annotateds.samples.fabric8.io", crdVersion, parallel, Annotated.class)); + cases.add(new TestCase("complexkinds.samples.fabric8.io", crdVersion, parallel, Complex.class)); + cases.add(new TestCase("children.sample.fabric8.io", crdVersion, parallel, Child.class)); + cases.add(new TestCase("containingjsons.sample.fabric8.io", crdVersion, parallel, ContainingJson.class)); + cases.add(new TestCase("k8svalidations.samples.fabric8.io", crdVersion, parallel, K8sValidation.class)); + cases.add(new TestCase("containingmaps.sample.fabric8.io", crdVersion, parallel, ContainingMaps.class)); + cases.add(new TestCase("multiples.sample.fabric8.io", crdVersion, parallel, + io.fabric8.crd.generator.approvaltests.multipleversions.v1.Multiple.class, + io.fabric8.crd.generator.approvaltests.multipleversions.v2.Multiple.class)); + cases.add(new TestCase("nocyclics.sample.fabric8.io", crdVersion, parallel, NoCyclic.class)); } - return cases.stream().map(tc -> Arguments.of(tc.crClasses, tc.expectedCrd, tc.version, tc.parallel)); + return cases.stream(); } private static final class TestCase { @@ -119,6 +154,7 @@ private static final class TestCase { private final String version; private final boolean parallel; + @SafeVarargs public TestCase(String expectedCrd, String version, boolean parallel, Class>... crClasses) { this.expectedCrd = expectedCrd; this.version = version;