-
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(api): add DSL entrypoint
getAPIVersions()
in Client interface
Add DSL entrypoint `getAPIVersions()` in Client interface Signed-off-by: Rohan Kumar <[email protected]> (cherry picked from commit 093d8cd) Signed-off-by: Marc Nuri <[email protected]>
- Loading branch information
1 parent
966b676
commit dcd3e04
Showing
6 changed files
with
154 additions
and
0 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
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
80 changes: 80 additions & 0 deletions
80
kubernetes-client/src/test/java/io/fabric8/kubernetes/client/impl/APIVersionsTest.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,80 @@ | ||
/* | ||
* 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.kubernetes.client.impl; | ||
|
||
import io.fabric8.kubernetes.client.Config; | ||
import io.fabric8.kubernetes.client.ConfigBuilder; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.fabric8.kubernetes.client.http.HttpClient; | ||
import io.fabric8.kubernetes.client.http.HttpRequest; | ||
import io.fabric8.kubernetes.client.http.TestHttpResponse; | ||
import io.fabric8.kubernetes.client.utils.KubernetesSerialization; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
class APIVersionsTest { | ||
private HttpClient mockClient; | ||
private KubernetesClient kubernetesClient; | ||
private List<HttpRequest.Builder> builders; | ||
|
||
@BeforeEach | ||
public void setUp() throws IOException { | ||
builders = new ArrayList<>(); | ||
this.mockClient = Mockito.mock(HttpClient.class, Mockito.RETURNS_DEEP_STUBS); | ||
Config config = new ConfigBuilder().withMasterUrl("https://localhost:8443/").build(); | ||
when(mockClient.sendAsync(any(), Mockito.eq(byte[].class))) | ||
.thenReturn(CompletableFuture.completedFuture(TestHttpResponse.from(200, | ||
"{\"kind\":\"Pod\", \"apiVersion\":\"v1\"}"))); | ||
kubernetesClient = new KubernetesClientImpl(mockClient, config, () -> Runnable::run, | ||
new KubernetesSerialization()); | ||
Mockito.when(mockClient.newHttpRequestBuilder()).thenAnswer(answer -> { | ||
HttpRequest.Builder result = Mockito.mock(HttpRequest.Builder.class, Mockito.RETURNS_SELF); | ||
builders.add(result); | ||
return result; | ||
}); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
kubernetesClient.close(); | ||
kubernetesClient = null; | ||
} | ||
|
||
@Test | ||
void getApiVersions() { | ||
// When | ||
kubernetesClient.getAPIVersions(); | ||
// Then | ||
verify(mockClient).sendAsync(any(), any()); | ||
ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class); | ||
verify(builders.get(0)).uri(stringCaptor.capture()); | ||
assertThat(stringCaptor.getValue()) | ||
.isEqualTo("https://localhost:8443/api"); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
kubernetes-itests/src/test/java/io/fabric8/kubernetes/APIVersionsIT.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,46 @@ | ||
/* | ||
* 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.kubernetes; | ||
|
||
import io.fabric8.kubernetes.api.model.APIVersions; | ||
import io.fabric8.kubernetes.api.model.ServerAddressByClientCIDR; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import org.assertj.core.api.InstanceOfAssertFactories; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Collections; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
class APIVersionsIT { | ||
KubernetesClient client; | ||
|
||
@Test | ||
void testApiVersions() { | ||
// Given + When | ||
APIVersions apiVersions = client.getAPIVersions(); | ||
// Then | ||
assertThat(apiVersions) | ||
.isNotNull() | ||
.hasFieldOrPropertyWithValue("versions", Collections.singletonList("v1")) | ||
.extracting(APIVersions::getServerAddressByClientCIDRs) | ||
.asInstanceOf(InstanceOfAssertFactories.list(ServerAddressByClientCIDR.class)) | ||
.singleElement() | ||
.hasFieldOrPropertyWithValue("clientCIDR", "0.0.0.0/0") | ||
.hasFieldOrPropertyWithValue("serverAddress", | ||
String.format("%s:%d", client.getMasterUrl().getHost(), client.getMasterUrl().getPort())); | ||
} | ||
} |