Skip to content

Commit

Permalink
Migrate from test builders to structs
Browse files Browse the repository at this point in the history
This is helpful as we migrate to the v1beta1 types since we won't have
to maintain separate test builders for v1beta1 types.

Ref #1067, #735

Signed-off-by: Dibyo Mukherjee <dibyo@google.com>
  • Loading branch information
dibyom authored and tekton-robot committed May 11, 2021
1 parent f84fcfc commit 74dec96
Show file tree
Hide file tree
Showing 8 changed files with 1,750 additions and 924 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"testing"

"github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1"
bldr "github.com/tektoncd/triggers/test/builder"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func Test_ClusterTriggerBindingValidate(t *testing.T) {
Expand All @@ -30,23 +30,49 @@ func Test_ClusterTriggerBindingValidate(t *testing.T) {
tb *v1alpha1.ClusterTriggerBinding
}{{
name: "empty",
tb: bldr.ClusterTriggerBinding("name"),
tb: &v1alpha1.ClusterTriggerBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
},
},
}, {
name: "multiple params",
tb: bldr.ClusterTriggerBinding("name",
bldr.ClusterTriggerBindingSpec(
bldr.TriggerBindingParam("param1", "$(body.input1)"),
bldr.TriggerBindingParam("param2", "$(body.input2)"),
bldr.TriggerBindingParam("param3", "$(body.input3)"),
)),
tb: &v1alpha1.ClusterTriggerBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
},
Spec: v1alpha1.TriggerBindingSpec{
Params: []v1alpha1.Param{{
Name: "param1",
Value: "$(body.input1)",
}, {
Name: "param2",
Value: "$(body.input2)",
}, {
Name: "param3",
Value: "$(body.input3)",
}},
},
},
}, {
name: "multiple params case sensitive",
tb: bldr.ClusterTriggerBinding("name",
bldr.ClusterTriggerBindingSpec(
bldr.TriggerBindingParam("param1", "$(body.input1)"),
bldr.TriggerBindingParam("PARAM1", "$(body.input2)"),
bldr.TriggerBindingParam("Param1", "$(body.input3)"),
)),
tb: &v1alpha1.ClusterTriggerBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
},
Spec: v1alpha1.TriggerBindingSpec{
Params: []v1alpha1.Param{{
Name: "param1",
Value: "$(body.input1)",
}, {
Name: "PARAM1",
Value: "$(body.input2)",
}, {
Name: "param3",
Value: "$(body.input3)",
}},
},
},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -63,12 +89,23 @@ func Test_ClusterTriggerBindingValidate_error(t *testing.T) {
tb *v1alpha1.ClusterTriggerBinding
}{{
name: "duplicate params",
tb: bldr.ClusterTriggerBinding("name",
bldr.ClusterTriggerBindingSpec(
bldr.TriggerBindingParam("param1", "$(body.param1)"),
bldr.TriggerBindingParam("param1", "$(body.param1)"),
bldr.TriggerBindingParam("param3", "$(body.param1)"),
)),
tb: &v1alpha1.ClusterTriggerBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
},
Spec: v1alpha1.TriggerBindingSpec{
Params: []v1alpha1.Param{{
Name: "param1",
Value: "$(body.input1)",
}, {
Name: "param1",
Value: "$(body.input2)",
}, {
Name: "param3",
Value: "$(body.input3)",
}},
},
},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading

0 comments on commit 74dec96

Please sign in to comment.