Search in sources :

Example 11 with Input

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input in project intellij-tekton by redhat-developer.

the class TknCliTest method checkRightArgsWhenStartingClusterTaskWithMultipleInputs.

@Test
public void checkRightArgsWhenStartingClusterTaskWithMultipleInputs() throws IOException {
    Map<String, Input> params = new HashMap<>();
    params.put("param1", new Input("param1", "string", Input.Kind.PARAMETER, "value1", Optional.empty(), Optional.empty()));
    Map<String, String> inputResources = new HashMap<>();
    inputResources.put("res1", "value1");
    inputResources.put("res2", "value2");
    Map<String, String> outputResources = new HashMap<>();
    outputResources.put("out1", "value1");
    Map<String, Workspace> workspaces = new HashMap<>();
    workspaces.put("work1", new Workspace("work1", Workspace.Kind.PVC, "value1"));
    workspaces.put("work2", new Workspace("work2", Workspace.Kind.SECRET, "value2"));
    MockedStatic<ExecHelper> exec = mockStatic(ExecHelper.class);
    exec.when(() -> ExecHelper.execute(anyString(), anyMap(), any())).thenReturn("");
    tkn.startClusterTask("ns", "name", params, inputResources, outputResources, "sa", workspaces, "prefix");
    exec.verify(() -> ExecHelper.execute(anyString(), anyMap(), eq("clustertask"), eq("start"), eq("name"), eq("-n"), eq("ns"), eq("-s=sa"), eq("-w"), eq("name=work2,secret=value2"), eq("-w"), eq("name=work1,claimName=value1"), eq("-p"), eq("param1=value1"), eq("-i"), eq("res1=value1"), eq("-i"), eq("res2=value2"), eq("-o"), eq("out1=value1"), eq("--prefix-name=prefix"), eq(FLAG_SKIP_OPTIONAL_WORKSPACES)));
    exec.close();
}
Also used : ExecHelper(com.redhat.devtools.intellij.common.utils.ExecHelper) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) Test(org.junit.Test)

Example 12 with Input

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input in project intellij-tekton by redhat-developer.

the class TknCliTest method checkRightArgsWhenStartingTaskWithParameters.

@Test
public void checkRightArgsWhenStartingTaskWithParameters() throws IOException {
    Map<String, Input> params = new HashMap<>();
    params.put("param1", new Input("param1", "string", Input.Kind.PARAMETER, "value1", Optional.empty(), Optional.empty()));
    params.put("param2", new Input("param2", "string", Input.Kind.PARAMETER, "value2", Optional.empty(), Optional.empty()));
    MockedStatic<ExecHelper> exec = mockStatic(ExecHelper.class);
    exec.when(() -> ExecHelper.execute(anyString(), anyMap(), any())).thenReturn("");
    tkn.startTask("ns", "name", params, Collections.emptyMap(), Collections.emptyMap(), "", Collections.emptyMap(), "");
    exec.verify(() -> ExecHelper.execute(anyString(), anyMap(), eq("task"), eq("start"), eq("name"), eq("-n"), eq("ns"), eq("-p"), eq("param1=value1"), eq("-p"), eq("param2=value2"), eq(FLAG_SKIP_OPTIONAL_WORKSPACES)));
    exec.close();
}
Also used : ExecHelper(com.redhat.devtools.intellij.common.utils.ExecHelper) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 13 with Input

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input in project intellij-tekton by redhat-developer.

the class TknCliPipelineTest method verifyStartPipelineCreateRuns.

