Skip to content

Commit 5b465b9

Browse files
authored
test(oauth): add unit test for oauth.go and rename it to gather_cluster_oauth.go (#738)
* rename oauth.go and create unit tests for it * lint fix * refactoring
1 parent 7f19a5c commit 5b465b9

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package clusterconfig
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
configv1 "github.com/openshift/api/config/v1"
8+
configfake "github.com/openshift/client-go/config/clientset/versioned/fake"
9+
"github.com/openshift/insights-operator/pkg/record"
10+
"github.com/stretchr/testify/assert"
11+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12+
)
13+
14+
func Test_gatherClusterOAuth(t *testing.T) {
15+
tests := []struct {
16+
name string
17+
oAuthDefinition *configv1.OAuth
18+
wantRecords []record.Record
19+
wantErrCount int
20+
}{
21+
{
22+
name: "successful retrieval cluster oauth",
23+
oAuthDefinition: &configv1.OAuth{ObjectMeta: metav1.ObjectMeta{Name: "cluster"}},
24+
wantRecords: []record.Record{
25+
{
26+
Name: "config/oauth",
27+
Item: record.ResourceMarshaller{
28+
Resource: &configv1.OAuth{ObjectMeta: metav1.ObjectMeta{Name: "cluster"}},
29+
},
30+
},
31+
},
32+
wantErrCount: 0,
33+
},
34+
{
35+
name: "empty oauth",
36+
oAuthDefinition: &configv1.OAuth{},
37+
wantRecords: nil,
38+
wantErrCount: 0,
39+
},
40+
}
41+
42+
for _, tt := range tests {
43+
t.Run(tt.name, func(t *testing.T) {
44+
configClient := configfake.NewSimpleClientset(tt.oAuthDefinition)
45+
records, errs := gatherClusterOAuth(context.TODO(), configClient.ConfigV1())
46+
assert.Equal(t, tt.wantRecords, records)
47+
assert.Len(t, errs, tt.wantErrCount)
48+
})
49+
}
50+
}

0 commit comments

Comments
 (0)