mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-04-15 07:06:45 +00:00
Stub in TestUpstreamGithubIdentityProvider for unit tests
This commit is contained in:
@@ -9,22 +9,29 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
k8sinformers "k8s.io/client-go/informers"
|
||||
kubernetesfake "k8s.io/client-go/kubernetes/fake"
|
||||
"k8s.io/utils/ptr"
|
||||
|
||||
"go.pinniped.dev/generated/latest/apis/supervisor/idp/v1alpha1"
|
||||
pinnipedfake "go.pinniped.dev/generated/latest/client/supervisor/clientset/versioned/fake"
|
||||
pinnipedinformers "go.pinniped.dev/generated/latest/client/supervisor/informers/externalversions"
|
||||
"go.pinniped.dev/internal/controllerlib"
|
||||
"go.pinniped.dev/internal/federationdomain/dynamicupstreamprovider"
|
||||
"go.pinniped.dev/internal/federationdomain/upstreamprovider"
|
||||
"go.pinniped.dev/internal/plog"
|
||||
"go.pinniped.dev/internal/testutil/oidctestutil"
|
||||
"go.pinniped.dev/internal/testutil/githubtestutil"
|
||||
"go.pinniped.dev/internal/upstreamgithub"
|
||||
)
|
||||
|
||||
func TestController(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testNamespace := "foo"
|
||||
testName := "bar"
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
githubIdentityProviders []runtime.Object
|
||||
@@ -32,11 +39,41 @@ func TestController(t *testing.T) {
|
||||
configClient func(*pinnipedfake.Clientset)
|
||||
wantErr string
|
||||
wantLogs []string
|
||||
wantResultingCache []*oidctestutil.TestUpstreamOIDCIdentityProvider
|
||||
wantResultingCache []*githubtestutil.TestUpstreamGithubIdentityProvider
|
||||
wantResultingUpstreams []v1alpha1.GitHubIdentityProvider
|
||||
}{
|
||||
{
|
||||
name: "The controller runs.... and should be further tested.",
|
||||
name: "no upstreams",
|
||||
}, {
|
||||
name: "found github idp is cached",
|
||||
inputSecrets: []runtime.Object{},
|
||||
githubIdentityProviders: []runtime.Object{&v1alpha1.GitHubIdentityProvider{
|
||||
ObjectMeta: v1.ObjectMeta{Namespace: testNamespace, Name: testName},
|
||||
Spec: v1alpha1.GitHubIdentityProviderSpec{
|
||||
GitHubAPI: v1alpha1.GitHubAPIConfig{
|
||||
Host: ptr.To("127.0.0.1"),
|
||||
TLS: &v1alpha1.TLSSpec{
|
||||
CertificateAuthorityData: "irrelevant",
|
||||
},
|
||||
},
|
||||
Claims: v1alpha1.GitHubClaims{
|
||||
Username: ptr.To(v1alpha1.GitHubUsernameID),
|
||||
Groups: ptr.To(v1alpha1.GitHubUseTeamNameForGroupName),
|
||||
},
|
||||
AllowAuthentication: v1alpha1.GitHubAllowAuthenticationSpec{
|
||||
Organizations: v1alpha1.GitHubOrganizationsSpec{
|
||||
Policy: ptr.To(v1alpha1.GitHubAllowedAuthOrganizationsPolicyAllGitHubUsers),
|
||||
Allowed: []string{"foo", "bar"},
|
||||
},
|
||||
},
|
||||
Client: v1alpha1.GitHubClientSpec{
|
||||
SecretName: "some-secret",
|
||||
},
|
||||
},
|
||||
}},
|
||||
wantResultingCache: []*githubtestutil.TestUpstreamGithubIdentityProvider{{
|
||||
Name: "test-github-idp-to-flesh-out",
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -45,7 +82,6 @@ func TestController(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dynamicUpstreamProvider := dynamicupstreamprovider.NewDynamicUpstreamIDPProvider()
|
||||
pinnipedAPIClient := pinnipedfake.NewSimpleClientset(tt.githubIdentityProviders...)
|
||||
fakePinnipedClientForInformers := pinnipedfake.NewSimpleClientset(tt.githubIdentityProviders...)
|
||||
pinnipedInformers := pinnipedinformers.NewSharedInformerFactory(fakePinnipedClientForInformers, 0)
|
||||
@@ -53,11 +89,16 @@ func TestController(t *testing.T) {
|
||||
fakeKubeClient := kubernetesfake.NewSimpleClientset(tt.inputSecrets...)
|
||||
kubeInformers := k8sinformers.NewSharedInformerFactoryWithOptions(fakeKubeClient, 0)
|
||||
|
||||
cache := dynamicupstreamprovider.NewDynamicUpstreamIDPProvider()
|
||||
cache.SetGitHubIdentityProviders([]upstreamprovider.UpstreamGithubIdentityProviderI{
|
||||
&upstreamgithub.ProviderConfig{Name: "initial-entry-to-remove"},
|
||||
})
|
||||
|
||||
var log bytes.Buffer
|
||||
logger := plog.TestLogger(t, &log)
|
||||
|
||||
controller := New(
|
||||
dynamicUpstreamProvider,
|
||||
cache,
|
||||
pinnipedAPIClient,
|
||||
pinnipedInformers.IDP().V1alpha1().GitHubIdentityProviders(),
|
||||
kubeInformers.Core().V1().Secrets(),
|
||||
@@ -79,6 +120,9 @@ func TestController(t *testing.T) {
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
actualIDPList := cache.GetGitHubIdentityProviders()
|
||||
require.Equal(t, len(tt.wantResultingCache), len(actualIDPList))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user