-
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.
test (kubernetes-server-mock) : Add disabled tests for handing Kubern…
…etes list types KubernetesResponseComposer should infer list type from list items instead of returning a hardcoded `List` kind value. Added tests to provide desired expectations. Signed-off-by: Rohan Kumar <[email protected]>
- Loading branch information
1 parent
eec18ee
commit cffde45
Showing
2 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...rc/test/java/io/fabric8/kubernetes/client/server/mock/KubernetesResponseComposerTest.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,61 @@ | ||
/* | ||
* 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.server.mock; | ||
|
||
import io.fabric8.kubernetes.api.model.KubernetesResourceList; | ||
import io.fabric8.kubernetes.client.utils.Serialization; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.stream.Stream; | ||
|
||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
|
||
class KubernetesResponseComposerTest { | ||
private KubernetesResponseComposer kubernetesResponseComposer; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
kubernetesResponseComposer = new KubernetesResponseComposer(); | ||
} | ||
|
||
static Stream<Arguments> composeInput() { | ||
return Stream.of( | ||
// https://github.com/fabric8io/kubernetes-client/issues/6220 | ||
// arguments("Secret", "SecretList"), | ||
arguments("", "List")); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("composeInput") | ||
void compose_whenKindProvidedInListItem_shouldInferListKindCorrectly(String providedKind, String parsedListKind) { | ||
// Given | ||
Collection<String> collection = new ArrayList<>(); | ||
collection.add(String.format("{\"kind\": \"%s\", \"apiVersion\": \"v1\", \"metadata\": {}}", providedKind)); | ||
|
||
// When | ||
String listString = kubernetesResponseComposer.compose(collection, "1"); | ||
|
||
// Then | ||
assertThat(Serialization.unmarshal(listString, KubernetesResourceList.class)) | ||
.hasFieldOrPropertyWithValue("kind", parsedListKind); | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
...t/java/io/fabric8/kubernetes/client/server/mock/crud/KubernetesCrudDispatcherGetTest.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,142 @@ | ||
/* | ||
* 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.server.mock.crud; | ||
|
||
import io.fabric8.kubernetes.api.model.ConfigMap; | ||
import io.fabric8.kubernetes.api.model.ConfigMapBuilder; | ||
import io.fabric8.kubernetes.api.model.ConfigMapList; | ||
import io.fabric8.kubernetes.client.dsl.NonDeletingOperation; | ||
import org.assertj.core.api.InstanceOfAssertFactories; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
class KubernetesCrudDispatcherGetTest extends KubernetesCrudDispatcherTestBase { | ||
|
||
@Nested | ||
class WithNoItems { | ||
|
||
@BeforeEach | ||
void clearItems() { | ||
client.resources(ConfigMap.class).delete(); | ||
} | ||
|
||
@Test | ||
void singleItem() { | ||
assertThat(client.configMaps().withName("config-map-1").get()).isNull(); | ||
} | ||
|
||
@Test | ||
@Disabled("#6220: Need to figure out a way to extract the singular from the plural form in URL") | ||
void multipleItems_shouldReturnListObjectWithCorrectKind() { | ||
// When | ||
final ConfigMapList result = client.configMaps().list(); | ||
// Then | ||
assertThat(result) | ||
.hasFieldOrPropertyWithValue("kind", "ConfigMapList") | ||
.extracting(ConfigMapList::getItems) | ||
.asInstanceOf(InstanceOfAssertFactories.list(ConfigMap.class)) | ||
.isEmpty(); | ||
} | ||
|
||
} | ||
|
||
@Nested | ||
class WithValidItems { | ||
|
||
@BeforeEach | ||
void addConsistentItems() { | ||
for (int it = 0; it < 5; it++) { | ||
client.resource(new ConfigMapBuilder().withNewMetadata().withName("config-map-" + it).endMetadata().build()) | ||
.createOr(NonDeletingOperation::update); | ||
} | ||
} | ||
|
||
@Test | ||
void singleItem() { | ||
assertThat(client.configMaps().withName("config-map-1").get()) | ||
.isInstanceOf(ConfigMap.class); | ||
} | ||
|
||
@Test | ||
@Disabled("#6220: Need to figure out a way to extract the singular from the plural form in URL") | ||
void multipleItems_shouldReturnListObjectWithCorrectKind() { | ||
// When | ||
final ConfigMapList result = client.configMaps().list(); | ||
// Then | ||
assertThat(result) | ||
.hasFieldOrPropertyWithValue("kind", "ConfigMapList") | ||
.extracting(ConfigMapList::getItems) | ||
.asInstanceOf(InstanceOfAssertFactories.list(ConfigMap.class)) | ||
.extracting("kind") | ||
.containsOnly("ConfigMap"); | ||
} | ||
} | ||
|
||
@Nested | ||
class WithInvalidItems { | ||
@BeforeEach | ||
void addInvalidItems() throws Exception { | ||
client.configMaps().resource(new ConfigMapBuilder() | ||
.withKind("NotConfigMap") | ||
.withNewMetadata().withName("NotConfigMap").endMetadata() | ||
.build()) | ||
.create(); | ||
for (int it = 0; it < 5; it++) { | ||
client.resource(new ConfigMapBuilder().withNewMetadata().withName("config-map-" + it).endMetadata().build()) | ||
.createOr(NonDeletingOperation::update); | ||
} | ||
client.getHttpClient().sendAsync(client.getHttpClient().newHttpRequestBuilder() | ||
.uri(server.url("/api/v1/namespaces/test/configmaps")) | ||
.post("application/json", "{\"kind\":\"NotConfigMap\"}") | ||
.build(), String.class) | ||
.get(10, TimeUnit.SECONDS); | ||
} | ||
|
||
@BeforeEach | ||
void addConsistentItems() { | ||
for (int it = 0; it < 10; it++) { | ||
client.resource(new ConfigMapBuilder().withNewMetadata().withName("config-map-" + it).endMetadata().build()) | ||
.createOr(NonDeletingOperation::update); | ||
} | ||
} | ||
|
||
@Test | ||
void singleItem() { | ||
assertThat(client.configMaps().withName("config-map-1").get()) | ||
.isInstanceOf(ConfigMap.class); | ||
} | ||
|
||
@Test | ||
@Disabled("#6220: Need to figure out a way to extract the singular from the plural form in URL") | ||
void multipleItems_shouldReturnListObjectWithCorrectKind() { | ||
// When | ||
final ConfigMapList result = client.configMaps().list(); | ||
// Then | ||
assertThat(result) | ||
.hasFieldOrPropertyWithValue("kind", "ConfigMapList") | ||
.extracting(ConfigMapList::getItems) | ||
.asInstanceOf(InstanceOfAssertFactories.list(ConfigMap.class)) | ||
.extracting("kind") | ||
.containsOnly("ConfigMap"); | ||
} | ||
} | ||
} |