Skip to content

Commit

Permalink
test(helm): add new tests to verify push/pull config when init HelmPu…
Browse files Browse the repository at this point in the history
…shMojo

Signed-off-by: arman-yekkehkhani <[email protected]>
  • Loading branch information
arman-yekkehkhani authored Jun 17, 2024
1 parent be1f6e1 commit cf73bdc
Showing 1 changed file with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.nio.file.Path;
import java.util.HashMap;

import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.eclipse.jkube.kit.common.RegistryServerConfiguration;
import org.eclipse.jkube.kit.resource.helm.BadUploadException;
Expand Down Expand Up @@ -80,6 +81,34 @@ void tearDown() {
helmPushMojo = null;
}

@Test
void init_withValidServer_shouldSetPullRegistry() throws MojoFailureException {
// Given
helmPushMojo.settings.addServer(completeValidServer());

// When
helmPushMojo.init();

// Then
assertThat(helmPushMojo.jkubeServiceHub.getConfiguration().getPullRegistryConfig().getSettings()).singleElement()
.isEqualTo(RegistryServerConfiguration.builder()
.id("SNAP-REPO").username("mavenUser").password("mavenPassword").configuration(new HashMap<>()).build());
}

@Test
void init_withValidServer_shouldSetPushRegistry() throws MojoFailureException {
// Given
helmPushMojo.settings.addServer(completeValidServer());

// When
helmPushMojo.init();

// Then
assertThat(helmPushMojo.jkubeServiceHub.getConfiguration().getPushRegistryConfig().getSettings()).singleElement()
.isEqualTo(RegistryServerConfiguration.builder()
.id("SNAP-REPO").username("mavenUser").password("mavenPassword").configuration(new HashMap<>()).build());
}

@Test
void execute_withValidXMLConfig_shouldUpload() throws Exception {
try (MockedConstruction<HelmService> helmServiceMockedConstruction = mockConstruction(HelmService.class)) {
Expand Down Expand Up @@ -166,12 +195,6 @@ void execute_withValidMavenSettings_shouldUpload() throws Exception {
// When
helmPushMojo.execute();
// Then
assertThat(helmPushMojo.jkubeServiceHub.getConfiguration().getPullRegistryConfig().getSettings()).singleElement()
.isEqualTo(RegistryServerConfiguration.builder()
.id("SNAP-REPO").username("mavenUser").password("mavenPassword").configuration(new HashMap<>()).build());
assertThat(helmPushMojo.jkubeServiceHub.getConfiguration().getPushRegistryConfig().getSettings()).singleElement()
.isEqualTo(RegistryServerConfiguration.builder()
.id("SNAP-REPO").username("mavenUser").password("mavenPassword").configuration(new HashMap<>()).build());
assertThat(helmServiceMockedConstruction.constructed()).hasSize(1);
verify(helmServiceMockedConstruction.constructed().get(0), times(1)).uploadHelmChart(helmPushMojo.helm);
}
Expand Down

0 comments on commit cf73bdc

Please sign in to comment.