-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:fabric8io/kubernetes-client into cr…
…d-generator-v7-development
Showing
63 changed files
with
3,413 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
crd-generator/api/src/test/java/io/fabric8/crd/generator/CRDGeneratorExamplesTest.java
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
crd-generator/api/src/test/java/io/fabric8/crd/generator/MultipleStoredVersionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.crd.generator; | ||
|
||
import io.fabric8.crd.example.multiple.v2.MultipleSpec; | ||
import io.fabric8.kubernetes.client.CustomResource; | ||
import io.fabric8.kubernetes.model.annotation.Group; | ||
import io.fabric8.kubernetes.model.annotation.Version; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.io.TempDir; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.io.File; | ||
import java.util.stream.Stream; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException; | ||
|
||
class MultipleStoredVersionsTest { | ||
|
||
@Group("sample.fabric8.io") | ||
@Version(value = "v3") | ||
public static class Multiple extends CustomResource<MultipleSpec, Void> { | ||
} | ||
|
||
@ParameterizedTest(name = "{index}: version: {0}, parallel: {1}") | ||
@DisplayName("Generate CRD for multiple stored versions throws exception") | ||
@MethodSource("multipleCrdVersions") | ||
void generateMultipleThrowsException(String crdVersion, boolean parallel, @TempDir File tmpDir) { | ||
final CRDGenerator crdGenerator = new CRDGenerator() | ||
.inOutputDir(tmpDir) | ||
.withParallelGenerationEnabled(parallel) | ||
.forCRDVersions(crdVersion) | ||
.customResourceClasses(io.fabric8.crd.example.multiple.v2.Multiple.class, Multiple.class); | ||
assertThatIllegalStateException() | ||
.isThrownBy(crdGenerator::generate) | ||
.withMessageContaining("Only one version can be marked as storage per custom resource."); | ||
} | ||
|
||
static Stream<Arguments> multipleCrdVersions() { | ||
return Stream.of("v1", "v1beta1") | ||
.flatMap(crdVersion -> Stream.of( | ||
Arguments.of(crdVersion, false), | ||
Arguments.of(crdVersion, true))); | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
...or/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.crd.generator.approvaltests; | ||
|
||
import io.fabric8.crd.generator.CRDGenerator; | ||
import io.fabric8.crd.generator.CRDInfo; | ||
import io.fabric8.crd.generator.approvaltests.annotated.Annotated; | ||
import io.fabric8.crd.generator.approvaltests.complex.Complex; | ||
import io.fabric8.crd.generator.approvaltests.inherited.Child; | ||
import io.fabric8.crd.generator.approvaltests.json.ContainingJson; | ||
import io.fabric8.crd.generator.approvaltests.k8svalidation.K8sValidation; | ||
import io.fabric8.crd.generator.approvaltests.map.ContainingMaps; | ||
import io.fabric8.crd.generator.approvaltests.nocyclic.NoCyclic; | ||
import io.fabric8.kubernetes.client.CustomResource; | ||
import org.approvaltests.Approvals; | ||
import org.junit.jupiter.api.io.TempDir; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class CRDGeneratorApprovalTest { | ||
|
||
@TempDir | ||
File tempDir; | ||
|
||
@ParameterizedTest(name = "{1}.{2} parallel={3}") | ||
@MethodSource("crdApprovalTests") | ||
void approvalTest( | ||
Class<? extends CustomResource<?, ?>>[] crClasses, String expectedCrd, String version, boolean parallel) | ||
throws IOException { | ||
Approvals.settings().allowMultipleVerifyCallsForThisMethod(); | ||
final Map<String, Map<String, CRDInfo>> result = new 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 String(Files.readAllBytes(new File(result.get(expectedCrd).get(version).getFilePath()).toPath())), | ||
Approvals.NAMES.withParameters(expectedCrd, version)); | ||
} | ||
|
||
static Stream<Arguments> crdApprovalTests() { | ||
final List<TestCase> 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)); | ||
} | ||
} | ||
return cases.stream().map(tc -> Arguments.of(tc.crClasses, tc.expectedCrd, tc.version, tc.parallel)); | ||
} | ||
|
||
private static final class TestCase { | ||
private Class<? extends CustomResource<?, ?>>[] crClasses; | ||
private String expectedCrd; | ||
private String version; | ||
private boolean parallel; | ||
|
||
public TestCase(String expectedCrd, String version, boolean parallel, Class<? extends CustomResource<?, ?>>... crClasses) { | ||
this.expectedCrd = expectedCrd; | ||
this.version = version; | ||
this.parallel = parallel; | ||
this.crClasses = crClasses; | ||
} | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/PackageSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.crd.generator.approvaltests; | ||
|
||
import org.approvaltests.core.ApprovalFailureReporter; | ||
import org.approvaltests.reporters.QuietReporter; | ||
|
||
/** | ||
* @see <a href= | ||
* "https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/docs/explanations/BestConfigurationPractices.md"> | ||
* ApprovalTests - Best Configuration Practices</a> | ||
*/ | ||
public class PackageSettings { | ||
/** | ||
* Disable Diff-Reporter | ||
*/ | ||
@SuppressWarnings("unused") | ||
public static ApprovalFailureReporter UseReporter = new QuietReporter(); | ||
public String ApprovalBaseDirectory = "../resources"; | ||
} |
26 changes: 26 additions & 0 deletions
26
...nerator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/Annotated.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.crd.generator.approvaltests.annotated; | ||
|
||
import io.fabric8.kubernetes.client.CustomResource; | ||
import io.fabric8.kubernetes.model.annotation.Group; | ||
import io.fabric8.kubernetes.model.annotation.Version; | ||
|
||
@Group("samples.fabric8.io") | ||
@Version("v1") | ||
public class Annotated extends CustomResource<AnnotatedSpec, Void> { | ||
|
||
} |
Oops, something went wrong.