-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Multiple Custom Resources with same (different apiGroup) name ca…
…n be added Signed-off-by: Marc Nuri <[email protected]>
- Loading branch information
Showing
21 changed files
with
255 additions
and
101 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
78 changes: 78 additions & 0 deletions
78
...n/src/test/java/org/eclipse/jkube/kit/common/GenericCustomResourceEqualsHashCodeTest.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,78 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.common; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class GenericCustomResourceEqualsHashCodeTest { | ||
|
||
@Test | ||
public void equals_withNull_shouldBeFalse() { | ||
// Given | ||
final GenericCustomResource gcr = new GenericCustomResource(); | ||
// When - Then | ||
final boolean result = gcr.equals(null); | ||
// Then | ||
assertThat(result).isFalse(); | ||
} | ||
|
||
@Test | ||
public void equals_withSameFields_shouldBeTrue() { | ||
// Given | ||
final GenericCustomResource one = initGenericCustomResource(); | ||
final GenericCustomResource other = initGenericCustomResource(); | ||
// When - Then | ||
assertThat(one).isEqualTo(other).isNotSameAs(other); | ||
} | ||
|
||
@Test | ||
public void equals_withDifferentMapFields_shouldBeFalse() { | ||
// Given | ||
final GenericCustomResource one = initGenericCustomResource(); | ||
final GenericCustomResource other = initGenericCustomResource(); | ||
other.setAdditionalProperty("extra", "other"); | ||
// When - Then | ||
assertThat(one).isNotEqualTo(other).isNotSameAs(other); | ||
} | ||
|
||
@Test | ||
public void hashSet_withSomeDuplicates_duplicatesAreRemoved() { | ||
// Given | ||
final Set<GenericCustomResource> uniqueValues = new HashSet<>(); | ||
uniqueValues.add(initGenericCustomResource()); | ||
uniqueValues.add(initGenericCustomResource()); | ||
final GenericCustomResource different = initGenericCustomResource(); | ||
different.setKind("Other"); | ||
uniqueValues.add(different); | ||
// When - Then | ||
assertThat(uniqueValues).hasSize(2).extracting("kind").containsExactlyInAnyOrder("Kind", "Other"); | ||
} | ||
|
||
private GenericCustomResource initGenericCustomResource() { | ||
final GenericCustomResource gcr = new GenericCustomResource(); | ||
gcr.setApiVersion("v1"); | ||
gcr.setKind("Kind"); | ||
gcr.setMetadata(new ObjectMetaBuilder().withName("name").build()); | ||
gcr.setAdditionalProperties(new HashMap<>(Collections.singletonMap("key", "value"))); | ||
return gcr; | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
...t/resources/util/kubernetes-helper/list-with-duplicates-and-same-name-custom-resource.yml
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,43 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: List | ||
items: | ||
- apiVersion: custom.resource.example.com/v1 | ||
kind: Example | ||
metadata: | ||
labels: | ||
app: custom-resources | ||
name: custom-resource | ||
namespace: code | ||
spec: | ||
field: i-have-a-duplicate | ||
- apiVersion: custom.resource.example.com/v1 | ||
kind: Example | ||
metadata: | ||
labels: | ||
app: custom-resources | ||
name: custom-resource | ||
namespace: code | ||
spec: | ||
field: i-have-a-duplicate | ||
- apiVersion: custom-other.resource.example.com/v1 | ||
kind: Example | ||
metadata: | ||
labels: | ||
app: custom-resources | ||
name: custom-resource | ||
namespace: code | ||
spec: | ||
field: not-the-same | ||
- apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
labels: | ||
provider: jkube | ||
name: should-be-first | ||
- apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
labels: | ||
provider: jkube | ||
name: should-be-first |
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
Oops, something went wrong.