Skip to content

Commit 7a11326

Browse files
Shuhei Kitagawatekton-robot
Shuhei Kitagawa
authored andcommitted
Add missing tests for pipelinerun_defaults and taskrun_defaults
1 parent 0eaa862 commit 7a11326

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Copyright 2019 The Tekton Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1_test
18+
19+
import (
20+
"context"
21+
"testing"
22+
"time"
23+
24+
"github.com/google/go-cmp/cmp"
25+
"github.com/tektoncd/pipeline/pkg/apis/config"
26+
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
27+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
)
29+
30+
func TestPipelineRunSpec_SetDefaults(t *testing.T) {
31+
cases := []struct {
32+
desc string
33+
prs *v1alpha1.PipelineRunSpec
34+
want *v1alpha1.PipelineRunSpec
35+
}{
36+
{
37+
desc: "timeout is nil",
38+
prs: &v1alpha1.PipelineRunSpec{},
39+
want: &v1alpha1.PipelineRunSpec{
40+
Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute},
41+
},
42+
},
43+
{
44+
desc: "timeout is not nil",
45+
prs: &v1alpha1.PipelineRunSpec{
46+
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
47+
},
48+
want: &v1alpha1.PipelineRunSpec{
49+
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
50+
},
51+
},
52+
}
53+
for _, tc := range cases {
54+
t.Run(tc.desc, func(t *testing.T) {
55+
ctx := context.Background()
56+
tc.prs.SetDefaults(ctx)
57+
58+
if diff := cmp.Diff(tc.want, tc.prs); diff != "" {
59+
t.Errorf("Mismatch of PipelineRunSpec: %s", diff)
60+
}
61+
})
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
Copyright 2019 The Tekton Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1_test
18+
19+
import (
20+
"context"
21+
"testing"
22+
"time"
23+
24+
"github.com/google/go-cmp/cmp"
25+
"github.com/tektoncd/pipeline/pkg/apis/config"
26+
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
27+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
)
29+
30+
func TestTaskRunSpec_SetDefaults(t *testing.T) {
31+
cases := []struct {
32+
desc string
33+
trs *v1alpha1.TaskRunSpec
34+
want *v1alpha1.TaskRunSpec
35+
}{
36+
{
37+
desc: "taskref is nil",
38+
trs: &v1alpha1.TaskRunSpec{
39+
TaskRef: nil,
40+
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
41+
},
42+
want: &v1alpha1.TaskRunSpec{
43+
TaskRef: nil,
44+
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
45+
},
46+
},
47+
{
48+
desc: "taskref kind is empty",
49+
trs: &v1alpha1.TaskRunSpec{
50+
TaskRef: &v1alpha1.TaskRef{},
51+
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
52+
},
53+
want: &v1alpha1.TaskRunSpec{
54+
TaskRef: &v1alpha1.TaskRef{Kind: v1alpha1.NamespacedTaskKind},
55+
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
56+
},
57+
},
58+
{
59+
desc: "timeout is nil",
60+
trs: &v1alpha1.TaskRunSpec{
61+
TaskRef: &v1alpha1.TaskRef{Kind: v1alpha1.ClusterTaskKind},
62+
},
63+
want: &v1alpha1.TaskRunSpec{
64+
TaskRef: &v1alpha1.TaskRef{Kind: v1alpha1.ClusterTaskKind},
65+
Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute},
66+
},
67+
},
68+
}
69+
for _, tc := range cases {
70+
t.Run(tc.desc, func(t *testing.T) {
71+
ctx := context.Background()
72+
tc.trs.SetDefaults(ctx)
73+
74+
if diff := cmp.Diff(tc.want, tc.trs); diff != "" {
75+
t.Errorf("Mismatch of TaskRunSpec: %s", diff)
76+
}
77+
})
78+
}
79+
}

0 commit comments

Comments
 (0)