Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PodTemplate’s copy constructor was incomplete #608

Merged
merged 4 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,15 @@ public PodTemplate(PodTemplate from) {
this.setServiceAccount(from.getServiceAccount());
this.setSlaveConnectTimeout(from.getSlaveConnectTimeout());
this.setActiveDeadlineSeconds(from.getActiveDeadlineSeconds());
this.setIdleMinutes(from.getIdleMinutes());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this was really wrong: the idleMinutes in the copy was always zero.

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.showRawYaml = from.showRawYaml;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to avoid having the field be defined in the copy when null in the original.

if (from.nodeProperties != null) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

this.setNodeProperties(from.getNodeProperties());
}
this.setPodRetention(from.getPodRetention());
}

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)));
}

}