Skip to content

Commit

Permalink
even better test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecirioli committed Nov 11, 2024
1 parent 7e4f0fa commit 5ec3dde
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/test/java/hudson/plugins/ec2/FileBasedSSHKeyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.RealJenkinsRule;

import java.util.Collections;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

Expand All @@ -17,10 +19,18 @@ public class FileBasedSSHKeyTest {
public void testFileBasedSShKey() throws Throwable {
r.startJenkins();
r.runRemotely(FileBasedSSHKeyTest::verifyKeyFile);
r.runRemotely(FileBasedSSHKeyTest::verifyCorrectKeyIsResolved);
}

private static void verifyKeyFile(JenkinsRule r) throws Throwable {
assertNotNull("file content should not have been empty", EC2PrivateKey.fetchFromDisk());
assertEquals("file content did not match", EC2PrivateKey.fetchFromDisk().getPrivateKey(),"hello, world!");
}

private static void verifyCorrectKeyIsResolved(JenkinsRule r) throws Throwable {
AmazonEC2Cloud cloud = new AmazonEC2Cloud("us-east-1", true, "abc", "us-east-1", null, "ghi", "3", Collections.emptyList(), "roleArn", "roleSessionName");
r.jenkins.clouds.add(cloud);
AmazonEC2Cloud c = r.jenkins.clouds.get(AmazonEC2Cloud.class);
assertEquals("An unexpected key was returned!", c.resolvePrivateKey().getPrivateKey(),"hello, world!");
}
}

0 comments on commit 5ec3dde

Please sign in to comment.