Skip to content

Commit

Permalink
Fix fabric8io#2687: RawCustomResourceOperationsImpl ignores provided …
Browse files Browse the repository at this point in the history
…Config

Removed colliding variables from parent OperationSupport class and added
a call to super in constructor
  • Loading branch information
rohanKanojia committed Jan 13, 2021
1 parent c9bf95d commit 0c04abb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
### 5.1-SNAPSHOT

#### Bugs
* Fix #2687: RawCustomResourceOperationsImpl ignores config

#### Improvements

Expand Down
Expand Up @@ -60,16 +60,13 @@ public class RawCustomResourceOperationsImpl extends OperationSupport {

private static final String METADATA = "metadata";
private static final String RESOURCE_VERSION = "resourceVersion";
private OkHttpClient client;
private Config config;
private CustomResourceDefinitionContext customResourceDefinition;
private ObjectMapper objectMapper;
private final CustomResourceDefinitionContext customResourceDefinition;
private final ObjectMapper objectMapper;

private enum HttpCallMethod { GET, POST, PUT, DELETE };
private enum HttpCallMethod { GET, POST, PUT, DELETE }

public RawCustomResourceOperationsImpl(OkHttpClient client, Config config, CustomResourceDefinitionContext customResourceDefinition) {
this.client = client;
this.config = config;
super(client, config);
this.customResourceDefinition = customResourceDefinition;
this.objectMapper = Serialization.jsonMapper();
}
Expand Down
Expand Up @@ -16,6 +16,7 @@
package io.fabric8.kubernetes.client.dsl.internal;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.*;

Expand Down Expand Up @@ -45,6 +46,8 @@
import okhttp3.Response;
import okhttp3.ResponseBody;

import static org.assertj.core.api.Assertions.assertThat;

public class RawCustomResourceOperationsImplTest {
private OkHttpClient mockClient;
private Config config;
Expand Down Expand Up @@ -146,7 +149,7 @@ void testDeleteUrl() throws IOException {
}

@Test
public void testFetchWatchUrlWithNamespace() throws MalformedURLException {
void testFetchWatchUrlWithNamespace() throws MalformedURLException {
// Given
RawCustomResourceOperationsImpl rawCustomResourceOperations = new RawCustomResourceOperationsImpl(mockClient, config, customResourceDefinitionContext);

Expand All @@ -158,7 +161,7 @@ public void testFetchWatchUrlWithNamespace() throws MalformedURLException {
}

@Test
public void testFetchWatchUrlWithNamespaceAndName() throws MalformedURLException {
void testFetchWatchUrlWithNamespaceAndName() throws MalformedURLException {
// Given
RawCustomResourceOperationsImpl rawCustomResourceOperations = new RawCustomResourceOperationsImpl(mockClient, config, customResourceDefinitionContext);

Expand All @@ -170,7 +173,7 @@ public void testFetchWatchUrlWithNamespaceAndName() throws MalformedURLException
}

@Test
public void testFetchWatchUrlWithNamespaceAndNameAndResourceVersion() throws MalformedURLException {
void testFetchWatchUrlWithNamespaceAndNameAndResourceVersion() throws MalformedURLException {
// Given
RawCustomResourceOperationsImpl rawCustomResourceOperations = new RawCustomResourceOperationsImpl(mockClient, config, customResourceDefinitionContext);

Expand All @@ -182,7 +185,7 @@ public void testFetchWatchUrlWithNamespaceAndNameAndResourceVersion() throws Mal
}

@Test
public void testFetchWatchUrlWithoutAnything() throws MalformedURLException {
void testFetchWatchUrlWithoutAnything() throws MalformedURLException {
// Given
RawCustomResourceOperationsImpl rawCustomResourceOperations = new RawCustomResourceOperationsImpl(mockClient, config, customResourceDefinitionContext);

Expand All @@ -194,7 +197,7 @@ public void testFetchWatchUrlWithoutAnything() throws MalformedURLException {
}

@Test
public void testFetchWatchUrlWithLabels() throws MalformedURLException {
void testFetchWatchUrlWithLabels() throws MalformedURLException {
// Given
RawCustomResourceOperationsImpl rawCustomResourceOperations = new RawCustomResourceOperationsImpl(mockClient, config, customResourceDefinitionContext);

Expand All @@ -210,7 +213,7 @@ public void testFetchWatchUrlWithLabels() throws MalformedURLException {
}

@Test
public void testFetchWatchUrlWithLabelsWithNamespace() throws MalformedURLException {
void testFetchWatchUrlWithLabelsWithNamespace() throws MalformedURLException {
// Given
RawCustomResourceOperationsImpl rawCustomResourceOperations = new RawCustomResourceOperationsImpl(mockClient, config, customResourceDefinitionContext);

Expand All @@ -224,4 +227,30 @@ public void testFetchWatchUrlWithLabelsWithNamespace() throws MalformedURLExcept
// Then
assertEquals("https://localhost:8443/apis/test.fabric8.io/v1alpha1/namespaces/test/hellos?labelSelector=" + Utils.toUrlEncoded("foo=bar") + "," + Utils.toUrlEncoded("foo1=bar1") + "&watch=true", url.url().toString());
}

@Test
void testGetConfigShouldNotReturnNull() {
// Given
Config config = new ConfigBuilder()
.withRequestTimeout(5)
.withWebsocketTimeout(10L)
.withWebsocketPingInterval(10L)
.withConnectionTimeout(10)
.withWatchReconnectLimit(1)
.withWatchReconnectInterval(10)
.build();
RawCustomResourceOperationsImpl rawOp = new RawCustomResourceOperationsImpl(mockClient, config, customResourceDefinitionContext);

// When
Config configFromRawOp = rawOp.getConfig();

// Then
assertThat(configFromRawOp).isNotNull();
assertThat(configFromRawOp.getRequestTimeout()).isEqualTo(5);
assertThat(configFromRawOp.getWebsocketTimeout()).isEqualTo(10L);
assertThat(configFromRawOp.getWebsocketPingInterval()).isEqualTo(10L);
assertThat(configFromRawOp.getConnectionTimeout()).isEqualTo(10L);
assertThat(configFromRawOp.getWatchReconnectInterval()).isEqualTo(10);
assertThat(configFromRawOp.getWatchReconnectLimit()).isEqualTo(1);
}
}

0 comments on commit 0c04abb

Please sign in to comment.