-
Notifications
You must be signed in to change notification settings - Fork 24
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
Increased versioncolumn coverage #278
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests look very good. One optional change that I'd like in this pull request so that we don't duplicate the junit test dependency
Thanks. This looks great. For future pull requests, please use a branch named something other than "master" so that I can use standard "gh" and "git" commands to interact with your pull request. |
@Test | ||
public void testMonitor_DifferentVersion_NotIgnored() throws IOException, InterruptedException { | ||
VersionMonitor.DescriptorImpl descriptor = spy(new VersionMonitor.DescriptorImpl()); | ||
doReturn(false).when(descriptor).isIgnored(); // Ensure isIgnored returns false | ||
|
||
Computer computer = mock(Computer.class); | ||
VirtualChannel channel = mock(VirtualChannel.class); | ||
String differentVersion = "different-version"; | ||
|
||
when(computer.getChannel()).thenReturn(channel); | ||
when(channel.call(ArgumentMatchers.<MasterToSlaveCallable<String, IOException>>any())) | ||
.thenReturn(differentVersion); | ||
when(computer.isOffline()).thenReturn(false); | ||
when(computer.getName()).thenReturn("TestComputer"); | ||
|
||
String result = descriptor.monitor(computer); | ||
|
||
assertEquals(differentVersion, result); | ||
verify(computer).setTemporarilyOffline(eq(true), any(VersionMonitor.RemotingVersionMismatchCause.class)); | ||
} | ||
|
||
@Test | ||
public void testMonitor_DifferentVersion_Ignored() throws IOException, InterruptedException { | ||
VersionMonitor.DescriptorImpl descriptor = spy(new VersionMonitor.DescriptorImpl()); | ||
doReturn(true).when(descriptor).isIgnored(); // Ensure isIgnored returns true | ||
|
||
Computer computer = mock(Computer.class); | ||
VirtualChannel channel = mock(VirtualChannel.class); | ||
String differentVersion = "different-version"; | ||
|
||
when(computer.getChannel()).thenReturn(channel); | ||
when(channel.call(ArgumentMatchers.<MasterToSlaveCallable<String, IOException>>any())) | ||
.thenReturn(differentVersion); | ||
when(computer.isOffline()).thenReturn(false); | ||
|
||
String result = descriptor.monitor(computer); | ||
|
||
assertEquals(differentVersion, result); | ||
verify(computer, never()).setTemporarilyOffline(anyBoolean(), any()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These newly-added tests are failing on recent cores as of jenkinsci/jenkins#9855. A hazard of using Mockito.
Testing done
Submitter checklist