-
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.
feat (openshift-client-api) : Add DSL for new OpenShift 4.13.12 resou…
…rces to OpenShiftClient (#5286) Add DSL support for the following endpoints: - openShiftClient.metal3RemediationTemplates() - openShiftClient.metal3Remediations() - openShiftClient.projectHelmChartRepositories() - openShiftClient.operatorHub().olmConfigs() - openShiftClient.config().imageTagMirrorSets() - openShiftClient.config().imageDigestMirrorSets() - openShiftClient.machine().controlPlaneMachineSets() Signed-off-by: Rohan Kumar <[email protected]>
- Loading branch information
1 parent
eb9ec36
commit 792870a
Showing
16 changed files
with
934 additions
and
0 deletions.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
...sts/src/test/java/io/fabric8/openshift/client/server/mock/ControlPlaneMachineSetTest.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,137 @@ | ||
/** | ||
* 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.openshift.client.server.mock; | ||
|
||
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; | ||
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; | ||
import io.fabric8.openshift.api.model.machine.v1.ControlPlaneMachineSet; | ||
import io.fabric8.openshift.api.model.machine.v1.ControlPlaneMachineSetBuilder; | ||
import io.fabric8.openshift.api.model.machine.v1.ControlPlaneMachineSetList; | ||
import io.fabric8.openshift.api.model.machine.v1.ControlPlaneMachineSetListBuilder; | ||
import io.fabric8.openshift.client.OpenShiftClient; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.net.HttpURLConnection; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@EnableKubernetesMockClient | ||
class ControlPlaneMachineSetTest { | ||
KubernetesMockServer server; | ||
OpenShiftClient client; | ||
|
||
@Test | ||
void create() { | ||
// Given | ||
ControlPlaneMachineSet controlPlaneMachineSet = getControlPlaneMachineSet(); | ||
server.expect().post() | ||
.withPath("/apis/machine.openshift.io/v1/namespaces/ns1/controlplanemachinesets") | ||
.andReturn(HttpURLConnection.HTTP_OK, controlPlaneMachineSet) | ||
.once(); | ||
|
||
// When | ||
controlPlaneMachineSet = client.machine().controlPlaneMachineSets().inNamespace("ns1").resource(controlPlaneMachineSet) | ||
.create(); | ||
|
||
// Then | ||
assertNotNull(controlPlaneMachineSet); | ||
assertEquals("cluster", controlPlaneMachineSet.getMetadata().getName()); | ||
} | ||
|
||
@Test | ||
void get() { | ||
// Given | ||
server.expect().get() | ||
.withPath("/apis/machine.openshift.io/v1/namespaces/ns1/controlplanemachinesets/cluster") | ||
.andReturn(HttpURLConnection.HTTP_OK, getControlPlaneMachineSet()) | ||
.once(); | ||
|
||
// When | ||
ControlPlaneMachineSet controlPlaneMachineSet = client.machine().controlPlaneMachineSets().inNamespace("ns1") | ||
.withName("cluster").get(); | ||
|
||
// Then | ||
assertNotNull(controlPlaneMachineSet); | ||
assertEquals("cluster", controlPlaneMachineSet.getMetadata().getName()); | ||
} | ||
|
||
@Test | ||
void list() { | ||
// Given | ||
server.expect().get() | ||
.withPath("/apis/machine.openshift.io/v1/namespaces/ns1/controlplanemachinesets") | ||
.andReturn(HttpURLConnection.HTTP_OK, | ||
new ControlPlaneMachineSetListBuilder().withItems(getControlPlaneMachineSet()).build()) | ||
.once(); | ||
|
||
// When | ||
ControlPlaneMachineSetList controlPlaneMachineSetList = client.machine().controlPlaneMachineSets().inNamespace("ns1") | ||
.list(); | ||
|
||
// Then | ||
assertNotNull(controlPlaneMachineSetList); | ||
assertNotNull(controlPlaneMachineSetList.getItems()); | ||
assertEquals(1, controlPlaneMachineSetList.getItems().size()); | ||
} | ||
|
||
@Test | ||
void delete() { | ||
// Given | ||
server.expect().delete() | ||
.withPath("/apis/machine.openshift.io/v1/namespaces/ns1/controlplanemachinesets/cluster") | ||
.andReturn(HttpURLConnection.HTTP_OK, getControlPlaneMachineSet()) | ||
.once(); | ||
|
||
// When | ||
boolean deleted = client.machine().controlPlaneMachineSets().inNamespace("ns1").withName("cluster").delete().size() == 1; | ||
|
||
// Then | ||
assertTrue(deleted); | ||
} | ||
|
||
private ControlPlaneMachineSet getControlPlaneMachineSet() { | ||
return new ControlPlaneMachineSetBuilder() | ||
.withNewMetadata() | ||
.withName("cluster") | ||
.endMetadata() | ||
.withNewSpec() | ||
.withReplicas(3) | ||
.withState("Active") | ||
.withNewStrategy().withType("RollingUpdate").endStrategy() | ||
.withNewSelector() | ||
.addToMatchLabels("machine.openshift.io/cluster-api-machine-role", "master") | ||
.addToMatchLabels("machine.openshift.io/cluster-api-machine-type", "master") | ||
.endSelector() | ||
.withNewTemplate() | ||
.withMachineType("machines_v1beta1_machine_openshift_io") | ||
.withNewMachinesV1beta1MachineOpenshiftIo() | ||
.withNewMetadata() | ||
.addToLabels("machine.openshift.io/cluster-api-machine-role", "master") | ||
.addToLabels("machine.openshift.io/cluster-api-machine-type", "master") | ||
.addToLabels("machine.openshift.io/cluster-api-cluster", "cluster") | ||
.endMetadata() | ||
.withNewSpec() | ||
.withNewProviderSpec() | ||
.endProviderSpec() | ||
.endSpec() | ||
.endMachinesV1beta1MachineOpenshiftIo() | ||
.endTemplate() | ||
.endSpec() | ||
.build(); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...tests/src/test/java/io/fabric8/openshift/client/server/mock/ImageDigestMirrorSetTest.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,99 @@ | ||
/** | ||
* 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.openshift.client.server.mock; | ||
|
||
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; | ||
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; | ||
import io.fabric8.openshift.api.model.config.v1.ImageDigestMirrorSet; | ||
import io.fabric8.openshift.api.model.config.v1.ImageDigestMirrorSetBuilder; | ||
import io.fabric8.openshift.api.model.config.v1.ImageDigestMirrorSetList; | ||
import io.fabric8.openshift.api.model.config.v1.ImageDigestMirrorSetListBuilder; | ||
import io.fabric8.openshift.client.OpenShiftClient; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.net.HttpURLConnection; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@EnableKubernetesMockClient | ||
class ImageDigestMirrorSetTest { | ||
private OpenShiftClient client; | ||
private KubernetesMockServer server; | ||
|
||
@Test | ||
void get() { | ||
// Given | ||
server.expect().get().withPath("/apis/config.openshift.io/v1/imagedigestmirrorsets/test-get") | ||
.andReturn(HttpURLConnection.HTTP_OK, createNewImageDigestMirrorSet("test-get")) | ||
.once(); | ||
|
||
// When | ||
ImageDigestMirrorSet imageDigestMirrorSet = client.config().imageDigestMirrorSets().withName("test-get").get(); | ||
|
||
// Then | ||
assertThat(imageDigestMirrorSet) | ||
.isNotNull() | ||
.hasFieldOrPropertyWithValue("metadata.name", "test-get"); | ||
} | ||
|
||
@Test | ||
void list() { | ||
// Given | ||
server.expect().get().withPath("/apis/config.openshift.io/v1/imagedigestmirrorsets") | ||
.andReturn(HttpURLConnection.HTTP_OK, new ImageDigestMirrorSetListBuilder() | ||
.addToItems(createNewImageDigestMirrorSet("test-list")) | ||
.build()) | ||
.once(); | ||
|
||
// When | ||
ImageDigestMirrorSetList imageDigestMirrorSetList = client.config().imageDigestMirrorSets().list(); | ||
|
||
// Then | ||
assertThat(imageDigestMirrorSetList).isNotNull(); | ||
assertThat(imageDigestMirrorSetList.getItems()).hasSize(1); | ||
assertThat(imageDigestMirrorSetList.getItems().get(0)) | ||
.hasFieldOrPropertyWithValue("metadata.name", "test-list"); | ||
} | ||
|
||
@Test | ||
void delete() { | ||
// Given | ||
server.expect().delete().withPath("/apis/config.openshift.io/v1/imagedigestmirrorsets/cluster") | ||
.andReturn(HttpURLConnection.HTTP_OK, createNewImageDigestMirrorSet("cluster")) | ||
.once(); | ||
|
||
// When | ||
boolean isDeleted = client.config().imageDigestMirrorSets().withName("cluster").delete().size() == 1; | ||
|
||
// Then | ||
assertThat(isDeleted).isTrue(); | ||
} | ||
|
||
private ImageDigestMirrorSet createNewImageDigestMirrorSet(String name) { | ||
return new ImageDigestMirrorSetBuilder() | ||
.withNewMetadata() | ||
.withName(name) | ||
.endMetadata() | ||
.withNewSpec() | ||
.addNewImageDigestMirror() | ||
.withMirrors("example.com/example/ubi-minimal") | ||
.withSource("registry.access.redhat.com/ubi9/ubi-minimal") | ||
.withMirrorSourcePolicy("AllowContactingSource") | ||
.endImageDigestMirror() | ||
.endSpec() | ||
.build(); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...es-tests/src/test/java/io/fabric8/openshift/client/server/mock/ImageTagMirrorSetTest.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,99 @@ | ||
/** | ||
* 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.openshift.client.server.mock; | ||
|
||
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; | ||
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; | ||
import io.fabric8.openshift.api.model.config.v1.ImageTagMirrorSet; | ||
import io.fabric8.openshift.api.model.config.v1.ImageTagMirrorSetBuilder; | ||
import io.fabric8.openshift.api.model.config.v1.ImageTagMirrorSetList; | ||
import io.fabric8.openshift.api.model.config.v1.ImageTagMirrorSetListBuilder; | ||
import io.fabric8.openshift.client.OpenShiftClient; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.net.HttpURLConnection; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@EnableKubernetesMockClient | ||
class ImageTagMirrorSetTest { | ||
private OpenShiftClient client; | ||
private KubernetesMockServer server; | ||
|
||
@Test | ||
void get() { | ||
// Given | ||
server.expect().get().withPath("/apis/config.openshift.io/v1/imagetagmirrorsets/test-get") | ||
.andReturn(HttpURLConnection.HTTP_OK, createNewImageTagMirrorSet("test-get")) | ||
.once(); | ||
|
||
// When | ||
ImageTagMirrorSet imageTagMirrorSet = client.config().imageTagMirrorSets().withName("test-get").get(); | ||
|
||
// Then | ||
assertThat(imageTagMirrorSet) | ||
.isNotNull() | ||
.hasFieldOrPropertyWithValue("metadata.name", "test-get"); | ||
} | ||
|
||
@Test | ||
void list() { | ||
// Given | ||
server.expect().get().withPath("/apis/config.openshift.io/v1/imagetagmirrorsets") | ||
.andReturn(HttpURLConnection.HTTP_OK, new ImageTagMirrorSetListBuilder() | ||
.addToItems(createNewImageTagMirrorSet("test-list")) | ||
.build()) | ||
.once(); | ||
|
||
// When | ||
ImageTagMirrorSetList imageTagMirrorSetList = client.config().imageTagMirrorSets().list(); | ||
|
||
// Then | ||
assertThat(imageTagMirrorSetList).isNotNull(); | ||
assertThat(imageTagMirrorSetList.getItems()).hasSize(1); | ||
assertThat(imageTagMirrorSetList.getItems().get(0)) | ||
.hasFieldOrPropertyWithValue("metadata.name", "test-list"); | ||
} | ||
|
||
@Test | ||
void delete() { | ||
// Given | ||
server.expect().delete().withPath("/apis/config.openshift.io/v1/imagetagmirrorsets/cluster") | ||
.andReturn(HttpURLConnection.HTTP_OK, createNewImageTagMirrorSet("cluster")) | ||
.once(); | ||
|
||
// When | ||
boolean isDeleted = client.config().imageTagMirrorSets().withName("cluster").delete().size() == 1; | ||
|
||
// Then | ||
assertThat(isDeleted).isTrue(); | ||
} | ||
|
||
private ImageTagMirrorSet createNewImageTagMirrorSet(String name) { | ||
return new ImageTagMirrorSetBuilder() | ||
.withNewMetadata() | ||
.withName(name) | ||
.endMetadata() | ||
.withNewSpec() | ||
.addNewImageTagMirror() | ||
.withMirrors("example.com/example/ubi-minimal") | ||
.withSource("registry.access.redhat.com/ubi9/ubi-minimal") | ||
.withMirrorSourcePolicy("AllowContactingSource") | ||
.endImageTagMirror() | ||
.endSpec() | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.