diff --git a/pom.xml b/pom.xml index 0b78330..3984e9d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.jenkins-ci.plugins plugin - 5.26 + 5.27 io.jenkins.plugins @@ -14,10 +14,12 @@ 999999-SNAPSHOT - 2.492 - ${jenkins.baseline}.3 + + 2.528 + 2.532 true jenkinsci/${project.artifactId}-plugin + false Pipeline Logging over CloudWatch Plugin @@ -50,7 +52,7 @@ io.jenkins.tools.bom bom-${jenkins.baseline}.x - 5473.vb_9533d9e5d88 + 5577.vea_979d35b_b_ff import pom @@ -64,6 +66,12 @@ io.jenkins.plugins aws-global-configuration + + + com.sun.xml.bind + jaxb-impl + + org.jenkins-ci.plugins @@ -72,11 +80,15 @@ org.jenkins-ci.plugins.workflow workflow-api + + 1409.v2617b_cfa_ff03 org.jenkins-ci.plugins.workflow workflow-api tests + + 1409.v2617b_cfa_ff03 test diff --git a/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/ConsoleNotesTest.java b/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/ConsoleNotesTest.java index 14e0545..32da88e 100644 --- a/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/ConsoleNotesTest.java +++ b/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/ConsoleNotesTest.java @@ -29,14 +29,16 @@ import java.nio.charset.StandardCharsets; import java.util.Map; import net.sf.json.JSONObject; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class ConsoleNotesTest { +class ConsoleNotesTest { @Test - public void parse() throws Exception { + void parse() throws Exception { assertParse("some message\n"); assertParse("some message\r\n"); assertParse("\u001b[8mha:////SomeJunk+AAAA\u001b[0m[Pipeline] }\n"); @@ -60,7 +62,6 @@ private static void assertParse(String line) throws Exception { if (line.contains(ConsoleNote.PREAMBLE_STR) && line.contains(ConsoleNote.POSTAMBLE_STR)) { assertThat(line + " converted to " + json, (String) map.get("message"), not(containsString("\u001b"))); } - assertEquals(line + " converted to " + json, line.replaceFirst("[\r\n]+$", "") + "\n", w.toString()); + assertEquals(line.replaceFirst("[\r\n]+$", "") + "\n", w.toString(), line + " converted to " + json); } - } diff --git a/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/IntegrationTest.java b/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/IntegrationTest.java index 1a99070..2c35837 100644 --- a/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/IntegrationTest.java +++ b/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/IntegrationTest.java @@ -33,23 +33,28 @@ import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; import org.jenkinsci.plugins.workflow.job.WorkflowJob; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.JenkinsRule; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; -import static org.junit.Assume.assumeFalse; +import static org.junit.jupiter.api.Assumptions.assumeFalse; + +import org.jvnet.hudson.test.junit.jupiter.WithJenkins; import software.amazon.awssdk.services.cloudwatchlogs.model.ResourceNotFoundException; -public class IntegrationTest { +@WithJenkins +class IntegrationTest { + + private JenkinsRule r; - @Rule public JenkinsRule r = new JenkinsRule(); + @BeforeEach + void setUp(JenkinsRule rule) throws Exception { + r = rule; - @Before public void setUp() throws Exception { PipelineBridgeTest.globalConfiguration(); CloudWatchAwsGlobalConfiguration config = ExtensionList.lookupSingleton(CloudWatchAwsGlobalConfiguration.class); var client = config.getCloudWatchLogsClient(); @@ -63,30 +68,35 @@ public class IntegrationTest { } @Issue("https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/112") - @Test public void missingNewline() throws Exception { + @Test + void missingNewline() throws Exception { assumeFalse(Functions.isWindows()); CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), new StringCredentialsImpl(CredentialsScope.GLOBAL, "creds", null, Secret.fromString("s3cr3t"))); r.createSlave("remote", null, null); WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition( - "node('remote') {\n" + - " withCredentials([string(variable: 'UNUSED', credentialsId: 'creds')]) {\n" + - " sh 'set +x; printf \"missing final newline\"'\n" + - " }\n" + - "}", true)); + """ + node('remote') { + withCredentials([string(variable: 'UNUSED', credentialsId: 'creds')]) { + sh 'set +x; printf "missing final newline"' + } + }""", true)); r.assertLogContains("missing final newline", r.buildAndAssertSuccess(p)); } - @Test public void distinctProjectsAndBuilds() throws Exception { + @Test + void distinctProjectsAndBuilds() throws Exception { assumeFalse(Functions.isWindows()); r.createSlave("remote", null, null); var script = - "node('!remote') {\n" + - " sh 'echo $BUILD_TAG on master'\n" + - "}\n" + - "node('remote') {\n" + - " sh 'echo $BUILD_TAG on agent'\n" + - "}\n"; + """ + node('!remote') { + sh 'echo $BUILD_TAG on master' + } + node('remote') { + sh 'echo $BUILD_TAG on agent' + } + """; var first = r.jenkins.createProject(WorkflowJob.class, "first"); first.setDefinition(new CpsFlowDefinition(script, true)); var second = r.jenkins.createProject(WorkflowJob.class, "second"); @@ -109,5 +119,4 @@ public class IntegrationTest { containsString("jenkins-second-1 on agent"), not(containsString("jenkins-first-")))); } - } diff --git a/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/PipelineBridgeTest.java b/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/PipelineBridgeTest.java index db9e3a9..5e5028c 100644 --- a/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/PipelineBridgeTest.java +++ b/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/PipelineBridgeTest.java @@ -34,24 +34,24 @@ import java.util.Map; import java.util.UUID; import java.util.logging.Level; -import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + import org.jenkinsci.plugins.workflow.log.LogStorage; import org.jenkinsci.plugins.workflow.log.LogStorageTestBase; -import static org.junit.Assume.*; -import org.junit.Before; -import org.junit.Rule; -import org.jvnet.hudson.test.LoggerRule; +import org.junit.jupiter.api.BeforeEach; +import org.jvnet.hudson.test.LogRecorder; -public class PipelineBridgeTest extends LogStorageTestBase { +class PipelineBridgeTest extends LogStorageTestBase { private static final String LOG_STREAM_NAME = "PipelineBridgeTest"; - @Rule public LoggerRule logging = new LoggerRule().recordPackage(PipelineBridge.class, Level.FINER); + @SuppressWarnings("unused") + private final LogRecorder logging = new LogRecorder().recordPackage(PipelineBridge.class, Level.FINER); private String id; - static void globalConfiguration() throws Exception { + static void globalConfiguration() { String logGroupName = System.getenv("CLOUDWATCH_LOG_GROUP_NAME"); - assumeThat("must define $CLOUDWATCH_LOG_GROUP_NAME", logGroupName, notNullValue()); + assumeTrue(logGroupName != null, "must define $CLOUDWATCH_LOG_GROUP_NAME"); String role = System.getenv("AWS_ROLE"); String credentialsId = null; if (role != null) { @@ -61,21 +61,23 @@ static void globalConfiguration() throws Exception { } CloudWatchAwsGlobalConfiguration configuration = ExtensionList.lookupSingleton(CloudWatchAwsGlobalConfiguration.class); FormValidation logGroupNameValidation = configuration.validate(logGroupName, null, credentialsId, false); - assumeThat(logGroupNameValidation.toString(), logGroupNameValidation.kind, is(FormValidation.Kind.OK)); + assumeTrue(logGroupNameValidation.kind == FormValidation.Kind.OK, logGroupNameValidation.toString()); configuration.setLogGroupName(logGroupName); } - @Before public void setUp() throws Exception { + @BeforeEach + void setUp() { globalConfiguration(); id = UUID.randomUUID().toString(); } - @Override protected LogStorage createStorage() { + @Override + protected LogStorage createStorage() { return PipelineBridge.get().forIDs(LOG_STREAM_NAME, id); } - @Override protected Map agentLoggers() { + @Override + protected Map agentLoggers() { return Collections.singletonMap(PipelineBridge.class.getPackage().getName(), Level.FINER); } - } diff --git a/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/TimestampTrackerTest.java b/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/TimestampTrackerTest.java index 778b965..0de7508 100644 --- a/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/TimestampTrackerTest.java +++ b/src/test/java/io/jenkins/plugins/pipeline_cloudwatch_logs/TimestampTrackerTest.java @@ -24,18 +24,44 @@ package io.jenkins.plugins.pipeline_cloudwatch_logs; -import org.junit.Test; -import static org.junit.Assert.*; +import org.junit.jupiter.api.Test; -public class TimestampTrackerTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; - @Test public void monoticallyIncrease() throws Exception { +class TimestampTrackerTest { + + @Test + void monoticallyIncrease() { assertEquals(1234, TimestampTracker.monoticallyIncrease(0, 1234)); assertEquals(1235, TimestampTracker.monoticallyIncrease(1234, 1234)); assertEquals(1236, TimestampTracker.monoticallyIncrease(1235, 1234)); assertEquals(3000, TimestampTracker.monoticallyIncrease(3000, 1234)); } - // TODO test for checkCompletion + @Test + void checkCompletion() { + TimestampTracker tracker = new TimestampTracker(); + assertTrue(tracker.checkCompletion(timestamp -> true)); + assertTrue(tracker.checkCompletion(timestamp -> false)); + + tracker.eventSent(); + assertTrue(tracker.checkCompletion(timestamp -> true)); + + tracker.eventSent(); + assertFalse(tracker.checkCompletion(timestamp -> false)); + tracker.eventSent(); + assertTrue(tracker.checkCompletion(timestamp -> { + tracker.eventSent(); + return true; + })); + + tracker.eventSent(); + assertFalse(tracker.checkCompletion(timestamp -> { + tracker.eventSent(); + return false; + })); + } }