@Test
public void verifyStartPipelineCreateRuns() throws IOException, InterruptedException, TimeoutException, ExecutionException {
    String TASK_NAME = "add-task";
    String PIPELINE_NAME = "sum-three-pipeline";
    String taskConfig = TestUtils.load("start/add-task.yaml");
    String pipelineConfig = TestUtils.load("start/sum-pipeline.yaml");
    TestUtils.saveResource(tkn, taskConfig, NAMESPACE, "tasks");
    TestUtils.saveResource(tkn, pipelineConfig, NAMESPACE, "pipelines");
    // verify task has been created
    List<String> tasks = tkn.getTasks(NAMESPACE).stream().map(task -> task.getMetadata().getName()).collect(Collectors.toList());
    assertTrue(tasks.contains(TASK_NAME));
    // verify pipeline has been created
    List<String> pipelines = tkn.getPipelines(NAMESPACE).stream().map(pp -> pp.getMetadata().getName()).collect(Collectors.toList());
    ;
    assertTrue(pipelines.contains(PIPELINE_NAME));
    // start pipeline and verify taskrun and pipelinerun has been created
    Map<String, Input> params = new HashMap<>();
    params.put("first", new Input("name", "string", Input.Kind.PARAMETER, "value", Optional.empty(), Optional.empty()));
    params.put("second", new Input("name2", "string", Input.Kind.PARAMETER, "value2", Optional.empty(), Optional.empty()));
    params.put("third", new Input("name3", "string", Input.Kind.PARAMETER, "value3", Optional.empty(), Optional.empty()));
    tkn.startPipeline(NAMESPACE, PIPELINE_NAME, params, Collections.emptyMap(), "", Collections.emptyMap(), Collections.emptyMap(), "");
    final String[] namePipelineRun = { "" };
    Watch watch = tkn.getClient(TektonClient.class).v1beta1().pipelineRuns().inNamespace(NAMESPACE).withLabel("tekton.dev/pipeline", PIPELINE_NAME).watch(createWatcher((resource) -> {
        namePipelineRun[0] = resource.getMetadata().getName();
    }));
    stopAndWaitOnConditionOrTimeout(watch, () -> namePipelineRun[0].isEmpty());
    assertFalse(namePipelineRun[0].isEmpty());
    try {
        // pipelinerun may have already finished its execution
        tkn.cancelPipelineRun(NAMESPACE, namePipelineRun[0]);
    } catch (IOException ignored) {
    }
    // clean up
    tkn.deletePipelines(NAMESPACE, Arrays.asList(PIPELINE_NAME), true);
    tkn.deleteTasks(NAMESPACE, Arrays.asList(TASK_NAME), false);
}
Also used : Arrays(java.util.Arrays) Watcher(io.fabric8.kubernetes.client.Watcher) TimeoutException(java.util.concurrent.TimeoutException) Assert.assertTrue(org.junit.Assert.assertTrue) Watch(io.fabric8.kubernetes.client.Watch) IOException(java.io.IOException) HashMap(java.util.HashMap) Test(org.junit.Test) TestUtils(com.redhat.devtools.intellij.tektoncd.TestUtils) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) WatcherException(io.fabric8.kubernetes.client.WatcherException) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) Optional(java.util.Optional) TektonClient(io.fabric8.tekton.client.TektonClient) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) PipelineRun(io.fabric8.tekton.pipeline.v1beta1.PipelineRun) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) HashMap(java.util.HashMap) TektonClient(io.fabric8.tekton.client.TektonClient) Watch(io.fabric8.kubernetes.client.Watch) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Input (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input)13 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 ExecHelper (com.redhat.devtools.intellij.common.utils.ExecHelper)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 Workspace (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)3 List (java.util.List)3 Map (java.util.Map)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 TestUtils (com.redhat.devtools.intellij.tektoncd.TestUtils)2 Resource (com.redhat.devtools.intellij.tektoncd.tkn.Resource)2 BORDER_LABEL_NAME (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.BORDER_LABEL_NAME)2 ROW_DIMENSION (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION)2 TIMES_PLAIN_14 (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_14)2 ActionToRunModel (com.redhat.devtools.intellij.tektoncd.utils.model.actions.ActionToRunModel)2 Watch (io.fabric8.kubernetes.client.Watch)2 Watcher (io.fabric8.kubernetes.client.Watcher)2 WatcherException (io.fabric8.kubernetes.client.WatcherException)2 TektonClient (io.fabric8.tekton.client.TektonClient)2