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 Mar 31, 2023
1 parent b51f08c commit 631991e
Show file tree
Hide file tree
Showing 34 changed files with 175 additions and 47 deletions.
3 changes: 2 additions & 1 deletion pkg/apis/pipeline/v1/matrix_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1
package v1_test

import (
"testing"

"github.com/google/go-cmp/cmp"
. "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/test/diff"
)

Expand Down
24 changes: 22 additions & 2 deletions pkg/apis/pipeline/v1/taskref_types_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
package v1
/*
Copyright 2023 The Tekton Authors
import "testing"
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 v1_test

import (
"testing"

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

func TestTaskRef_IsCustomTask(t *testing.T) {
tests := []struct {
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/pipeline/v1beta1/cluster_task_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1
package v1beta1_test

import (
"context"
"testing"

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

func TestClusterTaskConversionBadType(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/pipeline/v1beta1/matrix_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1
package v1beta1_test

import (
"testing"

"github.com/google/go-cmp/cmp"
. "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/test/diff"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/pipeline/v1beta1/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1
package v1beta1_test

import (
"testing"

"github.com/google/go-cmp/cmp"
. "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/test/diff"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down
24 changes: 22 additions & 2 deletions pkg/apis/pipeline/v1beta1/taskref_types_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
package v1beta1
/*
Copyright 2023 The Tekton Authors
import "testing"
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 v1beta1_test

import (
"testing"

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

func TestTaskRef_IsCustomTask(t *testing.T) {
tests := []struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

package v1alpha1
package v1alpha1_test

import (
"context"
Expand All @@ -24,6 +24,7 @@ import (

"github.com/google/go-cmp/cmp"
pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
. "github.com/tektoncd/pipeline/pkg/apis/resolution/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1"
"github.com/tektoncd/pipeline/test/diff"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
*/

package v1beta1
package v1beta1_test

import (
"context"
"testing"

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

func TestResolutionRequestConversionBadType(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/run/v1beta1/customrunstatus_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
*/

package v1beta1
package v1beta1_test

import (
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/tektoncd/pipeline/pkg/apis/run/v1alpha1"
. "github.com/tektoncd/pipeline/pkg/apis/run/v1beta1"
"github.com/tektoncd/pipeline/test/diff"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
16 changes: 16 additions & 0 deletions pkg/credentials/initialize_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2023 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 credentials

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/internal/computeresources/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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 computeresources

import (
Expand Down
4 changes: 3 additions & 1 deletion pkg/list/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package list
package list_test

import (
"reflect"
"testing"

. "github.com/tektoncd/pipeline/pkg/list"
)

func TestIsSame_same(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/names/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package names
package names_test

import (
"strings"
"testing"

. "github.com/tektoncd/pipeline/pkg/names"
"github.com/tektoncd/pipeline/test/names"
)

Expand Down Expand Up @@ -51,7 +52,7 @@ func TestRestrictLength(t *testing.T) {
want: "hello",
}, {
in: strings.Repeat("a", 100),
want: strings.Repeat("a", maxNameLength),
want: strings.Repeat("a", 63),
}, {
// Values that don't end with an alphanumeric value are
// trimmed until they do.
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/customrun/customrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package customrun
package customrun_test

import (
"context"
Expand All @@ -25,6 +25,7 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
. "github.com/tektoncd/pipeline/pkg/reconciler/customrun"
"github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent"
ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing"
"github.com/tektoncd/pipeline/test"
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/events/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package cache
package cache_test

import (
"net/url"
Expand All @@ -28,6 +28,7 @@ import (
lru "github.com/hashicorp/golang-lru"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
. "github.com/tektoncd/pipeline/pkg/reconciler/events/cache"
"github.com/tektoncd/pipeline/test/diff"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/events/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package events
package events_test

import (
"testing"

"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
. "github.com/tektoncd/pipeline/pkg/reconciler/events"
"github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent"
"github.com/tektoncd/pipeline/pkg/reconciler/events/k8sevent"
corev1 "k8s.io/api/core/v1"
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/events/k8sevent/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package k8sevent
package k8sevent_test

import (
"errors"
Expand All @@ -23,6 +23,7 @@ import (

"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
. "github.com/tektoncd/pipeline/pkg/reconciler/events/k8sevent"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/pipelinerun/pipelinespec/pipelinespec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package pipelinespec
package pipelinespec_test

import (
"context"
Expand All @@ -24,6 +24,7 @@ import (
"github.com/google/go-cmp/cmp"
cfgtesting "github.com/tektoncd/pipeline/pkg/apis/config/testing"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
. "github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/pipelinespec"
"github.com/tektoncd/pipeline/test/diff"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/pipelinerun/resources/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package resources
package resources_test

import (
"context"
Expand All @@ -24,6 +24,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
. "github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources"
"github.com/tektoncd/pipeline/test/diff"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/selection"
Expand Down
16 changes: 16 additions & 0 deletions pkg/reconciler/pipelinerun/resources/resultrefresolution_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2023 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 resources

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package resources
package resources_test

import (
"strings"
"testing"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
. "github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources"
"github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources"
"k8s.io/apimachinery/pkg/selection"
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/pipelinerun/resources/validate_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package resources
package resources_test

import (
"testing"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
. "github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down
Loading

0 comments on commit 631991e

Please sign in to comment.