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

Introduce parallelism to unit tests #306

Merged
merged 1 commit into from
Feb 12, 2021
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
2 changes: 1 addition & 1 deletion pkg/authorizer/clusterauthorizer/clusterauthorizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func nonCachedProxyFromEnvironment() func(*http.Request) (*url.URL, error) {
}
}


func TestProxy(tt *testing.T) {
testCases := []struct {
Name string
Expand Down Expand Up @@ -85,6 +84,7 @@ func TestProxy(tt *testing.T) {
for _, tcase := range testCases {
tc := tcase
tt.Run(tc.Name, func(t *testing.T) {
// do not use parallel here
for k, v := range tc.EnvValues {
defer SafeRestoreEnv(k)()
// nil will indicate the need to unset Env
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/configobserver/configobserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func TestChangeSupportConfig(t *testing.T) {
}

for _, tt := range cases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

// log klog to test
klog.SetOutput(utils.NewTestLog(t).Writer())
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ func TestSaveInitialStart(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

klog.SetOutput(utils.NewTestLog(t).Writer())
operators := []runtime.Object{}
Expand Down
2 changes: 2 additions & 0 deletions pkg/gather/clusterconfig/0_gahterer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ func Test_uniqueStrings(t *testing.T) {
{arr: []string{"a"}, want: []string{"a"}},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := uniqueStrings(tt.arr); !reflect.DeepEqual(got, tt.want) {
t.Errorf("uniqueStrings() = %v, want %v", got, tt.want)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/gather/clusterconfig/certificate_signing_requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func TestCSRs(t *testing.T) {
}

for _, tt := range files {
tt := tt
t.Run(tt.dataFile, func(t *testing.T) {
t.Parallel()

r := &certificatesv1b1api.CertificateSigningRequest{}

Expand Down Expand Up @@ -84,7 +86,10 @@ func TestCSRFilters(t *testing.T) {

for i, tt := range files {
n := csrName(tt.csr, fmt.Sprintf("[n/a:%d]", i))
tt := tt
t.Run(n, func(t *testing.T) {
t.Parallel()

now, err := time.Parse("Mon Jan 02 2006 15:04:05 GMT-0700 (MST)", "Tue Feb 18 2020 09:38:42 GMT+0100 (CEST)")
if err != nil {
t.Fatalf("parse couldnt parse date %v", err)
Expand Down
2 changes: 2 additions & 0 deletions pkg/gather/clusterconfig/config_maps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ func TestConfigMapAnonymizer(t *testing.T) {
}

for _, tt := range cases {
tt := tt
t.Run(tt.testName, func(t *testing.T) {
t.Parallel()
f, err := os.Open("testdata/configmaps.json")
mustNotFail(t, err, "error opening test data file. %+v")
defer f.Close()
Expand Down
2 changes: 2 additions & 0 deletions pkg/gather/clusterconfig/image_pruners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func TestGatherClusterPruner(t *testing.T) {
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
client := imageregistryfake.NewSimpleClientset(test.inputObj)
ctx := context.Background()
records, errs := gatherClusterImagePruner(ctx, client.ImageregistryV1())
Expand Down
2 changes: 2 additions & 0 deletions pkg/gather/clusterconfig/image_registries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ func TestGatherClusterImageRegistry(t *testing.T) {
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
client := imageregistryfake.NewSimpleClientset(test.inputObj)
ctx := context.Background()
records, errs := gatherClusterImageRegistry(ctx, client.ImageregistryV1())
Expand Down
2 changes: 2 additions & 0 deletions pkg/gather/clusterconfig/install_plans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func TestGatherInstallPlans(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()

var client *dynamicfake.FakeDynamicClient
coreClient := kubefake.NewSimpleClientset()
Expand Down
2 changes: 2 additions & 0 deletions pkg/gather/clusterconfig/service_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ func TestGatherServiceAccounts(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
coreClient := kubefake.NewSimpleClientset()
for _, d := range test.data {
_, err := coreClient.CoreV1().Namespaces().Create(context.Background(), &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: d.Namespace}}, metav1.CreateOptions{})
Expand Down