Skip to content

Commit

Permalink
🧪 k8s: Add test unit for OsCluster#apply.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vignaudo committed Jul 9, 2024
1 parent 56bf553 commit a5d13e9
Showing 1 changed file with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;
Expand Down Expand Up @@ -176,27 +175,31 @@ void testBadGetClusterInfo() {
@Test
void testFromKubeConfigBad() {
final OsClusterService srv = createService();
try (InputStream is = getClass().getResourceAsStream("/kubeConfig");
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
is.transferTo(baos);
final byte[] arr = baos.toByteArray();
assertThrows(VimException.class, () -> srv.fromKubeConfig("badCtx", arr));
} catch (final IOException e) {
throw new VimException(e);
}
final byte[] arr = load("/kubeConfig").getBytes();
assertThrows(VimException.class, () -> srv.fromKubeConfig("badCtx", arr));
}

@Test
void testFromKubeConfigGood() {
final OsClusterService srv = createService();
try (InputStream is = getClass().getResourceAsStream("/kubeConfig");
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
is.transferTo(baos);
final K8s res = srv.fromKubeConfig("capi-quickstart-admin@capi-quickstart", baos.toByteArray());
assertNotNull(res);
} catch (final IOException e) {
throw new VimException(e);
}
final byte[] arr = load("/kubeConfig").getBytes();
final K8s res = srv.fromKubeConfig("capi-quickstart-admin@capi-quickstart", arr);
assertNotNull(res);
}

@Test
void testApplySingle() {
final OsClusterService srv = createService();
srv.apply(k8sConfigMock, load("/capi/quickstart.yaml"));
assertTrue(true);
}

@Test
void testApplyMulti() {
final OsClusterService srv = createService();
final String qs = load("/capi/quickstart.yaml");
srv.apply(k8sConfigMock, List.of(qs, qs));
assertTrue(true);
}

private static String toBase64(final String r) {
Expand Down

0 comments on commit a5d13e9

Please sign in to comment.