Search in sources :

Example 16 with Workspace

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace 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 17 with Workspace

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

the class YAMLBuilderTest method checkTaskRunCreatedHasWorkspace.

@Test
public void checkTaskRunCreatedHasWorkspace() throws IOException {
    String content = load("task10.yaml");
    AddTriggerModel model = new AddTriggerModel(content, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyMap());
    if (model.getWorkspaces().containsKey("write-allowed")) {
        model.getWorkspaces().put("write-allowed", new Workspace("foo1", Workspace.Kind.EMPTYDIR, "foo"));
    }
    if (model.getWorkspaces().containsKey("write-disallowed")) {
        model.getWorkspaces().put("write-disallowed", new Workspace("foo2", Workspace.Kind.EMPTYDIR, "foo"));
    }
    ObjectNode taskRunNode = YAMLBuilder.createTaskRun(model);
    assertEquals(taskRunNode.get("apiVersion").asText(), "tekton.dev/v1beta1");
    assertEquals(taskRunNode.get("kind").asText(), "TaskRun");
    assertEquals(taskRunNode.get("metadata").get("generateName").asText(), "foo-");
    assertEquals(taskRunNode.get("spec").get("taskRef").get("name").asText(), "foo");
    assertFalse(taskRunNode.get("spec").has("serviceAccountName"));
    assertFalse(taskRunNode.get("spec").has("serviceAccountNames"));
    assertFalse(taskRunNode.get("spec").has("params"));
    assertFalse(taskRunNode.get("spec").has("resources"));
    assertTrue(taskRunNode.get("spec").has("workspaces"));
    assertEquals(taskRunNode.get("spec").get("workspaces").get(0).get("name").asText(), "foo1");
    assertEquals(taskRunNode.get("spec").get("workspaces").get(1).get("name").asText(), "foo2");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AddTriggerModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) Test(org.junit.Test) BaseTest(com.redhat.devtools.intellij.tektoncd.BaseTest)

Example 18 with Workspace

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

the class YAMLBuilderTest method checkPipelineRunCreatedHasWorkspace.

@Test
public void checkPipelineRunCreatedHasWorkspace() throws IOException {
    String content = load("pipeline5.yaml");
    AddTriggerModel model = new AddTriggerModel(content, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyMap());
    if (model.getWorkspaces().containsKey("password-vault")) {
        model.getWorkspaces().put("password-vault", new Workspace("foo1", Workspace.Kind.EMPTYDIR, "foo"));
    }
    if (model.getWorkspaces().containsKey("recipe-store")) {
        model.getWorkspaces().put("recipe-store", new Workspace("foo2", Workspace.Kind.EMPTYDIR, "foo"));
    }
    ObjectNode pipelineRunNode = YAMLBuilder.createPipelineRun(model);
    assertEquals(pipelineRunNode.get("apiVersion").asText(), "tekton.dev/v1beta1");
    assertEquals(pipelineRunNode.get("kind").asText(), "PipelineRun");
    assertEquals(pipelineRunNode.get("metadata").get("generateName").asText(), "foo-");
    assertEquals(pipelineRunNode.get("spec").get("pipelineRef").get("name").asText(), "foo");
    assertFalse(pipelineRunNode.get("spec").has("serviceAccountName"));
    assertFalse(pipelineRunNode.get("spec").has("serviceAccountNames"));
    assertFalse(pipelineRunNode.get("spec").has("params"));
    assertFalse(pipelineRunNode.get("spec").has("resources"));
    assertTrue(pipelineRunNode.get("spec").has("workspaces"));
    assertEquals(pipelineRunNode.get("spec").get("workspaces").get(0).get("name").asText(), "foo1");
    assertEquals(pipelineRunNode.get("spec").get("workspaces").get(1).get("name").asText(), "foo2");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AddTriggerModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) Test(org.junit.Test) BaseTest(com.redhat.devtools.intellij.tektoncd.BaseTest)

Example 19 with Workspace

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

the class TektonAction method createNewVolumes.

protected void createNewVolumes(Map<String, Workspace> workspaces, Tkn tkn) throws IOException {
    int counter = 0;
    for (Map.Entry<String, Workspace> entry : workspaces.entrySet()) {
        Workspace workspace = entry.getValue();
        if (workspace != null && workspace.getKind() == Workspace.Kind.PVC && workspace.getResource().isEmpty() && workspace.getItems().size() > 0) {
            if (KIND_VCT.equals(workspace.getItems().get("type"))) {
                VirtualFile vf = createVCT(workspace.getItems(), counter);
                workspace.getItems().put("file", vf.getPath());
                counter++;
            } else {
                String name = createNewPVC(workspace.getItems(), tkn);
                workspace.setResource(name);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Map(java.util.Map) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)

Aggregations

Workspace (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)19 HashMap (java.util.HashMap)11 Test (org.junit.Test)7 ExecHelper (com.redhat.devtools.intellij.common.utils.ExecHelper)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 Pair (com.intellij.openapi.util.Pair)4 DocumentAdapter (com.intellij.ui.DocumentAdapter)4 KIND_VCT (com.redhat.devtools.intellij.tektoncd.Constants.KIND_VCT)4 GridBagConstraints (java.awt.GridBagConstraints)4 GridBagLayout (java.awt.GridBagLayout)4 JComboBox (javax.swing.JComboBox)4 Strings (com.google.common.base.Strings)3 ColorKey (com.intellij.openapi.editor.colors.ColorKey)3 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)3 ComboBox (com.intellij.openapi.ui.ComboBox)3 Input (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input)3 CONFIGMAP (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.CONFIGMAP)3