Search in sources :

Example 11 with Workspace

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

the class RunConfigurationModel method getWorkspaces.

private Map<String, Workspace> getWorkspaces(String configuration) {
    Map<String, Workspace> workspaces = new HashMap<>();
    try {
        JsonNode workspacesNode = YAMLHelper.getValueFromYAML(configuration, new String[] { "spec", "workspaces" });
        if (workspacesNode != null) {
            for (JsonNode workspaceNode : workspacesNode) {
                if (!workspaceNode.has("name"))
                    continue;
                String name = workspaceNode.get("name").asText();
                Workspace.Kind kind = workspaceNode.has(KIND_PVC) || workspaceNode.has(KIND_VCT) ? Workspace.Kind.PVC : workspaceNode.has(KIND_CONFIGMAP) ? Workspace.Kind.CONFIGMAP : workspaceNode.has(KIND_SECRET) ? Workspace.Kind.SECRET : Workspace.Kind.EMPTYDIR;
                String resource = kind.equals(Workspace.Kind.PVC) ? workspaceNode.has("persistentVolumeClaim") ? workspaceNode.get("persistentVolumeClaim").get("claimName").asText() : "" : kind.equals(Workspace.Kind.CONFIGMAP) ? workspaceNode.get(KIND_CONFIGMAP).get("name").asText() : kind.equals(Workspace.Kind.SECRET) ? workspaceNode.get(KIND_SECRET).get("secretName").asText() : "";
                Map<String, String> values = extractValuesFromVCTNode(workspaceNode);
                boolean optional = workspaceNode.has("optional") && workspaceNode.get("optional").asBoolean(false);
                workspaces.put(name, new Workspace(name, kind, resource, values, optional));
            }
        }
    } catch (IOException e) {
        logger.warn(e.getLocalizedMessage(), e);
    }
    return workspaces;
}
Also used : HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)

Example 12 with Workspace

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

the class TknCliTest method checkRightArgsWhenStartingPipelineWithMultipleInputs.

@Test
public void checkRightArgsWhenStartingPipelineWithMultipleInputs() 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> resources = new HashMap<>();
    resources.put("res1", "value1");
    resources.put("res2", "value2");
    Map<String, String> taskServiceAccount = new HashMap<>();
    taskServiceAccount.put("task1", "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.startPipeline("ns", "name", params, resources, "sa", taskServiceAccount, workspaces, "prefix");
    exec.verify(() -> ExecHelper.execute(anyString(), anyMap(), eq("pipeline"), eq("start"), eq("name"), eq("-n"), eq("ns"), eq("-s=sa"), eq("--task-serviceaccount"), eq("task1=value1"), eq("-w"), eq("name=work2,secret=value2"), eq("-w"), eq("name=work1,claimName=value1"), eq("-p"), eq("param1=value1"), eq("-r"), eq("res1=value1"), eq("-r"), eq("res2=value2"), 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 13 with Workspace

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

the class TknCliTest method checkRightArgsWhenStartingClusterTaskWithWorkspaces.

@Test
public void checkRightArgsWhenStartingClusterTaskWithWorkspaces() throws IOException {
    Map<String, Workspace> workspaces = new HashMap<>();
    workspaces.put("work1", new Workspace("work1", Workspace.Kind.PVC, "value1"));
    workspaces.put("work2", new Workspace("work2", Workspace.Kind.CONFIGMAP, "value2"));
    workspaces.put("work3", new Workspace("work3", Workspace.Kind.SECRET, "value3"));
    workspaces.put("work4", new Workspace("work4", Workspace.Kind.EMPTYDIR, null));
    MockedStatic<ExecHelper> exec = mockStatic(ExecHelper.class);
    exec.when(() -> ExecHelper.execute(anyString(), anyMap(), any())).thenReturn("");
    tkn.startClusterTask("ns", "name", Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), "", workspaces, "");
    exec.verify(() -> ExecHelper.execute(anyString(), anyMap(), eq("clustertask"), eq("start"), eq("name"), eq("-n"), eq("ns"), eq("-w"), eq("name=work2,config=value2"), eq("-w"), eq("name=work1,claimName=value1"), eq("-w"), eq("name=work4,emptyDir="), eq("-w"), eq("name=work3,secret=value3"), eq(FLAG_SKIP_OPTIONAL_WORKSPACES)));
    exec.close();
}
Also used : ExecHelper(com.redhat.devtools.intellij.common.utils.ExecHelper) 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 14 with Workspace

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

the class TknCliTest method checkRightArgsWhenStartingPipelineWithWorkspaces.

@Test
public void checkRightArgsWhenStartingPipelineWithWorkspaces() throws IOException {
    Map<String, Workspace> workspaces = new HashMap<>();
    workspaces.put("work1", new Workspace("work1", Workspace.Kind.PVC, "value1"));
    workspaces.put("work2", new Workspace("work2", Workspace.Kind.CONFIGMAP, "value2"));
    workspaces.put("work3", new Workspace("work3", Workspace.Kind.SECRET, "value3"));
    workspaces.put("work4", new Workspace("work4", Workspace.Kind.EMPTYDIR, null));
    MockedStatic<ExecHelper> exec = mockStatic(ExecHelper.class);
    exec.when(() -> ExecHelper.execute(anyString(), anyMap(), any())).thenReturn("");
    tkn.startPipeline("ns", "name", Collections.emptyMap(), Collections.emptyMap(), "", Collections.emptyMap(), workspaces, "");
    exec.verify(() -> ExecHelper.execute(anyString(), anyMap(), eq("pipeline"), eq("start"), eq("name"), eq("-n"), eq("ns"), eq("-w"), eq("name=work2,config=value2"), eq("-w"), eq("name=work1,claimName=value1"), eq("-w"), eq("name=work4,emptyDir="), eq("-w"), eq("name=work3,secret=value3"), eq(FLAG_SKIP_OPTIONAL_WORKSPACES)));
    exec.close();
}
Also used : ExecHelper(com.redhat.devtools.intellij.common.utils.ExecHelper) 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 15 with Workspace

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

the class TknCliTest method checkRightArgsWhenStartingTaskWithMultipleInputs.

@Test
public void checkRightArgsWhenStartingTaskWithMultipleInputs() 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.startTask("ns", "name", params, inputResources, outputResources, "sa", workspaces, "prefix");
    exec.verify(() -> ExecHelper.execute(anyString(), anyMap(), eq("task"), 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)

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