-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jenkins core version requirement probe (#154)
- Loading branch information
Showing
8 changed files
with
197 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/io/jenkins/pluginhealth/scoring/probes/JenkinsCoreProbe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2022 Jenkins Infra | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.jenkins.pluginhealth.scoring.probes; | ||
|
||
import io.jenkins.pluginhealth.scoring.model.Plugin; | ||
import io.jenkins.pluginhealth.scoring.model.ProbeResult; | ||
import io.jenkins.pluginhealth.scoring.model.updatecenter.UpdateCenter; | ||
|
||
import org.springframework.core.annotation.Order; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Order(JenkinsCoreProbe.ORDER) | ||
public class JenkinsCoreProbe extends Probe { | ||
public static final String KEY = "jenkins-version"; | ||
public static final int ORDER = InstallationStatProbe.ORDER + 1; | ||
|
||
@Override | ||
protected ProbeResult doApply(Plugin plugin, ProbeContext context) { | ||
final UpdateCenter uc = context.getUpdateCenter(); | ||
final io.jenkins.pluginhealth.scoring.model.updatecenter.Plugin ucPlugin = uc.plugins().get(plugin.getName()); | ||
|
||
if (ucPlugin == null) { | ||
return ProbeResult.failure(KEY, "Plugin is not in the update-center"); | ||
} | ||
return ProbeResult.success(KEY, ucPlugin.requiredCore()); | ||
} | ||
|
||
@Override | ||
public String key() { | ||
return KEY; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "This probe registers the Jenkins core version requirement for each plugin."; | ||
} | ||
|
||
@Override | ||
protected boolean requiresRelease() { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/test/java/io/jenkins/pluginhealth/scoring/probes/JenkinsCoreProbeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2022 Jenkins Infra | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.jenkins.pluginhealth.scoring.probes; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import io.jenkins.pluginhealth.scoring.model.Plugin; | ||
import io.jenkins.pluginhealth.scoring.model.ProbeResult; | ||
import io.jenkins.pluginhealth.scoring.model.ResultStatus; | ||
import io.jenkins.pluginhealth.scoring.model.updatecenter.UpdateCenter; | ||
|
||
import org.assertj.core.api.SoftAssertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class JenkinsCoreProbeTest { | ||
@Test | ||
public void shouldBeUsingJenkinsVersionKey() { | ||
final JenkinsCoreProbe probe = spy(JenkinsCoreProbe.class); | ||
assertThat(probe.key()).isEqualTo("jenkins-version"); | ||
} | ||
|
||
@Test | ||
public void shouldRequireRelease() { | ||
final JenkinsCoreProbe probe = spy(JenkinsCoreProbe.class); | ||
assertThat(probe.requiresRelease()).isTrue(); | ||
} | ||
|
||
@Test | ||
public void shouldNotRequireSourceCodeChange() { | ||
final JenkinsCoreProbe probe = spy(JenkinsCoreProbe.class); | ||
assertThat(probe.isSourceCodeRelated()).isFalse(); | ||
} | ||
|
||
@Test | ||
public void shouldHaveDescription() { | ||
final JenkinsCoreProbe probe = spy(JenkinsCoreProbe.class); | ||
assertThat(probe.getDescription()).isNotBlank(); | ||
} | ||
|
||
@Test | ||
public void shouldFailIfPluginNotInUpdateCenter() { | ||
final String pluginName = "plugin"; | ||
final Plugin plugin = mock(Plugin.class); | ||
final ProbeContext ctx = mock(ProbeContext.class); | ||
|
||
when(plugin.getName()).thenReturn(pluginName); | ||
when(ctx.getUpdateCenter()).thenReturn(new UpdateCenter( | ||
Map.of(), | ||
Map.of(), | ||
List.of() | ||
)); | ||
|
||
final JenkinsCoreProbe probe = spy(JenkinsCoreProbe.class); | ||
final ProbeResult result = probe.apply(plugin, ctx); | ||
|
||
assertThat(result).isNotNull(); | ||
SoftAssertions.assertSoftly(softly -> { | ||
softly.assertThat(result).extracting("id").isEqualTo(probe.key()); | ||
softly.assertThat(result).extracting("status").isEqualTo(ResultStatus.FAILURE); | ||
softly.assertThat(result).extracting("message").isEqualTo("Plugin is not in the update-center"); | ||
}); | ||
} | ||
|
||
@Test | ||
public void shouldBeAbleToExtractJenkinsVersionFromUpdateCenter() { | ||
final String pluginName = "plugin"; | ||
final Plugin plugin = mock(Plugin.class); | ||
final ProbeContext ctx = mock(ProbeContext.class); | ||
|
||
when(plugin.getName()).thenReturn(pluginName); | ||
when(ctx.getUpdateCenter()).thenReturn(new UpdateCenter( | ||
Map.of( | ||
pluginName, | ||
new io.jenkins.pluginhealth.scoring.model.updatecenter.Plugin( | ||
pluginName, null, null, null, List.of(), 0, "2.361.1" | ||
) | ||
), | ||
Map.of(), | ||
List.of() | ||
)); | ||
|
||
final JenkinsCoreProbe probe = spy(JenkinsCoreProbe.class); | ||
final ProbeResult result = probe.apply(plugin, ctx); | ||
|
||
assertThat(result).isNotNull(); | ||
SoftAssertions.assertSoftly(softly -> { | ||
softly.assertThat(result).extracting("id").isEqualTo(probe.key()); | ||
softly.assertThat(result).extracting("status").isEqualTo(ResultStatus.SUCCESS); | ||
softly.assertThat(result).extracting("message").isEqualTo("2.361.1"); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters