From 1e8a4ef99ce418bab68fc76d3855f0ea48bebe3a Mon Sep 17 00:00:00 2001 From: Dima Date: Tue, 7 May 2024 13:47:47 +0300 Subject: [PATCH] fix and add more tests --- .../library/steps/LoadExtensions.groovy | 2 +- .../library/steps/LoadExtensionsTest.java | 19 ++++++++++++++++--- test/unit/resources/jobConfiguration.json | 11 +++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/ru/pulsar/jenkins/library/steps/LoadExtensions.groovy b/src/ru/pulsar/jenkins/library/steps/LoadExtensions.groovy index 2b92ffe..ced8c88 100644 --- a/src/ru/pulsar/jenkins/library/steps/LoadExtensions.groovy +++ b/src/ru/pulsar/jenkins/library/steps/LoadExtensions.groovy @@ -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() diff --git a/test/unit/groovy/ru/pulsar/jenkins/library/steps/LoadExtensionsTest.java b/test/unit/groovy/ru/pulsar/jenkins/library/steps/LoadExtensionsTest.java index 4b6bf53..d4eb127 100644 --- a/test/unit/groovy/ru/pulsar/jenkins/library/steps/LoadExtensionsTest.java +++ b/test/unit/groovy/ru/pulsar/jenkins/library/steps/LoadExtensionsTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test; 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; @@ -34,20 +35,32 @@ class LoadExtensionsTest { .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"); } } } diff --git a/test/unit/resources/jobConfiguration.json b/test/unit/resources/jobConfiguration.json index 794de67..803b75e 100644 --- a/test/unit/resources/jobConfiguration.json +++ b/test/unit/resources/jobConfiguration.json @@ -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"] } ] },