You've already forked jenkins-lib
forked from jenkins/jenkins-lib
bump mockito, add tests, fix errors
This commit is contained in:
@@ -48,7 +48,7 @@ dependencies {
|
|||||||
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", junitVersion)
|
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", junitVersion)
|
||||||
|
|
||||||
testImplementation("org.assertj", "assertj-core", "3.15.0")
|
testImplementation("org.assertj", "assertj-core", "3.15.0")
|
||||||
testImplementation("org.mockito", "mockito-core", "3.3.3")
|
testImplementation("org.mockito", "mockito-core", "5.11.0")
|
||||||
|
|
||||||
testImplementation("org.slf4j", "slf4j-api", slf4jVersion)
|
testImplementation("org.slf4j", "slf4j-api", slf4jVersion)
|
||||||
testImplementation("org.slf4j", "slf4j-simple", slf4jVersion)
|
testImplementation("org.slf4j", "slf4j-simple", slf4jVersion)
|
||||||
|
@@ -178,21 +178,27 @@
|
|||||||
"description" : "Массив расширений для загрузки в конфигурацию.",
|
"description" : "Массив расширений для загрузки в конфигурацию.",
|
||||||
"items" : {
|
"items" : {
|
||||||
"type" : "object",
|
"type" : "object",
|
||||||
"id": "urn:jsonschema:ru:pulsar:jenkins:library:configuration:InitInfoBaseOptions:extensions:exception",
|
"id" : "urn:jsonschema:ru:pulsar:jenkins:library:configuration:InitInfoBaseOptions:Extension",
|
||||||
"description": "Информация о расширении для загрузки",
|
|
||||||
"properties" : {
|
"properties" : {
|
||||||
"name" : {
|
"name" : {
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
"description": "Имя расширения с которым оно грузится в конфигурацию"
|
"description" : "Имя расширения, используемое при его загрузке в конфигурацию."
|
||||||
},
|
},
|
||||||
"initMethod" : {
|
"initMethod" : {
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
"description": "\n Способ инициализации расширения.\n Поддерживается два варианта:\n * fromSource - инициализация расширения из исходников;\n * fromFile - использование скомпилированного cfe.",
|
"description" : "\n Способ инициализации расширения.\n Поддерживается два варианта:\n * fromSource - инициализация расширения из исходников;\n * fromFile - скачивание скомпилированного cfe по ссылке.\n ",
|
||||||
"enum" : [ "fromSource", "fromFile" ]
|
"enum" : [ "fromSource", "fromFile" ]
|
||||||
},
|
},
|
||||||
"path" : {
|
"path" : {
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
"description": "Хранит в себе путь к расширению.\n * В случае если выбран initMethod <fromSource> - указывается путь к исходникам расширения.\n * В случае если выбран initMethod <fromFile> - указывается путь к cfe-файлу"
|
"description" : "\n Путь к расширению.\n * В случае если выбран initMethod <fromSource> - указывается путь к исходникам расширения.\n * В случае если выбран initMethod <fromFile> - указывается путь к cfe-файлу\n "
|
||||||
|
},
|
||||||
|
"stages" : {
|
||||||
|
"type" : "array",
|
||||||
|
"description" : "\n Шаги, на которых необходимо использовать расширение\n * Если не заполнено, то расширение будет подключено при инициализации базы и останется в базе на всех последующих шагах.\n * Если заполнено, то расширение будет подключено только на соответствующих шагах.\n ",
|
||||||
|
"items" : {
|
||||||
|
"type" : "string"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -379,12 +385,7 @@
|
|||||||
"type" : "array",
|
"type" : "array",
|
||||||
"items" : {
|
"items" : {
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
"enum": [
|
"enum" : [ "developers", "requestor", "brokenBuildSuspects", "brokenTestsSuspects" ]
|
||||||
"developers",
|
|
||||||
"requestor",
|
|
||||||
"brokenBuildSuspects",
|
|
||||||
"brokenTestsSuspects"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -64,7 +64,6 @@ class InitInfoBaseOptions implements Serializable {
|
|||||||
", runMigration=" + runMigration +
|
", runMigration=" + runMigration +
|
||||||
", additionalInitializationSteps=" + additionalInitializationSteps +
|
", additionalInitializationSteps=" + additionalInitializationSteps +
|
||||||
", extensions=" + extensions +
|
", extensions=" + extensions +
|
||||||
", vrunnerSettings=" + vrunnerSettings +
|
|
||||||
'}'
|
'}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,27 +14,31 @@ class LoadExtensions implements Serializable {
|
|||||||
private final JobConfiguration config
|
private final JobConfiguration config
|
||||||
private final String stageName
|
private final String stageName
|
||||||
|
|
||||||
|
private Extension[] extensionsFiltered
|
||||||
|
|
||||||
LoadExtensions(JobConfiguration config, String stageName = "") {
|
LoadExtensions(JobConfiguration config, String stageName = "") {
|
||||||
this.config = config
|
this.config = config
|
||||||
this.stageName = stageName
|
this.stageName = stageName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Extension[] getExtensionsFiltered() {
|
||||||
|
return extensionsFiltered
|
||||||
|
}
|
||||||
|
|
||||||
def run() {
|
def run() {
|
||||||
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()
|
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()
|
||||||
|
|
||||||
Logger.printLocation()
|
Logger.printLocation()
|
||||||
|
|
||||||
|
|
||||||
Extension[] filteredExtensions
|
|
||||||
def extensions = this.config.initInfoBaseOptions.extensions
|
def extensions = this.config.initInfoBaseOptions.extensions
|
||||||
|
|
||||||
if (this.stageName) {
|
if (this.stageName) {
|
||||||
filteredExtensions = extensions.findAll { extension ->
|
this.extensionsFiltered = extensions.findAll { extension ->
|
||||||
extension.stages.contains(this.stageName)
|
extension.stages.contains(this.stageName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
filteredExtensions = extensions.findAll { extension -> extension.stages.empty || extension.stages.contains("initInfoBase") }
|
this.extensionsFiltered = extensions.findAll { extension -> extension.stages.empty || extension.stages.contains("initInfoBase") }
|
||||||
}
|
}
|
||||||
|
|
||||||
def env = steps.env()
|
def env = steps.env()
|
||||||
@@ -42,7 +46,7 @@ class LoadExtensions implements Serializable {
|
|||||||
|
|
||||||
String vrunnerPath = VRunner.getVRunnerPath()
|
String vrunnerPath = VRunner.getVRunnerPath()
|
||||||
|
|
||||||
filteredExtensions.each {
|
this.extensionsFiltered.each {
|
||||||
Logger.println("Установим расширение ${it.name}")
|
Logger.println("Установим расширение ${it.name}")
|
||||||
loadExtension(it, vrunnerPath, steps, cfeDir)
|
loadExtension(it, vrunnerPath, steps, cfeDir)
|
||||||
}
|
}
|
||||||
@@ -62,7 +66,7 @@ class LoadExtensions implements Serializable {
|
|||||||
loadCommand += executeParameter
|
loadCommand += executeParameter
|
||||||
loadCommand += ' --ibconnection "/F./build/ib"'
|
loadCommand += ' --ibconnection "/F./build/ib"'
|
||||||
|
|
||||||
String vrunnerSettings = getVrunnerSettings(this.config, this.stageName)
|
String vrunnerSettings = getVrunnerSettingsForStage(this.config, this.stageName)
|
||||||
if (vrunnerSettings && steps.fileExists(vrunnerSettings)) {
|
if (vrunnerSettings && steps.fileExists(vrunnerSettings)) {
|
||||||
loadCommand += " --settings $vrunnerSettings"
|
loadCommand += " --settings $vrunnerSettings"
|
||||||
}
|
}
|
||||||
@@ -73,7 +77,7 @@ class LoadExtensions implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getVrunnerSettings(JobConfiguration config, String stageName) {
|
private static String getVrunnerSettingsForStage(JobConfiguration config, String stageName) {
|
||||||
|
|
||||||
if (!stageName) {
|
if (!stageName) {
|
||||||
return ""
|
return ""
|
||||||
|
@@ -47,7 +47,7 @@ class jobConfigurationTest {
|
|||||||
'jobConfiguration.json',
|
'jobConfiguration.json',
|
||||||
StandardCharsets.UTF_8,
|
StandardCharsets.UTF_8,
|
||||||
this.getClass().getClassLoader()
|
this.getClass().getClassLoader()
|
||||||
);
|
)
|
||||||
|
|
||||||
def writeFile = """
|
def writeFile = """
|
||||||
writeFile text: \"\"\"$file\"\"\", file: 'jobConfiguration.json'
|
writeFile text: \"\"\"$file\"\"\", file: 'jobConfiguration.json'
|
||||||
@@ -74,6 +74,5 @@ class jobConfigurationTest {
|
|||||||
rule.assertLogContains("v8version='8.3.12.1500'", run)
|
rule.assertLogContains("v8version='8.3.12.1500'", run)
|
||||||
rule.assertLogContains("sonarScannerToolName='sonar-scanner'", run)
|
rule.assertLogContains("sonarScannerToolName='sonar-scanner'", run)
|
||||||
rule.assertLogContains("initMethod=FROM_SOURCE", run)
|
rule.assertLogContains("initMethod=FROM_SOURCE", run)
|
||||||
rule.assertLogContains("custom_units", run)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,19 +1,23 @@
|
|||||||
package ru.pulsar.jenkins.library.steps;
|
package ru.pulsar.jenkins.library.steps;
|
||||||
|
|
||||||
|
import hudson.FilePath;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import ru.pulsar.jenkins.library.IStepExecutor;
|
import org.mockito.MockedStatic;
|
||||||
|
import org.mockito.Mockito;
|
||||||
import ru.pulsar.jenkins.library.configuration.ConfigurationReader;
|
import ru.pulsar.jenkins.library.configuration.ConfigurationReader;
|
||||||
import ru.pulsar.jenkins.library.configuration.JobConfiguration;
|
import ru.pulsar.jenkins.library.configuration.JobConfiguration;
|
||||||
|
import ru.pulsar.jenkins.library.utils.FileUtils;
|
||||||
import ru.pulsar.jenkins.library.utils.TestUtils;
|
import ru.pulsar.jenkins.library.utils.TestUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
|
||||||
class LoadExtensionsTest {
|
class LoadExtensionsTest {
|
||||||
|
|
||||||
@@ -25,21 +29,25 @@ class LoadExtensionsTest {
|
|||||||
@Test
|
@Test
|
||||||
void runYaxunit() throws IOException {
|
void runYaxunit() throws IOException {
|
||||||
|
|
||||||
|
try (MockedStatic<FileUtils> fu = Mockito.mockStatic(FileUtils.class)) {
|
||||||
|
fu.when(() -> FileUtils.getFilePath(anyString()))
|
||||||
|
.thenReturn(new FilePath(new File("/")));
|
||||||
|
|
||||||
// given
|
// given
|
||||||
|
// файл содержит 2 расширения для двух стейджей
|
||||||
String config = IOUtils.resourceToString(
|
String config = IOUtils.resourceToString(
|
||||||
"jobConfiguration.json",
|
"jobConfiguration.json",
|
||||||
StandardCharsets.UTF_8,
|
StandardCharsets.UTF_8,
|
||||||
this.getClass().getClassLoader()
|
this.getClass().getClassLoader()
|
||||||
);
|
);
|
||||||
|
|
||||||
// when
|
|
||||||
JobConfiguration jobConfiguration = ConfigurationReader.create(config);
|
JobConfiguration jobConfiguration = ConfigurationReader.create(config);
|
||||||
|
|
||||||
LoadExtensions loadExtensions = new LoadExtensions(jobConfiguration, "yaxunit");
|
LoadExtensions loadExtensions = new LoadExtensions(jobConfiguration, "yaxunit");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Object run = loadExtensions.run();
|
loadExtensions.run();
|
||||||
|
|
||||||
// assertThat(log.toString).(1);
|
// then
|
||||||
|
assertThat(loadExtensions.getExtensionsFiltered().length).isEqualTo(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,32 @@
|
|||||||
|
package ru.pulsar.jenkins.library.utils;
|
||||||
|
|
||||||
|
import hudson.EnvVars;
|
||||||
|
import org.jenkinsci.plugins.workflow.support.actions.EnvironmentAction;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class EnvUtils implements EnvironmentAction {
|
||||||
|
|
||||||
|
public String NODE_NAME = "node";
|
||||||
|
public String WORKSPACE = "ws";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnvVars getEnvironment() throws IOException, InterruptedException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIconFileName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDisplayName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUrlName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@@ -28,6 +28,8 @@ public class TestUtils {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
when(steps.env()).thenAnswer(invocation -> new EnvUtils());
|
||||||
|
|
||||||
when(steps.readFile(anyString(), anyString())).thenAnswer(invocation -> {
|
when(steps.readFile(anyString(), anyString())).thenAnswer(invocation -> {
|
||||||
String file = invocation.getArgument(0);
|
String file = invocation.getArgument(0);
|
||||||
String encoding = invocation.getArgument(1);
|
String encoding = invocation.getArgument(1);
|
||||||
|
@@ -14,6 +14,20 @@
|
|||||||
"runMigration": false,
|
"runMigration": false,
|
||||||
"additionalInitializationSteps": [
|
"additionalInitializationSteps": [
|
||||||
"vanessa --settings ./tools/vrunner.first.json"
|
"vanessa --settings ./tools/vrunner.first.json"
|
||||||
|
],
|
||||||
|
"extensions": [
|
||||||
|
{
|
||||||
|
"name": "YAXUnit",
|
||||||
|
"initMethod": "fromSource",
|
||||||
|
"path": "./src/cfe/YAXUnit",
|
||||||
|
"stages": ["yaxunit"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "BDD",
|
||||||
|
"initMethod": "fromSource",
|
||||||
|
"path": "./src/cfe/bdd",
|
||||||
|
"stages": ["bdd"]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"sonarqube": {
|
"sonarqube": {
|
||||||
|
Reference in New Issue
Block a user