Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing tests for pipelinerun_defaults and taskrun_defaults #1153

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_defaults_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2019 The Tekton Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1_test

import (
"context"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestPipelineRunSpec_SetDefaults(t *testing.T) {
cases := []struct {
desc string
prs *v1alpha1.PipelineRunSpec
want *v1alpha1.PipelineRunSpec
}{
{
desc: "timeout is nil",
prs: &v1alpha1.PipelineRunSpec{},
want: &v1alpha1.PipelineRunSpec{
Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute},
},
},
{
desc: "timeout is not nil",
prs: &v1alpha1.PipelineRunSpec{
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
},
want: &v1alpha1.PipelineRunSpec{
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
},
},
}
for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
ctx := context.Background()
tc.prs.SetDefaults(ctx)

if diff := cmp.Diff(tc.want, tc.prs); diff != "" {
t.Errorf("Mismatch of PipelineRunSpec: %s", diff)
}
})
}
}
79 changes: 79 additions & 0 deletions pkg/apis/pipeline/v1alpha1/taskrun_defaults_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Copyright 2019 The Tekton Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1_test

import (
"context"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestTaskRunSpec_SetDefaults(t *testing.T) {
cases := []struct {
desc string
trs *v1alpha1.TaskRunSpec
want *v1alpha1.TaskRunSpec
}{
{
desc: "taskref is nil",
trs: &v1alpha1.TaskRunSpec{
TaskRef: nil,
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
},
want: &v1alpha1.TaskRunSpec{
TaskRef: nil,
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
},
},
{
desc: "taskref kind is empty",
trs: &v1alpha1.TaskRunSpec{
TaskRef: &v1alpha1.TaskRef{},
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
},
want: &v1alpha1.TaskRunSpec{
TaskRef: &v1alpha1.TaskRef{Kind: v1alpha1.NamespacedTaskKind},
Timeout: &metav1.Duration{Duration: 500 * time.Millisecond},
},
},
{
desc: "timeout is nil",
trs: &v1alpha1.TaskRunSpec{
TaskRef: &v1alpha1.TaskRef{Kind: v1alpha1.ClusterTaskKind},
},
want: &v1alpha1.TaskRunSpec{
TaskRef: &v1alpha1.TaskRef{Kind: v1alpha1.ClusterTaskKind},
Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute},
},
},
}
for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
ctx := context.Background()
tc.trs.SetDefaults(ctx)

if diff := cmp.Diff(tc.want, tc.trs); diff != "" {
t.Errorf("Mismatch of TaskRunSpec: %s", diff)
}
})
}
}