Skip to content

Commit

Permalink
Use moar builders in tests 👷‍♀️
Browse files Browse the repository at this point in the history
In tektoncd#1043 @EliZucker updated the package names of the v1alpha1 tests to
be `v1alpha1_test`. He did this b/c he wanted to use a function he was
adding to the builder test package for the work he is doing in tektoncd#207, but
this has the nice side effect of making it so that we can use more
builders in these tests! (We couldn't before b/c the builders themselves
have to import and use `v1alpha1`). This commit updates many of these
tests to use builders.
  • Loading branch information
bobcatfish committed Jul 4, 2019
1 parent 5f1fccb commit 981e377
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 621 deletions.
165 changes: 42 additions & 123 deletions pkg/apis/pipeline/v1alpha1/build_gcs_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/test/names"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

tb "github.com/tektoncd/pipeline/test/builder"
)

func Test_Invalid_BuildGCSResource(t *testing.T) {
Expand All @@ -32,120 +33,50 @@ func Test_Invalid_BuildGCSResource(t *testing.T) {
pipelineResource *v1alpha1.PipelineResource
}{{
name: "no location params",
pipelineResource: &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "buildgcs-resource-with-no-location-param",
},
Spec: v1alpha1.PipelineResourceSpec{
Type: v1alpha1.PipelineResourceTypeStorage,
Params: []v1alpha1.Param{{
Name: "NotLocation",
Value: "doesntmatter",
}, {
Name: "type",
Value: "build-gcs",
}},
},
},
pipelineResource: tb.PipelineResource("buildgcs-resource-with-no-location-param", "default", tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeStorage,
tb.PipelineResourceSpecParam("NotLocation", "doesntmatter"),
tb.PipelineResourceSpecParam("type", "build-gcs"),
)),
}, {
name: "location param with empty value",
pipelineResource: &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "gcs-resource-with-empty-location-param",
},
Spec: v1alpha1.PipelineResourceSpec{
Type: v1alpha1.PipelineResourceTypeStorage,
Params: []v1alpha1.Param{{
Name: "Location",
Value: "",
}, {
Name: "type",
Value: "build-gcs",
}},
},
},
pipelineResource: tb.PipelineResource("buildgcs-resource-with-empty-location-param", "default", tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeStorage,
tb.PipelineResourceSpecParam("Location", ""),
tb.PipelineResourceSpecParam("type", "build-gcs"),
)),
}, {
name: "no artifactType params",
pipelineResource: &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "buildgcs-resource-with-no-artifactType-param",
},
Spec: v1alpha1.PipelineResourceSpec{
Type: v1alpha1.PipelineResourceTypeStorage,
Params: []v1alpha1.Param{{
Name: "Location",
Value: "gs://test",
}, {
Name: "type",
Value: "build-gcs",
}},
},
},
pipelineResource: tb.PipelineResource("buildgcs-resource-with-no-artifactType-param", "default", tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeStorage,
tb.PipelineResourceSpecParam("Location", "gs://test"),
tb.PipelineResourceSpecParam("type", "build-gcs"),
)),
}, {
name: "artifactType param with empty value",
pipelineResource: &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "gcs-resource-with-empty-location-param",
},
Spec: v1alpha1.PipelineResourceSpec{
Type: v1alpha1.PipelineResourceTypeStorage,
Params: []v1alpha1.Param{{
Name: "Location",
Value: "gs://test",
}, {
Name: "type",
Value: "build-gcs",
}, {
Name: "ArtifactType",
Value: "",
}},
},
},
pipelineResource: tb.PipelineResource("buildgcs-resource-with-empty-artifactType-param", "default", tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeStorage,
tb.PipelineResourceSpecParam("Location", "gs://test"),
tb.PipelineResourceSpecParam("type", "build-gcs"),
tb.PipelineResourceSpecParam("ArtifactType", ""),
)),
}, {
name: "artifactType param with invalid value",
pipelineResource: &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "gcs-resource-with-empty-location-param",
},
Spec: v1alpha1.PipelineResourceSpec{
Type: v1alpha1.PipelineResourceTypeStorage,
Params: []v1alpha1.Param{{
Name: "Location",
Value: "gs://test",
}, {
Name: "type",
Value: "build-gcs",
}, {
Name: "ArtifactType",
Value: "invalid-type",
}},
},
},
pipelineResource: tb.PipelineResource("buildgcs-resource-with-invalid-artifactType-param", "default", tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeStorage,
tb.PipelineResourceSpecParam("Location", "gs://test"),
tb.PipelineResourceSpecParam("type", "build-gcs"),
tb.PipelineResourceSpecParam("ArtifactType", "invalid-type"),
)),
}, {
name: "artifactType param with secrets value",
pipelineResource: &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "gcs-resource-with-secrets",
},
Spec: v1alpha1.PipelineResourceSpec{
Type: v1alpha1.PipelineResourceTypeStorage,
Params: []v1alpha1.Param{{
Name: "Location",
Value: "gs://test",
}, {
Name: "type",
Value: "build-gcs",
}, {
Name: "ArtifactType",
Value: "invalid-type",
}},
SecretParams: []v1alpha1.SecretParam{{
SecretKey: "secretKey",
SecretName: "secretName",
FieldName: "GOOGLE_APPLICATION_CREDENTIALS",
}},
},
},
pipelineResource: tb.PipelineResource("buildgcs-resource-with-invalid-artifactType-param-and-secrets", "default", tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeStorage,
tb.PipelineResourceSpecParam("Location", "gs://test"),
tb.PipelineResourceSpecParam("type", "build-gcs"),
tb.PipelineResourceSpecParam("ArtifactType", "invalid-type"),
tb.PipelineResourceSpecSecretParam("secretKey", "secretName", "GOOGLE_APPLICATION_CREDENTIALS"),
)),
}}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
Expand All @@ -158,24 +89,12 @@ func Test_Invalid_BuildGCSResource(t *testing.T) {
}

