Skip to content

Commit

Permalink
coverage for ChartInstallRequest.apply()
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <jeromy@swirldslabs.com>
  • Loading branch information
jeromy-cannon committed Sep 22, 2023
1 parent 622fd31 commit d1b70f8
Showing 1 changed file with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,32 @@
package com.hedera.fullstack.helm.client.test.proxy.request.chart;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.hedera.fullstack.helm.client.execution.HelmExecutionBuilder;
import com.hedera.fullstack.helm.client.model.Chart;
import com.hedera.fullstack.helm.client.model.install.InstallChartOptions;
import com.hedera.fullstack.helm.client.proxy.request.chart.ChartInstallRequest;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class ChartInstallRequestTest {
@Mock
InstallChartOptions installChartOptionsMock;

@Mock
Chart chartMock;

@Mock
HelmExecutionBuilder helmExecutionBuilderMock;

@Test
@DisplayName("Test ChartInstallRequest Chart constructor")
void testChartInstallRequestChartConstructor() {
Expand All @@ -45,5 +62,47 @@ void testChartInstallRequestChartConstructor() {
.isNotEqualTo(InstallChartOptions.defaults());
}

// TODO: test ChartInstallRequest apply method using mock of builder to verify calls
@Test
@DisplayName("Test ChartInstallRequest apply with unqualified chart")
void testChartInstallRequestApplyUnqualifiedChart() {
final ChartInstallRequest chartInstallRequest =
new ChartInstallRequest("mocked", chartMock, installChartOptionsMock);
assertThat(chartInstallRequest).isNotNull();
assertThat(chartInstallRequest.chart()).isNotNull().isEqualTo(chartMock);
assertThat(chartInstallRequest.releaseName()).isEqualTo("mocked");
assertThat(chartInstallRequest.options()).isNotNull().isEqualTo(installChartOptionsMock);

when(installChartOptionsMock.repo()).thenReturn("mockedRepo");
when(chartMock.unqualified()).thenReturn("mockedUnqualified");
when(helmExecutionBuilderMock.positional("mocked")).thenReturn(helmExecutionBuilderMock);
when(helmExecutionBuilderMock.positional("mockedUnqualified")).thenReturn(helmExecutionBuilderMock);
chartInstallRequest.apply(helmExecutionBuilderMock);
verify(helmExecutionBuilderMock, times(1)).subcommands("install");
verify(installChartOptionsMock, times(1)).apply(helmExecutionBuilderMock);
verify(installChartOptionsMock, times(2)).repo();
verify(chartMock, times(1)).unqualified();
verify(helmExecutionBuilderMock, times(2)).positional(anyString());
}

@Test
@DisplayName("Test ChartInstallRequest apply with qualified chart")
void testChartInstallRequestApplyQualifiedChart() {
final ChartInstallRequest chartInstallRequest =
new ChartInstallRequest("mocked", chartMock, installChartOptionsMock);
assertThat(chartInstallRequest).isNotNull();
assertThat(chartInstallRequest.chart()).isNotNull().isEqualTo(chartMock);
assertThat(chartInstallRequest.releaseName()).isEqualTo("mocked");
assertThat(chartInstallRequest.options()).isNotNull().isEqualTo(installChartOptionsMock);

when(installChartOptionsMock.repo()).thenReturn(null);
when(chartMock.qualified()).thenReturn("mockedQualified");
when(helmExecutionBuilderMock.positional("mocked")).thenReturn(helmExecutionBuilderMock);
when(helmExecutionBuilderMock.positional("mockedQualified")).thenReturn(helmExecutionBuilderMock);
chartInstallRequest.apply(helmExecutionBuilderMock);
verify(helmExecutionBuilderMock, times(1)).subcommands("install");
verify(installChartOptionsMock, times(1)).apply(helmExecutionBuilderMock);
verify(installChartOptionsMock, times(1)).repo();
verify(chartMock, times(1)).qualified();
verify(helmExecutionBuilderMock, times(2)).positional(anyString());
}
}

0 comments on commit d1b70f8

Please sign in to comment.