Skip to content

Commit

Permalink
Prevents executing probes on plugin with no scm configured (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecharp authored Oct 10, 2023
1 parent 2283ba6 commit 8c59f97
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public void runOn(Plugin plugin) throws IOException {
}

private void runOn(Plugin plugin, UpdateCenter updateCenter) {
if (plugin.getScm() == null || plugin.getScm().isBlank()) {
LOGGER.info("Will not run probes on {} because its SCM is not set correctly.", plugin.getName());
return;
}
final ProbeContext probeContext;
try {
probeContext = probeService.getProbeContext(plugin, updateCenter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void shouldBeAbleToRunSimpleProbe() throws IOException {

final ProbeResult expectedResult = ProbeResult.success("foo", "bar", 1);

when(plugin.getScm()).thenReturn("this-is-ok-for-testing");
when(plugin.getDetails()).thenReturn(Map.of());
when(probe.key()).thenReturn("probe");
when(probe.doApply(plugin, ctx)).thenReturn(expectedResult);
Expand All @@ -105,6 +106,7 @@ void shouldNotApplyProbeWithReleaseRequirementOnPluginWithNoNewReleaseWithPastRe
final Probe probe = spy(Probe.class);
final ProbeContext ctx = mock(ProbeContext.class);

when(plugin.getScm()).thenReturn("this-is-ok-for-testing");
when(plugin.getName()).thenReturn("foo");
when(plugin.getReleaseTimestamp()).thenReturn(ZonedDateTime.now().minusDays(1));
when(plugin.getDetails()).thenReturn(Map.of(probeKey, ProbeResult.success(probeKey, "This is good", 1)));
Expand All @@ -130,6 +132,7 @@ void shouldNotApplyProbeRelatedToCodeWithNoNewCode() throws IOException {
final Probe probe = spy(Probe.class);
final ProbeContext ctx = mock(ProbeContext.class);

when(plugin.getScm()).thenReturn("this-is-ok-for-testing");
when(plugin.getDetails()).thenReturn(Map.of(
"probe", new ProbeResult("probe", "message", ProbeResult.Status.SUCCESS, ZonedDateTime.now().minusDays(1), 1)
));
Expand Down Expand Up @@ -159,6 +162,7 @@ void shouldApplyProbeRelatedToCodeWithNewCommit() throws IOException {

final ProbeResult result = new ProbeResult(probeKey, "message", ProbeResult.Status.SUCCESS, 1);

when(plugin.getScm()).thenReturn("this-is-ok-for-testing");
when(plugin.getDetails()).thenReturn(Map.of(
probeKey, new ProbeResult(probeKey, "message", ProbeResult.Status.SUCCESS, ZonedDateTime.now().minusDays(1), 1)
));
Expand Down Expand Up @@ -189,6 +193,7 @@ void shouldApplyProbeWithReleaseRequirementOnPluginWithNewReleaseAndPastResult()
final Probe probe = spy(Probe.class);
final ProbeContext ctx = mock(ProbeContext.class);

when(plugin.getScm()).thenReturn("this-is-ok-for-testing");
when(plugin.getReleaseTimestamp()).thenReturn(ZonedDateTime.now());
when(plugin.getDetails()).thenReturn(Map.of(probeKey, new ProbeResult(probeKey, "this is ok", ProbeResult.Status.SUCCESS, ZonedDateTime.now().minusDays(1), 1)));

Expand All @@ -215,6 +220,7 @@ void shouldApplyProbeWithNoReleaseRequirementOnPluginWithPastResult() throws IOE
final Probe probe = spy(Probe.class);
final ProbeContext ctx = mock(ProbeContext.class);

when(plugin.getScm()).thenReturn("this-is-ok-for-testing");
when(plugin.getDetails()).thenReturn(Map.of(
probeKey,
new ProbeResult(probeKey, "this is ok", ProbeResult.Status.SUCCESS, ZonedDateTime.now().minusDays(1), 1)
Expand Down Expand Up @@ -242,6 +248,7 @@ void shouldSaveEvenErrors() throws IOException {
final Probe probe = spy(Probe.class);
final ProbeContext ctx = mock(ProbeContext.class);

when(plugin.getScm()).thenReturn("this-is-ok-for-testing");
when(probe.doApply(plugin, ctx)).thenReturn(ProbeResult.error("foo", "bar", 1));

when(probeService.getProbeContext(any(Plugin.class), any(UpdateCenter.class))).thenReturn(ctx);
Expand Down Expand Up @@ -290,6 +297,8 @@ public long getVersion() {
when(probeService.getProbes()).thenReturn(List.of(probeOne, probeTwo));
when(pluginService.streamAll()).thenReturn(Stream.of(plugin));

when(plugin.getScm()).thenReturn("this-is-ok-for-testing");

final ProbeEngine probeEngine = new ProbeEngine(probeService, pluginService, updateCenterService, gitHub, pluginDocumentationService);
probeEngine.run();

Expand Down Expand Up @@ -335,6 +344,7 @@ protected boolean isSourceCodeRelated() {
final ProbeContext ctx = mock(ProbeContext.class);

final ProbeResult previousResult = new ProbeResult(probeKey, "this is a message", ProbeResult.Status.SUCCESS, version);
when(plugin.getScm()).thenReturn("this-is-ok-for-testing");
when(plugin.getDetails()).thenReturn(Map.of(
probeKey, previousResult
));
Expand Down

0 comments on commit 8c59f97

Please sign in to comment.