Skip to content

Commit

Permalink
🧪 k8s: Add test unit for OsCluster#fromKubeConfig.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vignaudo committed Jul 9, 2024
1 parent f82b8b3 commit 56bf553
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
package com.ubiqube.etsi.mano.vim.k8s;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
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 @@ -171,6 +173,32 @@ void testBadGetClusterInfo() {
assertTrue(res.isEmpty());
}

@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);
}
}

@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);
}
}

private static String toBase64(final String r) {
return Base64.getEncoder().encodeToString(r.getBytes());
}
Expand Down

0 comments on commit 56bf553

Please sign in to comment.