From 95f22fba3ba6f460c9dba27497bb0e51407b1af8 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 8 Feb 2020 15:04:05 -0700 Subject: [PATCH] Cover NodeLabelCache case when computer is null Getting labels for a node is not expected to return null for the computer of the node, but if it returns null, the case is handled and now is also tested that it continues to be handled. --- .../platformlabeler/NodeLabelCacheTest.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/test/java/org/jvnet/hudson/plugins/platformlabeler/NodeLabelCacheTest.java b/src/test/java/org/jvnet/hudson/plugins/platformlabeler/NodeLabelCacheTest.java index cb9b53869..25ffb1923 100644 --- a/src/test/java/org/jvnet/hudson/plugins/platformlabeler/NodeLabelCacheTest.java +++ b/src/test/java/org/jvnet/hudson/plugins/platformlabeler/NodeLabelCacheTest.java @@ -11,6 +11,7 @@ import hudson.slaves.RetentionStrategy; import java.io.IOException; import java.nio.charset.Charset; +import java.util.Collection; import java.util.List; import java.util.Set; import java.util.concurrent.Future; @@ -85,6 +86,13 @@ public void testCacheLabelsNullingComputer() throws Exception { nodeLabelCache.cacheLabels(nullingComputer); } + @Test + public void testGetLabelsForNode_IsNull() throws Exception { + Node nullingNode = new NullingNode(); + Collection labels = nodeLabelCache.getLabelsForNode(nullingNode); + assertThat(labels, is(empty())); + } + /** Class that intentionally returns nulls for test purposes. */ private class NullingComputer extends Computer { @@ -140,4 +148,61 @@ public RetentionStrategy getRetentionStrategy() { throw new UnsupportedOperationException("Unsupported"); } } + + private class NullingNode extends Node { + public hudson.remoting.Callable + getClockDifferenceCallable() { + throw new UnsupportedOperationException("Unsupported"); + } + + public hudson.slaves.NodeDescriptor getDescriptor() { + throw new UnsupportedOperationException("Unsupported"); + } + + public hudson.util.DescribableList< + hudson.slaves.NodeProperty, hudson.slaves.NodePropertyDescriptor> + getNodeProperties() { + throw new UnsupportedOperationException("Unsupported"); + } + + public hudson.FilePath getRootPath() { + throw new UnsupportedOperationException("Unsupported"); + } + + public hudson.FilePath getWorkspaceFor(hudson.model.TopLevelItem item) { + throw new UnsupportedOperationException("Unsupported"); + } + + public String getLabelString() { + throw new UnsupportedOperationException("Unsupported"); + } + + public Computer createComputer() { + throw new UnsupportedOperationException("Unsupported"); + } + + public Node.Mode getMode() { + throw new UnsupportedOperationException("Unsupported"); + } + + public int getNumExecutors() { + throw new UnsupportedOperationException("Unsupported"); + } + + public hudson.Launcher createLauncher(TaskListener listener) { + throw new UnsupportedOperationException("Unsupported"); + } + + public String getNodeDescription() { + throw new UnsupportedOperationException("Unsupported"); + } + + public void setNodeName(String name) { + throw new UnsupportedOperationException("Unsupported"); + } + + public String getNodeName() { + throw new UnsupportedOperationException("Unsupported"); + } + } }