From 99cf283b392b7d90653399dbeab73f7a822ecfe1 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Wed, 25 Jan 2023 14:53:52 +0100 Subject: [PATCH 1/2] Cloud.name should be part of equals/hashCode --- .../csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java index 7a7ecaafe1..3dbbae26e7 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java @@ -661,7 +661,8 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; KubernetesCloud that = (KubernetesCloud) o; - return skipTlsVerify == that.skipTlsVerify && + return Objects.equals(name, that.name) && + skipTlsVerify == that.skipTlsVerify && addMasterProxyEnvVars == that.addMasterProxyEnvVars && capOnlyOnAlivePods == that.capOnlyOnAlivePods && Objects.equals(containerCap, that.containerCap) && @@ -687,7 +688,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(defaultsProviderTemplate, templates, serverUrl, serverCertificate, skipTlsVerify, + return Objects.hash(name, defaultsProviderTemplate, templates, serverUrl, serverCertificate, skipTlsVerify, addMasterProxyEnvVars, capOnlyOnAlivePods, namespace, jnlpregistry, jenkinsUrl, jenkinsTunnel, credentialsId, containerCap, retentionTimeout, connectTimeout, readTimeout, podLabels, usageRestricted, maxRequestsPerHost, podRetention, useJenkinsProxy); From d8f39ffdea9b7fcde545c5e1a6b75f15540a9d19 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Wed, 25 Jan 2023 17:05:36 +0100 Subject: [PATCH 2/2] Fix test --- .../jenkins/plugins/kubernetes/KubernetesCloudTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloudTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloudTest.java index 80be894630..1aa664ac51 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloudTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloudTest.java @@ -2,6 +2,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.ArrayList; @@ -24,6 +25,7 @@ import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomUtils; +import org.apache.commons.lang3.builder.EqualsBuilder; import org.csanchez.jenkins.plugins.kubernetes.pod.retention.Always; import org.csanchez.jenkins.plugins.kubernetes.pod.retention.PodRetention; import org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume; @@ -244,7 +246,7 @@ public void copyConstructor() throws Exception { KubernetesCloud copy = new KubernetesCloud("copy", cloud); assertEquals("copy", copy.name); - assertEquals("Expected cloud from copy constructor to be equal to the source except for name", cloud, copy); + assertTrue("Expected cloud from copy constructor to be equal to the source except for name", EqualsBuilder.reflectionEquals(cloud, copy, true, KubernetesCloud.class, "name")); } @Test