-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(clusterconfig): add tests for gather_cluster_authentication
- Loading branch information
Ricardo Lüders
committed
Jun 16, 2023
1 parent
d31d4db
commit 020d568
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
pkg/gatherers/clusterconfig/gather_cluster_authentication_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package clusterconfig | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
configfake "github.com/openshift/client-go/config/clientset/versioned/fake" | ||
|
||
v1 "github.com/openshift/api/config/v1" | ||
"github.com/openshift/insights-operator/pkg/record" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_gatherClusterAuthentication(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
authentication *v1.Authentication | ||
result []record.Record | ||
errCount int | ||
}{ | ||
{ | ||
name: "Retrieving authentication returns record of that authentication and no errors", | ||
authentication: &v1.Authentication{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "cluster", | ||
}, | ||
}, | ||
result: []record.Record{ | ||
{ | ||
Name: "config/authentication", | ||
Item: record.ResourceMarshaller{ | ||
Resource: &v1.Authentication{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
errCount: 0, | ||
}, | ||
{ | ||
name: "Retrieving no authentication returns no error/no records", | ||
authentication: &v1.Authentication{}, | ||
result: nil, | ||
}, | ||
} | ||
for _, testCase := range tests { | ||
tc := testCase | ||
t.Run(tc.name, func(t *testing.T) { | ||
t.Parallel() | ||
// Given | ||
configClient := configfake.NewSimpleClientset(tc.authentication) | ||
|
||
// When | ||
got, gotErrs := gatherClusterAuthentication(context.Background(), configClient.ConfigV1()) | ||
|
||
// Assert | ||
assert.Equal(t, tc.result, got) | ||
assert.Len(t, gotErrs, tc.errCount) | ||
}) | ||
} | ||
} |