Skip to content

Commit

Permalink
PodTemplate’s copy constructor was incomplete (#608)
Browse files Browse the repository at this point in the history
PodTemplate’s copy constructor was incomplete
  • Loading branch information
Vlatombe authored Oct 1, 2019
2 parents 464320a + cb9434b commit 35c10f8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
import hudson.model.Saveable;
import hudson.model.labels.LabelAtom;
import hudson.slaves.NodeProperty;
import hudson.util.XStream2;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.client.KubernetesClient;
import java.io.StringReader;
import jenkins.model.Jenkins;

/**
Expand Down Expand Up @@ -158,26 +160,9 @@ public PodTemplate() {
}

public PodTemplate(PodTemplate from) {
this.setAnnotations(from.getAnnotations());
this.setContainers(from.getContainers());
this.setImagePullSecrets(from.getImagePullSecrets());
this.setInstanceCap(from.getInstanceCap());
this.setLabel(from.getLabel());
this.setName(from.getName());
this.setNamespace(from.getNamespace());
this.setInheritFrom(from.getInheritFrom());
this.setNodeSelector(from.getNodeSelector());
this.setNodeUsageMode(from.getNodeUsageMode());
this.setServiceAccount(from.getServiceAccount());
this.setSlaveConnectTimeout(from.getSlaveConnectTimeout());
this.setActiveDeadlineSeconds(from.getActiveDeadlineSeconds());
this.setVolumes(from.getVolumes());
this.setWorkspaceVolume(from.getWorkspaceVolume());
this.yaml = from.yaml;
this.setYamls(from.getYamls());
this.setShowRawYaml(from.isShowRawYaml());
this.setNodeProperties(from.getNodeProperties());
this.setPodRetention(from.getPodRetention());
XStream2 xs = new XStream2();
xs.unmarshal(XStream2.getDefaultDriver().createReader(new StringReader(xs.toXML(from))), this);
this.yamls = from.yamls;
}

@Deprecated
Expand Down Expand Up @@ -740,10 +725,6 @@ protected Object readResolve() {
yamls = null;
}

if (showRawYaml == null) {
showRawYaml = Boolean.TRUE;
}

if (yamlMergeStrategy == null) {
yamlMergeStrategy = YamlMergeStrategy.defaultStrategy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public void multipleFilters() {
podtemplates.add(podTemplate);
List<PodTemplate> result = PodTemplateFilter.applyAll(null, podtemplates, Label.get("label"));
assertEquals(1, result.size());
List<String> yamls = result.get(0).getYamls();
assertEquals(2, yamls.size());
assertThat(yamls, Matchers.containsInAnyOrder("yaml1", "yaml2"));
assertThat(result.get(0).getYamls(), Matchers.containsInAnyOrder("yaml1", "yaml2"));
}

private static PodTemplate addYaml(@Nonnull PodTemplate podTemplate, String yaml) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.csanchez.jenkins.plugins.kubernetes;

import hudson.util.XStream2;
import org.junit.Test;

import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.*;

public class PodTemplateTest {
@Test
Expand All @@ -18,4 +19,16 @@ public void getYamlsExposesSingleYamlField() {
podTemplate.setYaml(null);
assertThat(podTemplate.getYamls(), empty());
}

@Test
public void copyConstructor() throws Exception {
XStream2 xs = new XStream2();
PodTemplate pt = new PodTemplate();
assertEquals(xs.toXML(pt), xs.toXML(new PodTemplate(pt)));
pt.setActiveDeadlineSeconds(99);
assertEquals(xs.toXML(pt), xs.toXML(new PodTemplate(pt)));
pt.setIdleMinutes(99);
assertEquals(xs.toXML(pt), xs.toXML(new PodTemplate(pt)));
}

}

0 comments on commit 35c10f8

Please sign in to comment.