Search in sources :

Example 1 with ExecConfigBuilder

use of io.fabric8.kubernetes.api.model.ExecConfigBuilder in project kubernetes-client by fabric8io.

the class ConfigTest method testGetAuthenticatorCommandFromExecConfig.

@Test
void testGetAuthenticatorCommandFromExecConfig() throws IOException {
    // Given
    File commandFolder = Files.createTempDirectory("test").toFile();
    File commandFile = new File(commandFolder, "aws");
    boolean isNewFileCreated = commandFile.createNewFile();
    String systemPathValue = getTestPathValue(commandFolder);
    ExecConfig execConfig = new ExecConfigBuilder().withApiVersion("client.authentication.k8s.io/v1alpha1").addToArgs("--region", "us-west2", "eks", "get-token", "--cluster-name", "api-eks.example.com").withCommand("aws").build();
    // When
    List<String> processBuilderArgs = Config.getAuthenticatorCommandFromExecConfig(execConfig, new File("~/.kube/config"), systemPathValue);
    // Then
    assertTrue(isNewFileCreated);
    assertNotNull(processBuilderArgs);
    assertEquals(3, processBuilderArgs.size());
    assertPlatformPrefixes(processBuilderArgs);
    List<String> commandParts = Arrays.asList(processBuilderArgs.get(2).split(" "));
    assertEquals(commandFile.getAbsolutePath(), commandParts.get(0));
    assertEquals("--region", commandParts.get(1));
    assertEquals("us-west2", commandParts.get(2));
    assertEquals("eks", commandParts.get(3));
    assertEquals("get-token", commandParts.get(4));
    assertEquals("--cluster-name", commandParts.get(5));
    assertEquals("api-eks.example.com", commandParts.get(6));
}
Also used : ExecConfig(io.fabric8.kubernetes.api.model.ExecConfig) ExecConfigBuilder(io.fabric8.kubernetes.api.model.ExecConfigBuilder) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

ExecConfig (io.fabric8.kubernetes.api.model.ExecConfig)1 ExecConfigBuilder (io.fabric8.kubernetes.api.model.ExecConfigBuilder)1 File (java.io.File)1 Test (org.junit.jupiter.api.Test)1