Skip to content

Commit

Permalink
test: modify test package name
Browse files Browse the repository at this point in the history
Try to ensure that only exported functions are tested.

Ref: https://github.com/tektoncd/community/blob/main/standards.md#go-packages

```
All exported functions should have tests
  * If your package is named "foo", prefer putting tests in a "foo_test" package in the same folder to ensure that only exported functions are tested
```

The shell command to search for test package names without the `_test` suffix is:
* `find . -name "*_test.go" | xargs grep -E '^package ' | grep -Ev '_test$' | grep -v '^./test' | sort`
  • Loading branch information
l-qing committed Apr 17, 2023
1 parent 59040f5 commit 3b0f7bd
Show file tree
Hide file tree
Showing 33 changed files with 1,229 additions and 1,151 deletions.
605 changes: 303 additions & 302 deletions pkg/apis/pipeline/v1/matrix_types_test.go

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions pkg/apis/pipeline/v1/taskref_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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
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,
Expand All @@ -14,47 +14,51 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1
package v1_test

import "testing"
import (
"testing"

v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
)

func TestTaskRef_IsCustomTask(t *testing.T) {
tests := []struct {
name string
tr *TaskRef
tr *v1.TaskRef
want bool
}{{
name: "not a custom task - apiVersion and Kind are not set",
tr: &TaskRef{
tr: &v1.TaskRef{
Name: "foo",
},
want: false,
}, {
// related issue: https://github.com/tektoncd/pipeline/issues/6459
name: "not a custom task - apiVersion is not set",
tr: &TaskRef{
tr: &v1.TaskRef{
Name: "foo",
Kind: "Example",
},
want: false,
}, {
name: "not a custom task - kind is not set",
tr: &TaskRef{
tr: &v1.TaskRef{
Name: "foo",
APIVersion: "example/v0",
},
want: false,
}, {
name: "custom task with name",
tr: &TaskRef{
tr: &v1.TaskRef{
Name: "foo",
Kind: "Example",
APIVersion: "example/v0",
},
want: true,
}, {
name: "custom task without name",
tr: &TaskRef{
tr: &v1.TaskRef{
Kind: "Example",
APIVersion: "example/v0",
},
Expand Down
6 changes: 4 additions & 2 deletions pkg/apis/pipeline/v1beta1/cluster_task_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1
package v1beta1_test

import (
"context"
"testing"

v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
)

func TestClusterTaskConversionBadType(t *testing.T) {
good, bad := &ClusterTask{}, &Pipeline{}
good, bad := &v1beta1.ClusterTask{}, &v1beta1.Pipeline{}

if err := good.ConvertTo(context.Background(), bad); err == nil {
t.Errorf("ConvertTo() = %#v, wanted error", bad)
Expand Down
Loading

0 comments on commit 3b0f7bd

Please sign in to comment.