Skip to content

Commit

Permalink
fix and add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ovcharenko-di committed May 7, 2024
1 parent a7eca18 commit 1e8a4ef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ru/pulsar/jenkins/library/steps/LoadExtensions.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LoadExtensions implements Serializable {
}
}
else {
this.extensionsFiltered = extensions.findAll { extension -> extension.stages.empty || extension.stages.contains("initInfoBase") }
this.extensionsFiltered = extensions.findAll { extension -> extension.stages.length == 0 || extension.stages.contains("initInfoBase") }
}

def env = steps.env()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import ru.pulsar.jenkins.library.configuration.ConfigurationReader;
import ru.pulsar.jenkins.library.configuration.InitInfoBaseOptions;
import ru.pulsar.jenkins.library.configuration.JobConfiguration;
import ru.pulsar.jenkins.library.utils.FileUtils;
import ru.pulsar.jenkins.library.utils.TestUtils;
Expand All @@ -34,20 +35,32 @@ void runYaxunit() throws IOException {
.thenReturn(new FilePath(new File("/")));

// given
// файл содержит 2 расширения для двух стейджей
// файл содержит 4 расширения для разных стейджей
String config = IOUtils.resourceToString(
"jobConfiguration.json",
StandardCharsets.UTF_8,
this.getClass().getClassLoader()
);
JobConfiguration jobConfiguration = ConfigurationReader.create(config);
LoadExtensions loadExtensions = new LoadExtensions(jobConfiguration, "yaxunit");

// when
LoadExtensions loadExtensions = new LoadExtensions(jobConfiguration);
loadExtensions.run();

// then
assertThat(loadExtensions.getExtensionsFiltered().length).isEqualTo(1);
InitInfoBaseOptions.Extension[] extensions = loadExtensions.getExtensionsFiltered();
assertThat(extensions.length).isEqualTo(2);
assertThat(extensions[0].getName()).isEqualTo("mods");
assertThat(extensions[1].getName()).isEqualTo("mods2");

// when
LoadExtensions loadExtensionsWithStage = new LoadExtensions(jobConfiguration, "yaxunit");
loadExtensionsWithStage.run();

// then
extensions = loadExtensionsWithStage.getExtensionsFiltered();
assertThat(extensions.length).isEqualTo(1);
assertThat(extensions[0].getName()).isEqualTo("YAXUnit");
}
}
}
11 changes: 11 additions & 0 deletions test/unit/resources/jobConfiguration.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
"initMethod": "fromSource",
"path": "./src/cfe/bdd",
"stages": ["bdd"]
},
{
"name": "mods",
"initMethod": "fromSource",
"path": "./src/cfe/mods"
},
{
"name": "mods2",
"initMethod": "fromSource",
"path": "./src/cfe/mods2",
"stages": ["initInfoBase"]
}
]
},
Expand Down

0 comments on commit 1e8a4ef

Please sign in to comment.