Skip to content

Commit

Permalink
test(clusterconfig): add tests for gather_cluster_authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
rluders committed Jun 16, 2023
1 parent d31d4db commit 020d568
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions pkg/gatherers/clusterconfig/gather_cluster_authentication_test.go
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)
})
}
}

0 comments on commit 020d568

Please sign in to comment.