Skip to content

Commit

Permalink
Merge pull request #306 from rluders/parallelism-testing
Browse files Browse the repository at this point in the history
Introduce parallelism to unit tests
  • Loading branch information
openshift-merge-robot authored Feb 12, 2021
2 parents 20612a8 + a5d2e07 commit e43b41e
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 1 deletion.
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 @@ -163,7 +163,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 := &certificatesv1api.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 @@ -120,7 +120,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)
coreClient := kubefake.NewSimpleClientset()
ctx := context.Background()
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

0 comments on commit e43b41e

Please sign in to comment.