Skip to content

Commit

Permalink
Fix fabric8io#2354: Fix NullPointerException in ResourceCompare when …
Browse files Browse the repository at this point in the history
…no resource is returned from fromServer.get()

Somehow resource was being returned as `null` from `fromServer.get()` call due to no
namespace being provided. Added a case of Null items in `ResourceCompare#equals`
  • Loading branch information
rohanKanojia committed Aug 3, 2020
1 parent 50c1e8d commit bb6307d
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@
#### Bugs
* Fix #2373: Unable to create a Template on OCP3
* Fix #2316: Cannot load resource from stream without apiVersion
* Fix #2354: Fix NullPointerException in ResourceCompare when no resource is returned from fromServer.get()

#### Improvements
* Fix #2331: Fixed documentation for namespaced informer for all custom types implementing `Namespaced` interface
Expand Down
@@ -0,0 +1,79 @@
/**
* 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.knative.test;

import io.fabric8.knative.client.KnativeClient;
import io.fabric8.knative.mock.KnativeServer;
import io.fabric8.knative.serving.v1.Route;
import io.fabric8.knative.serving.v1.RouteBuilder;
import org.junit.Rule;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;

import java.net.HttpURLConnection;

import static org.junit.jupiter.api.Assertions.assertNotNull;

@EnableRuleMigrationSupport
class RouteTest {
@Rule
public KnativeServer server = new KnativeServer();

@Test
void testCreateOrReplace() {
// Given
Route route = new RouteBuilder()
.withNewMetadata()
.withName("helloworld-nodejs-red-blue1")
.withNamespace("test")
.endMetadata()
.withNewSpec()
.addNewTraffic()
.withConfigurationName("greeter")
.withPercent(100L)
.endTraffic()
.endSpec()
.build();
server.expect().post().withPath("/apis/serving.knative.dev/v1/namespaces/test/routes")
.andReturn(HttpURLConnection.HTTP_CONFLICT, route)
.once();
server.expect().get().withPath("/apis/serving.knative.dev/v1/namespaces/test/routes/helloworld-nodejs-red-blue1")
.andReturn(HttpURLConnection.HTTP_OK, route)
.times(2);
server.expect().put().withPath("/apis/serving.knative.dev/v1/namespaces/test/routes/helloworld-nodejs-red-blue1")
.andReturn(HttpURLConnection.HTTP_OK, route)
.once();
KnativeClient kn = server.getKnativeClient();

// When
route = kn.routes().createOrReplaceWithNew()
.withNewMetadata()
.withName("helloworld-nodejs-red-blue1")
.addToAnnotations("foo", "bar")
.withNamespace("test")
.endMetadata()
.withNewSpec()
.addNewTraffic()
.withConfigurationName("greeter")
.withPercent(100L)
.endTraffic()
.endSpec()
.done();

// Then
assertNotNull(route);
}
}
Expand Up @@ -29,7 +29,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

@EnableRuleMigrationSupport
public class RouteTest {
public class RouteCrudTest {
@Rule
public KnativeServer server = new KnativeServer(true, true);

Expand Down
Expand Up @@ -77,6 +77,14 @@ public static boolean compareKubernetesList(Map<String, Object> leftJson, Map<St
}

public static boolean compareKubernetesResource(Map<String, Object> leftJson, Map<String, Object> rightJson) {
if (leftJson == null && rightJson == null) {
return true;
} else if (leftJson == null) {
return false;
} else if (rightJson == null) {
return false;
}

return isEqualMetadata(leftJson, rightJson) &&
isEqualSpec(leftJson, rightJson);
}
Expand Down

0 comments on commit bb6307d

Please sign in to comment.