func Test_Valid_NewBuildGCSResource(t *testing.T) {
pr := &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "build-gcs-resource",
},
Spec: v1alpha1.PipelineResourceSpec{
Type: v1alpha1.PipelineResourceTypeStorage,
Params: []v1alpha1.Param{{
Name: "Location",
Value: "gs://fake-bucket",
}, {
Name: "type",
Value: "build-gcs",
}, {
Name: "ArtifactType",
Value: "Manifest",
}},
},
}
pr := tb.PipelineResource("build-gcs-resource", "default", tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeStorage,
tb.PipelineResourceSpecParam("Location", "gs://fake-bucket"),
tb.PipelineResourceSpecParam("type", "build-gcs"),
tb.PipelineResourceSpecParam("ArtifactType", "Manifest"),
))
expectedGCSResource := &v1alpha1.BuildGCSResource{
Name: "build-gcs-resource",
Location: "gs://fake-bucket",
Expand Down
125 changes: 30 additions & 95 deletions pkg/apis/pipeline/v1alpha1/cluster_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/test/names"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

tb "github.com/tektoncd/pipeline/test/builder"
)

func TestNewClusterResource(t *testing.T) {
Expand All @@ -30,29 +31,13 @@ func TestNewClusterResource(t *testing.T) {
want *v1alpha1.ClusterResource
}{{
desc: "basic cluster resource",
resource: &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "test-clus ter-resource",
Namespace: "foo",
},
Spec: v1alpha1.PipelineResourceSpec{
Type: v1alpha1.PipelineResourceTypeCluster,
Params: []v1alpha1.Param{{
Name: "name",
Value: "test_cluster_resource",
}, {
Name: "url",
Value: "http://10.10.10.10",
}, {
Name: "cadata",
Value: "bXktY2x1c3Rlci1jZXJ0Cg",
}, {
Name: "token",
Value: "my-token",
},
},
},
},
resource: tb.PipelineResource("test-cluster-resource", "default", tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeCluster,
tb.PipelineResourceSpecParam("name", "test_cluster_resource"),
tb.PipelineResourceSpecParam("url", "http://10.10.10.10"),
tb.PipelineResourceSpecParam("cadata", "bXktY2x1c3Rlci1jZXJ0Cg"),
tb.PipelineResourceSpecParam("token", "my-token"),
)),
want: &v1alpha1.ClusterResource{
Name: "test_cluster_resource",
Type: v1alpha1.PipelineResourceTypeCluster,
Expand All @@ -62,32 +47,14 @@ func TestNewClusterResource(t *testing.T) {
},
}, {
desc: "resource with password instead of token",
resource: &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster-resource",
Namespace: "foo",
},
Spec: v1alpha1.PipelineResourceSpec{
Type: v1alpha1.PipelineResourceTypeCluster,
Params: []v1alpha1.Param{{
Name: "name",
Value: "test_cluster_resource",
}, {
Name: "url",
Value: "http://10.10.10.10",
}, {
Name: "cadata",
Value: "bXktY2x1c3Rlci1jZXJ0Cg",
}, {
Name: "username",
Value: "user",
}, {
Name: "password",
Value: "pass",
},
},
},
},
resource: tb.PipelineResource("test-cluster-resource", "default", tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeCluster,
tb.PipelineResourceSpecParam("name", "test_cluster_resource"),
tb.PipelineResourceSpecParam("url", "http://10.10.10.10"),
tb.PipelineResourceSpecParam("cadata", "bXktY2x1c3Rlci1jZXJ0Cg"),
tb.PipelineResourceSpecParam("username", "user"),
tb.PipelineResourceSpecParam("password", "pass"),
)),
want: &v1alpha1.ClusterResource{
Name: "test_cluster_resource",
Type: v1alpha1.PipelineResourceTypeCluster,
Expand All @@ -98,26 +65,12 @@ func TestNewClusterResource(t *testing.T) {
},
}, {
desc: "set insecure flag to true when there is no cert",
resource: &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster-resource",
Namespace: "foo",
},
Spec: v1alpha1.PipelineResourceSpec{
Type: v1alpha1.PipelineResourceTypeCluster,
Params: []v1alpha1.Param{{
Name: "Name",
Value: "test.cluster.resource",
}, {
Name: "url",
Value: "http://10.10.10.10",
}, {
Name: "token",
Value: "my-token",
},
},
},
},
resource: tb.PipelineResource("test-cluster-resource", "foo", tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeCluster,
tb.PipelineResourceSpecParam("name", "test.cluster.resource"),
tb.PipelineResourceSpecParam("url", "http://10.10.10.10"),
tb.PipelineResourceSpecParam("token", "my-token"),
)),
want: &v1alpha1.ClusterResource{
Name: "test.cluster.resource",
Type: v1alpha1.PipelineResourceTypeCluster,
Expand All @@ -127,31 +80,13 @@ func TestNewClusterResource(t *testing.T) {
},
}, {
desc: "basic resource with secrets",
resource: &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster-resource",
Namespace: "foo",
},
Spec: v1alpha1.PipelineResourceSpec{
Type: v1alpha1.PipelineResourceTypeCluster,
Params: []v1alpha1.Param{{
Name: "name",
Value: "test-cluster-resource",
}, {
Name: "url",
Value: "http://10.10.10.10",
}},
SecretParams: []v1alpha1.SecretParam{{
FieldName: "cadata",
SecretKey: "cadatakey",
SecretName: "secret1",
}, {
FieldName: "token",
SecretKey: "tokenkey",
SecretName: "secret1",
}},
},
},
resource: tb.PipelineResource("test-cluster-resource", "default", tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeCluster,
tb.PipelineResourceSpecParam("name", "test-cluster-resource"),
tb.PipelineResourceSpecParam("url", "http://10.10.10.10"),
tb.PipelineResourceSpecSecretParam("cadata", "secret1", "cadatakey"),
tb.PipelineResourceSpecSecretParam("token", "secret1", "tokenkey"),
)),
want: &v1alpha1.ClusterResource{
Name: "test-cluster-resource",
Type: v1alpha1.PipelineResourceTypeCluster,
Expand Down
Loading

0 comments on commit 981e377

Please sign in to comment.