Hithomelabs/CFTunnels#88: address PR review - fix test expectations, import, and assertions

This commit is contained in:
hitanshu310 2026-07-06 23:49:12 +05:30
parent 07b70e633d
commit da2db99755
3 changed files with 9 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package com.hithomelabs.common.portainer.client;
import com.hithomelabs.common.portainer.client.exception.PortainerAuthenticationException; import com.hithomelabs.common.portainer.client.exception.PortainerAuthenticationException;
import com.hithomelabs.common.portainer.client.exception.PortainerConnectionException; import com.hithomelabs.common.portainer.client.exception.PortainerConnectionException;
import com.hithomelabs.common.portainer.client.exception.PortainerDeploymentException;
import com.hithomelabs.common.portainer.client.exception.PortainerResourceNotFoundException; import com.hithomelabs.common.portainer.client.exception.PortainerResourceNotFoundException;
import com.hithomelabs.common.portainer.model.EnvVariable; import com.hithomelabs.common.portainer.model.EnvVariable;
import com.hithomelabs.common.portainer.model.PortainerAuthRequest; import com.hithomelabs.common.portainer.model.PortainerAuthRequest;
@ -254,7 +255,7 @@ class PortainerApiClientTest {
@Test @Test
void getStack_nullId_throwsException() { void getStack_nullId_throwsException() {
assertThrows(com.hithomelabs.common.portainer.client.exception.PortainerDeploymentException.class, assertThrows(PortainerDeploymentException.class,
() -> client.getStack(null)); () -> client.getStack(null));
verifyNoInteractions(restTemplate); verifyNoInteractions(restTemplate);
} }
@ -417,14 +418,14 @@ class PortainerApiClientTest {
@Test @Test
void redeployGitStack_nullId_throwsException() { void redeployGitStack_nullId_throwsException() {
assertThrows(com.hithomelabs.common.portainer.client.exception.PortainerDeploymentException.class, assertThrows(PortainerDeploymentException.class,
() -> client.redeployGitStack(null, 2L, true, null)); () -> client.redeployGitStack(null, 2L, true, null));
verifyNoInteractions(restTemplate); verifyNoInteractions(restTemplate);
} }
@Test @Test
void redeployGitStack_nullEndpointId_throwsException() { void redeployGitStack_nullEndpointId_throwsException() {
assertThrows(com.hithomelabs.common.portainer.client.exception.PortainerDeploymentException.class, assertThrows(PortainerDeploymentException.class,
() -> client.redeployGitStack(1L, null, true, null)); () -> client.redeployGitStack(1L, null, true, null));
verifyNoInteractions(restTemplate); verifyNoInteractions(restTemplate);
} }
@ -498,7 +499,7 @@ class PortainerApiClientTest {
anyLong())) anyLong()))
.thenReturn(responseEntity); .thenReturn(responseEntity);
assertThrows(com.hithomelabs.common.portainer.client.exception.PortainerDeploymentException.class, assertThrows(PortainerDeploymentException.class,
() -> client.redeployGitStack(1L, 2L, true, null)); () -> client.redeployGitStack(1L, 2L, true, null));
} }
} }

View File

@ -29,14 +29,14 @@ class EnvVariableTest {
void nullName() throws JsonProcessingException { void nullName() throws JsonProcessingException {
EnvVariable env = new EnvVariable(null, "value"); EnvVariable env = new EnvVariable(null, "value");
String json = mapper.writeValueAsString(env); String json = mapper.writeValueAsString(env);
assertTrue(json.contains("\"value\":\"value\"")); assertEquals("{\"name\":null,\"value\":\"value\"}", json);
} }
@Test @Test
void nullValue() throws JsonProcessingException { void nullValue() throws JsonProcessingException {
EnvVariable env = new EnvVariable("name", null); EnvVariable env = new EnvVariable("name", null);
String json = mapper.writeValueAsString(env); String json = mapper.writeValueAsString(env);
assertTrue(json.contains("\"name\":\"name\"")); assertEquals("{\"name\":\"name\",\"value\":null}", json);
} }
@Test @Test

View File

@ -61,8 +61,8 @@ class DeployServiceTest {
deployService.redeploy(STACK_ID); deployService.redeploy(STACK_ID);
verify(portainerApiClient).getStack(STACK_ID); verify(portainerApiClient).getStack(STACK_ID);
// When getEnv() returns null, null is passed to redeployGitStack no NPE // When getEnv() returns null, an empty list is passed to redeployGitStack
verify(portainerApiClient).redeployGitStack(STACK_ID, ENDPOINT_ID, true, null); verify(portainerApiClient).redeployGitStack(STACK_ID, ENDPOINT_ID, true, List.of());
} }
@Test @Test