forked from tektoncd/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use golden package for unit test for PipelineResource 🐐
This allow to remove the potential long expected output from the test code. See gotest.tools/v3/golden for documentation. Signed-off-by: Vincent Demeester <[email protected]>
- Loading branch information
1 parent
3e05b0b
commit f326912
Showing
11 changed files
with
53 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
package pipelineresource | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
|
@@ -23,6 +24,7 @@ import ( | |
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" | ||
pipelinetest "github.com/tektoncd/pipeline/test" | ||
tb "github.com/tektoncd/pipeline/test/builder" | ||
"gotest.tools/v3/golden" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
@@ -77,90 +79,49 @@ func TestPipelineResourceList(t *testing.T) { | |
name string | ||
command *cobra.Command | ||
args []string | ||
expected []string | ||
wantError bool | ||
}{ | ||
{ | ||
name: "Invalid namespace", | ||
command: command(t, pres, ns), | ||
args: []string{"list", "-n", "invalid"}, | ||
wantError: true, | ||
expected: []string{ | ||
"Error: namespaces \"invalid\" not found\n", | ||
}, | ||
}, | ||
{ | ||
name: "Multiple pipeline resources", | ||
command: command(t, pres, ns), | ||
args: []string{"list", "-n", "test-ns-1"}, | ||
wantError: false, | ||
expected: []string{ | ||
"NAME TYPE DETAILS", | ||
"test-5 cloudEvent targetURI: http://sink", | ||
"test git url: [email protected]:tektoncd/cli-new.git", | ||
"test-2 git url: [email protected]:tektoncd/cli.git", | ||
"test-1 image URL: quey.io/tekton/controller", | ||
"test-3 image ---", | ||
"", | ||
}, | ||
}, | ||
{ | ||
name: "Single pipeline resource", | ||
command: command(t, pres, ns), | ||
args: []string{"list", "-n", "test-ns-2"}, | ||
wantError: false, | ||
expected: []string{ | ||
"NAME TYPE DETAILS", | ||
"test-4 image URL: quey.io/tekton/webhook", | ||
"", | ||
}, | ||
}, | ||
{ | ||
name: "Single Pipeline Resource by type", | ||
command: command(t, pres, ns), | ||
args: []string{"list", "-n", "test-ns-2", "-t", "image"}, | ||
wantError: false, | ||
expected: []string{ | ||
"NAME TYPE DETAILS", | ||
"test-4 image URL: quey.io/tekton/webhook", | ||
"", | ||
}, | ||
}, | ||
{ | ||
name: "Multiple Pipeline Resource by type", | ||
command: command(t, pres, ns), | ||
args: []string{"list", "-n", "test-ns-1", "-t", "image"}, | ||
wantError: false, | ||
expected: []string{ | ||
"NAME TYPE DETAILS", | ||
"test-1 image URL: quey.io/tekton/controller", | ||
"test-3 image ---", | ||
"", | ||
}, | ||
}, | ||
{ | ||
name: "Empty Pipeline Resource by type", | ||
command: command(t, pres, ns), | ||
args: []string{"list", "-n", "test-ns-1", "-t", "storage"}, | ||
wantError: false, | ||
expected: []string{ | ||
"No pipelineresources found.", | ||
"", | ||
}, | ||
}, | ||
{ | ||
name: "By template", | ||
command: command(t, pres, ns), | ||
args: []string{"list", "-n", "test-ns-1", "-o", "jsonpath={range .items[*]}{.metadata.name}{\"\\n\"}{end}"}, | ||
wantError: false, | ||
expected: []string{ | ||
"test-5", | ||
"test", | ||
"test-2", | ||
"test-1", | ||
"test-3", | ||
"", | ||
}, | ||
}, | ||
} | ||
|
||
|
@@ -171,7 +132,7 @@ func TestPipelineResourceList(t *testing.T) { | |
if !td.wantError && err != nil { | ||
t.Errorf("Unexpected error: %v", err) | ||
} | ||
test.AssertOutput(t, strings.Join(td.expected, "\n"), out) | ||
golden.Assert(t, out, strings.ReplaceAll(fmt.Sprintf("%s.golden", t.Name()), "/", "-")) | ||
}) | ||
} | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
pkg/cmd/pipelineresource/testdata/TestPipelineResourceDescribe_WithParams.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Name: test-1 | ||
Namespace: test-ns-1 | ||
PipelineResource Type: image | ||
|
||
Params | ||
|
||
NAME VALUE | ||
URL quay.io/tekton/controller | ||
|
||
Secret Params | ||
|
||
No secret params |
14 changes: 14 additions & 0 deletions
14
pkg/cmd/pipelineresource/testdata/TestPipelineResourceDescribe_WithSecretParams.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Name: test-1 | ||
Namespace: test-ns-1 | ||
PipelineResource Type: image | ||
|
||
Params | ||
|
||
NAME VALUE | ||
URL quay.io/tekton/controller | ||
TAG latest | ||
|
||
Secret Params | ||
|
||
FIELDNAME SECRETNAME | ||
githubToken github-secrets |
5 changes: 5 additions & 0 deletions
5
pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-By_template.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
test-5 | ||
test | ||
test-2 | ||
test-1 | ||
test-3 |
1 change: 1 addition & 0 deletions
1
...pipelineresource/testdata/TestPipelineResourceList-Empty_Pipeline_Resource_by_type.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
No pipelineresources found. |
1 change: 1 addition & 0 deletions
1
pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Invalid_namespace.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Error: namespaces "invalid" not found |
3 changes: 3 additions & 0 deletions
3
...elineresource/testdata/TestPipelineResourceList-Multiple_Pipeline_Resource_by_type.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
NAME TYPE DETAILS | ||
test-1 image URL: quey.io/tekton/controller | ||
test-3 image --- |
6 changes: 6 additions & 0 deletions
6
...cmd/pipelineresource/testdata/TestPipelineResourceList-Multiple_pipeline_resources.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
NAME TYPE DETAILS | ||
test-5 cloudEvent targetURI: http://sink | ||
test git url: [email protected]:tektoncd/cli-new.git | ||
test-2 git url: [email protected]:tektoncd/cli.git | ||
test-1 image URL: quey.io/tekton/controller | ||
test-3 image --- |
2 changes: 2 additions & 0 deletions
2
...ipelineresource/testdata/TestPipelineResourceList-Single_Pipeline_Resource_by_type.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
NAME TYPE DETAILS | ||
test-4 image URL: quey.io/tekton/webhook |
2 changes: 2 additions & 0 deletions
2
pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Single_pipeline_resource.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
NAME TYPE DETAILS | ||
test-4 image URL: quey.io/tekton/webhook |