From 9e3be94099bfb82926df6b2ce17f17ca32ada09a Mon Sep 17 00:00:00 2001 From: Daniel Helfand Date: Sat, 25 Apr 2020 15:26:11 -0400 Subject: [PATCH] fix --dry-run with --filename tests for all start commands --- pkg/cmd/clustertask/start_test.go | 16 --- pkg/cmd/pipeline/start_test.go | 24 +--- ...ry_Run_with_output=json_-f_v1alpha1.golden | 101 +++++++++++++++ ...nd-Dry_Run_using_--filename_v1beta1.golden | 53 ++++++++ ...Dry_Run_with_output=json_-f_v1beta1.golden | 101 +++++++++++++++ pkg/cmd/task/start_test.go | 21 +--- ...ry_Run_with_output=json_-f_v1alpha1.golden | 116 ++++++++++++++++++ ...Dry_Run_with_output=json_-f_v1beta1.golden | 84 +++++++++++++ 8 files changed, 462 insertions(+), 54 deletions(-) create mode 100644 pkg/cmd/pipeline/testdata/TestPipelineStart_ExecuteCommand-Dry_Run_with_output=json_-f_v1alpha1.golden create mode 100644 pkg/cmd/pipeline/testdata/TestPipelineV1beta1Start_ExecuteCommand-Dry_Run_using_--filename_v1beta1.golden create mode 100644 pkg/cmd/pipeline/testdata/TestPipelineV1beta1Start_ExecuteCommand-Dry_Run_with_output=json_-f_v1beta1.golden create mode 100644 pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_output=json_-f_v1alpha1.golden create mode 100644 pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand_v1beta1-Dry_Run_with_output=json_-f_v1beta1.golden diff --git a/pkg/cmd/clustertask/start_test.go b/pkg/cmd/clustertask/start_test.go index aefad84aa..1b7d846e8 100644 --- a/pkg/cmd/clustertask/start_test.go +++ b/pkg/cmd/clustertask/start_test.go @@ -925,22 +925,6 @@ func Test_ClusterTask_Start_v1beta1(t *testing.T) { wantError: false, goldenFile: true, }, - { - name: "Dry run with output=json", - command: []string{"start", "clustertask-2", - "-i", "my-repo=git", - "-o", "code-image=output-image", - "-l", "key=value", - "-s=svc1", - "--dry-run", - "--output=json", - }, - dynamic: seeds[3].dynamicClient, - input: seeds[3].pipelineClient, - inputStream: nil, - wantError: false, - goldenFile: true, - }, { name: "Dry run with no output v1beta1", command: []string{"start", "clustertask-2", diff --git a/pkg/cmd/pipeline/start_test.go b/pkg/cmd/pipeline/start_test.go index d4199361c..221f752f2 100644 --- a/pkg/cmd/pipeline/start_test.go +++ b/pkg/cmd/pipeline/start_test.go @@ -593,7 +593,7 @@ func TestPipelineStart_ExecuteCommand(t *testing.T) { goldenFile: true, }, { - name: "Dry Run using --filename", + name: "Dry Run using --filename v1alpha1", command: []string{"start", "-f", "./testdata/pipeline-v1alpha1.yaml", "-r=source-repo=scaffold-git", "-r=web-image=imageres", @@ -606,7 +606,7 @@ func TestPipelineStart_ExecuteCommand(t *testing.T) { goldenFile: true, }, { - name: "Dry Run with output=json -f", + name: "Dry Run with output=json -f v1alpha1", command: []string{"start", "-f", "./testdata/pipeline-v1alpha1.yaml", "-r=source-repo=scaffold-git", "-r=web-image=imageres", @@ -1209,23 +1209,7 @@ func TestPipelineV1beta1Start_ExecuteCommand(t *testing.T) { want: "cannot use --last or --use-pipelinerun options with --use-param-defaults option", }, { - name: "Dry Run with output=json", - command: []string{"start", "test-pipeline", - "-s=svc1", - "-r=source=scaffold-git", - "-p=pipeline-param=value1", - "-l=jemange=desfrites", - "-n", "ns", - "--dry-run", - "--output", "json", - }, - namespace: "", - input: c2, - wantError: false, - goldenFile: true, - }, - { - name: "Dry Run using --filename", + name: "Dry Run using --filename v1beta1", command: []string{"start", "-f", "./testdata/pipeline-v1beta1.yaml", "-r=source-repo=scaffold-git", "-r=web-image=imageres", @@ -1238,7 +1222,7 @@ func TestPipelineV1beta1Start_ExecuteCommand(t *testing.T) { goldenFile: true, }, { - name: "Dry Run with output=json -f", + name: "Dry Run with output=json -f v1beta1", command: []string{"start", "-f", "./testdata/pipeline-v1beta1.yaml", "-r=source-repo=scaffold-git", "-r=web-image=imageres", diff --git a/pkg/cmd/pipeline/testdata/TestPipelineStart_ExecuteCommand-Dry_Run_with_output=json_-f_v1alpha1.golden b/pkg/cmd/pipeline/testdata/TestPipelineStart_ExecuteCommand-Dry_Run_with_output=json_-f_v1alpha1.golden new file mode 100644 index 000000000..d1303e5ea --- /dev/null +++ b/pkg/cmd/pipeline/testdata/TestPipelineStart_ExecuteCommand-Dry_Run_with_output=json_-f_v1alpha1.golden @@ -0,0 +1,101 @@ +{ + "kind": "PipelineRun", + "apiVersion": "tekton.dev/v1alpha1", + "metadata": { + "generateName": "test-pipeline-run-", + "namespace": "ns", + "creationTimestamp": null + }, + "spec": { + "pipelineSpec": { + "resources": [ + { + "name": "source-repo", + "type": "git" + }, + { + "name": "web-image", + "type": "image" + } + ], + "tasks": [ + { + "name": "build-skaffold-web", + "taskRef": { + "name": "build-docker-image-from-git-source" + }, + "resources": { + "inputs": [ + { + "name": "docker-source", + "resource": "source-repo" + } + ], + "outputs": [ + { + "name": "builtImage", + "resource": "web-image" + } + ] + }, + "params": [ + { + "name": "pathToDockerFile", + "value": "Dockerfile" + }, + { + "name": "pathToContext", + "value": "/workspace/docker-source/examples/microservices/leeroy-web" + } + ] + }, + { + "name": "deploy-web", + "taskRef": { + "name": "deploy-using-kubectl" + }, + "resources": { + "inputs": [ + { + "name": "source", + "resource": "source-repo" + }, + { + "name": "image", + "resource": "web-image", + "from": [ + "build-skaffold-web" + ] + } + ] + }, + "params": [ + { + "name": "path", + "value": "/workspace/source/examples/microservices/leeroy-web/kubernetes/deployment.yaml" + }, + { + "name": "yamlPathToImage", + "value": "spec.template.spec.containers[0].image" + } + ] + } + ] + }, + "resources": [ + { + "name": "source-repo", + "resourceRef": { + "name": "scaffold-git" + } + }, + { + "name": "web-image", + "resourceRef": { + "name": "imageres" + } + } + ] + }, + "status": {} +} diff --git a/pkg/cmd/pipeline/testdata/TestPipelineV1beta1Start_ExecuteCommand-Dry_Run_using_--filename_v1beta1.golden b/pkg/cmd/pipeline/testdata/TestPipelineV1beta1Start_ExecuteCommand-Dry_Run_using_--filename_v1beta1.golden new file mode 100644 index 000000000..21cb72a10 --- /dev/null +++ b/pkg/cmd/pipeline/testdata/TestPipelineV1beta1Start_ExecuteCommand-Dry_Run_using_--filename_v1beta1.golden @@ -0,0 +1,53 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + generateName: test-pipeline-run- + namespace: ns +spec: + pipelineSpec: + resources: + - name: source-repo + type: git + - name: web-image + type: image + tasks: + - name: build-skaffold-web + params: + - name: pathToDockerFile + value: Dockerfile + - name: pathToContext + value: /workspace/docker-source/examples/microservices/leeroy-web + resources: + inputs: + - name: docker-source + resource: source-repo + outputs: + - name: builtImage + resource: web-image + taskRef: + name: build-docker-image-from-git-source + - name: deploy-web + params: + - name: path + value: /workspace/source/examples/microservices/leeroy-web/kubernetes/deployment.yaml + - name: yamlPathToImage + value: spec.template.spec.containers[0].image + resources: + inputs: + - name: source + resource: source-repo + - from: + - build-skaffold-web + name: image + resource: web-image + taskRef: + name: deploy-using-kubectl + resources: + - name: source-repo + resourceRef: + name: scaffold-git + - name: web-image + resourceRef: + name: imageres +status: {} diff --git a/pkg/cmd/pipeline/testdata/TestPipelineV1beta1Start_ExecuteCommand-Dry_Run_with_output=json_-f_v1beta1.golden b/pkg/cmd/pipeline/testdata/TestPipelineV1beta1Start_ExecuteCommand-Dry_Run_with_output=json_-f_v1beta1.golden new file mode 100644 index 000000000..5b83c9057 --- /dev/null +++ b/pkg/cmd/pipeline/testdata/TestPipelineV1beta1Start_ExecuteCommand-Dry_Run_with_output=json_-f_v1beta1.golden @@ -0,0 +1,101 @@ +{ + "kind": "PipelineRun", + "apiVersion": "tekton.dev/v1beta1", + "metadata": { + "generateName": "test-pipeline-run-", + "namespace": "ns", + "creationTimestamp": null + }, + "spec": { + "pipelineSpec": { + "resources": [ + { + "name": "source-repo", + "type": "git" + }, + { + "name": "web-image", + "type": "image" + } + ], + "tasks": [ + { + "name": "build-skaffold-web", + "taskRef": { + "name": "build-docker-image-from-git-source" + }, + "resources": { + "inputs": [ + { + "name": "docker-source", + "resource": "source-repo" + } + ], + "outputs": [ + { + "name": "builtImage", + "resource": "web-image" + } + ] + }, + "params": [ + { + "name": "pathToDockerFile", + "value": "Dockerfile" + }, + { + "name": "pathToContext", + "value": "/workspace/docker-source/examples/microservices/leeroy-web" + } + ] + }, + { + "name": "deploy-web", + "taskRef": { + "name": "deploy-using-kubectl" + }, + "resources": { + "inputs": [ + { + "name": "source", + "resource": "source-repo" + }, + { + "name": "image", + "resource": "web-image", + "from": [ + "build-skaffold-web" + ] + } + ] + }, + "params": [ + { + "name": "path", + "value": "/workspace/source/examples/microservices/leeroy-web/kubernetes/deployment.yaml" + }, + { + "name": "yamlPathToImage", + "value": "spec.template.spec.containers[0].image" + } + ] + } + ] + }, + "resources": [ + { + "name": "source-repo", + "resourceRef": { + "name": "scaffold-git" + } + }, + { + "name": "web-image", + "resourceRef": { + "name": "imageres" + } + } + ] + }, + "status": {} +} diff --git a/pkg/cmd/task/start_test.go b/pkg/cmd/task/start_test.go index d7a20654e..97f377714 100644 --- a/pkg/cmd/task/start_test.go +++ b/pkg/cmd/task/start_test.go @@ -3847,7 +3847,7 @@ func TestTaskStart_ExecuteCommand(t *testing.T) { goldenFile: true, }, { - name: "Dry Run with output=json -f", + name: "Dry Run with output=json -f v1alpha1", command: []string{"start", "-f", "./testdata/task-v1alpha1.yaml", "-n", "ns", @@ -4000,21 +4000,6 @@ func TestTaskStart_ExecuteCommand_v1beta1(t *testing.T) { wantError: false, goldenFile: true, }, - { - name: "Dry Run with output=json", - command: []string{"start", "task-1", - "-i=my-repo=git-repo", - "-o=code-image=output-image", - "-s=svc1", - "-n", "ns", - "--dry-run", - "--output=json"}, - namespace: "", - dynamic: dc, - input: cs, - wantError: false, - goldenFile: true, - }, { name: "Dry Run with -f v1beta1", command: []string{"start", @@ -4047,9 +4032,9 @@ func TestTaskStart_ExecuteCommand_v1beta1(t *testing.T) { goldenFile: true, }, { - name: "Dry Run with output=json -f", + name: "Dry Run with output=json -f v1beta1", command: []string{"start", - "-f", "./testdata/task-v1alpha1.yaml", + "-f", "./testdata/task-v1beta1.yaml", "-n", "ns", "-s=svc1", "-i=docker-source=git", diff --git a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_output=json_-f_v1alpha1.golden b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_output=json_-f_v1alpha1.golden new file mode 100644 index 000000000..2433a4a75 --- /dev/null +++ b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_output=json_-f_v1alpha1.golden @@ -0,0 +1,116 @@ +{ + "kind": "TaskRun", + "apiVersion": "tekton.dev/v1alpha1", + "metadata": { + "generateName": "test-task-run-", + "namespace": "ns", + "creationTimestamp": null + }, + "spec": { + "serviceAccountName": "svc1", + "taskSpec": { + "resources": { + "inputs": [ + { + "name": "docker-source", + "type": "git" + } + ], + "outputs": [ + { + "name": "builtImage", + "type": "image" + } + ] + }, + "params": [ + { + "name": "pathToDockerFile", + "type": "string", + "description": "The path to the dockerfile to build", + "default": "/workspace/docker-source/Dockerfile" + }, + { + "name": "pathToContext", + "type": "string", + "description": "The build context used by Kaniko (https://github.com/GoogleContainerTools/kaniko#kaniko-build-contexts)", + "default": "/workspace/docker-source" + } + ], + "steps": [ + { + "name": "build-and-push", + "image": "gcr.io/kaniko-project/executor:v0.14.0", + "command": [ + "/kaniko/executor" + ], + "args": [ + "--dockerfile=$(inputs.params.pathToDockerFile)", + "--destination=$(outputs.resources.builtImage.url)", + "--context=$(inputs.params.pathToContext)" + ], + "env": [ + { + "name": "DOCKER_CONFIG", + "value": "/tekton/home/.docker/" + } + ], + "resources": {} + } + ], + "inputs": { + "resources": [ + { + "name": "docker-source", + "type": "git" + } + ], + "params": [ + { + "name": "pathToDockerFile", + "type": "string", + "description": "The path to the dockerfile to build", + "default": "/workspace/docker-source/Dockerfile" + }, + { + "name": "pathToContext", + "type": "string", + "description": "The build context used by Kaniko (https://github.com/GoogleContainerTools/kaniko#kaniko-build-contexts)", + "default": "/workspace/docker-source" + } + ] + }, + "outputs": { + "resources": [ + { + "name": "builtImage", + "type": "image" + } + ] + } + }, + "inputs": { + "resources": [ + { + "name": "docker-source", + "resourceRef": { + "name": "git" + } + } + ] + }, + "outputs": { + "resources": [ + { + "name": "builtImage", + "resourceRef": { + "name": "image" + } + } + ] + } + }, + "status": { + "podName": "" + } +} diff --git a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand_v1beta1-Dry_Run_with_output=json_-f_v1beta1.golden b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand_v1beta1-Dry_Run_with_output=json_-f_v1beta1.golden new file mode 100644 index 000000000..56c8277da --- /dev/null +++ b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand_v1beta1-Dry_Run_with_output=json_-f_v1beta1.golden @@ -0,0 +1,84 @@ +{ + "kind": "TaskRun", + "apiVersion": "tekton.dev/v1beta1", + "metadata": { + "generateName": "test-task-run-", + "namespace": "ns", + "creationTimestamp": null + }, + "spec": { + "resources": { + "inputs": [ + { + "name": "docker-source", + "resourceRef": { + "name": "git" + } + } + ], + "outputs": [ + { + "name": "builtImage", + "resourceRef": { + "name": "image" + } + } + ] + }, + "serviceAccountName": "svc1", + "taskSpec": { + "resources": { + "inputs": [ + { + "name": "docker-source", + "type": "git" + } + ], + "outputs": [ + { + "name": "builtImage", + "type": "image" + } + ] + }, + "params": [ + { + "name": "pathToDockerFile", + "type": "string", + "description": "The path to the dockerfile to build", + "default": "/workspace/docker-source/Dockerfile" + }, + { + "name": "pathToContext", + "type": "string", + "description": "The build context used by Kaniko (https://github.com/GoogleContainerTools/kaniko#kaniko-build-contexts)", + "default": "/workspace/docker-source" + } + ], + "steps": [ + { + "name": "build-and-push", + "image": "gcr.io/kaniko-project/executor:v0.14.0", + "command": [ + "/kaniko/executor" + ], + "args": [ + "--dockerfile=$(inputs.params.pathToDockerFile)", + "--destination=$(outputs.resources.builtImage.url)", + "--context=$(inputs.params.pathToContext)" + ], + "env": [ + { + "name": "DOCKER_CONFIG", + "value": "/tekton/home/.docker/" + } + ], + "resources": {} + } + ] + } + }, + "status": { + "podName": "" + } +}