Skip to content

Commit

Permalink
Make a standalone test for cyclic lists, revert changes to original test
Browse files Browse the repository at this point in the history
  • Loading branch information
xRodney committed Oct 20, 2022
1 parent dd22c74 commit 03730a5
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* 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.example.cyclic;

import io.fabric8.kubernetes.api.model.Namespaced;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Version;

@Group("sample.fabric8.io")
@Version("v1alpha1")
public class CyclicList extends CustomResource<CyclicListSpec, CyclicStatus> implements Namespaced {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* 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.example.cyclic;

import java.util.List;

public class CyclicListSpec {
private List<RefList> ref;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
import java.util.List;

public class CyclicSpec {
private List<Ref> ref;
private Ref ref;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@

public class Ref {

private List<Ref> ref;
private Ref ref;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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.example.cyclic;

import java.util.List;

public class RefList {

private List<RefList> ref;

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.fabric8.crd.example.basic.BasicSpec;
import io.fabric8.crd.example.basic.BasicStatus;
import io.fabric8.crd.example.cyclic.Cyclic;
import io.fabric8.crd.example.cyclic.CyclicList;
import io.fabric8.crd.example.inherited.*;
import io.fabric8.crd.example.joke.Joke;
import io.fabric8.crd.example.joke.JokeRequest;
Expand Down Expand Up @@ -214,6 +215,19 @@ void shouldProperlyGenerateMultipleVersionsOfCRDs() {
);
}

@Test void generatingACycleInListShouldFail() {
final CRDGenerator generator = new CRDGenerator()
.customResourceClasses(CyclicList.class)
.forCRDVersions("v1", "v1beta1")
.withOutput(output);

assertThrows(
IllegalArgumentException.class,
() -> generator.detailedGenerate(),
"An IllegalArgument Exception hasn't been thrown when generating a CRD with cyclic references"
);
}

@Test void notGeneratingACycleShouldSucceed() {
final CRDGenerator generator = new CRDGenerator()
.customResourceClasses(NoCyclic.class)
Expand Down

0 comments on commit 03730a5

Please sign in to comment.