You've already forked jenkins-lib
forked from jenkins/jenkins-lib
bump mockito, add tests, fix errors
This commit is contained in:
@@ -47,7 +47,7 @@ class jobConfigurationTest {
|
||||
'jobConfiguration.json',
|
||||
StandardCharsets.UTF_8,
|
||||
this.getClass().getClassLoader()
|
||||
);
|
||||
)
|
||||
|
||||
def writeFile = """
|
||||
writeFile text: \"\"\"$file\"\"\", file: 'jobConfiguration.json'
|
||||
@@ -74,6 +74,5 @@ class jobConfigurationTest {
|
||||
rule.assertLogContains("v8version='8.3.12.1500'", run)
|
||||
rule.assertLogContains("sonarScannerToolName='sonar-scanner'", run)
|
||||
rule.assertLogContains("initMethod=FROM_SOURCE", run)
|
||||
rule.assertLogContains("custom_units", run)
|
||||
}
|
||||
}
|
@@ -1,19 +1,23 @@
|
||||
package ru.pulsar.jenkins.library.steps;
|
||||
|
||||
import hudson.FilePath;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
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.JobConfiguration;
|
||||
import ru.pulsar.jenkins.library.utils.FileUtils;
|
||||
import ru.pulsar.jenkins.library.utils.TestUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
|
||||
class LoadExtensionsTest {
|
||||
|
||||
@@ -25,21 +29,25 @@ class LoadExtensionsTest {
|
||||
@Test
|
||||
void runYaxunit() throws IOException {
|
||||
|
||||
// given
|
||||
String config = IOUtils.resourceToString(
|
||||
"jobConfiguration.json",
|
||||
StandardCharsets.UTF_8,
|
||||
this.getClass().getClassLoader()
|
||||
);
|
||||
try (MockedStatic<FileUtils> fu = Mockito.mockStatic(FileUtils.class)) {
|
||||
fu.when(() -> FileUtils.getFilePath(anyString()))
|
||||
.thenReturn(new FilePath(new File("/")));
|
||||
|
||||
// when
|
||||
JobConfiguration jobConfiguration = ConfigurationReader.create(config);
|
||||
// given
|
||||
// файл содержит 2 расширения для двух стейджей
|
||||
String config = IOUtils.resourceToString(
|
||||
"jobConfiguration.json",
|
||||
StandardCharsets.UTF_8,
|
||||
this.getClass().getClassLoader()
|
||||
);
|
||||
JobConfiguration jobConfiguration = ConfigurationReader.create(config);
|
||||
LoadExtensions loadExtensions = new LoadExtensions(jobConfiguration, "yaxunit");
|
||||
|
||||
LoadExtensions loadExtensions = new LoadExtensions(jobConfiguration, "yaxunit");
|
||||
// when
|
||||
loadExtensions.run();
|
||||
|
||||
// when
|
||||
Object 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 -> {
|
||||
String file = invocation.getArgument(0);
|
||||
String encoding = invocation.getArgument(1);
|
||||
|
@@ -14,6 +14,20 @@
|
||||
"runMigration": false,
|
||||
"additionalInitializationSteps": [
|
||||
"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": {
|
||||
|
Reference in New Issue
Block a user