Skip to content

Commit

Permalink
Add expectedPodIndity to ResolveAuthRef tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Wozniak <wozniak.jan@gmail.com>
  • Loading branch information
sammaxwellxyz authored and wozniakjan committed Jan 5, 2024
1 parent df74300 commit 4f9cdc9
Showing 1 changed file with 72 additions and 16 deletions.
88 changes: 72 additions & 16 deletions pkg/scaling/resolver/scale_resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,56 @@ func TestResolveNonExistingConfigMapsOrSecretsEnv(t *testing.T) {
}
}

func TestResolveAuthRefAndPodIdentity(t *testing.T) {
if err := corev1.AddToScheme(scheme.Scheme); err != nil {
t.Errorf("Expected Error because: %v", err)
}
if err := kedav1alpha1.AddToScheme(scheme.Scheme); err != nil {
t.Errorf("Expected Error because: %v", err)
}
tests := []struct {
name string
existing []runtime.Object
soar *kedav1alpha1.AuthenticationRef
podTemplateSpec *corev1.PodTemplateSpec
expected map[string]string
expectedPodIdentity kedav1alpha1.AuthPodIdentity
expectedError error
}{
// ensure podIdentity is returned
{
name: "foo",
expected: make(map[string]string),
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
}
var secretsLister corev1listers.SecretLister
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
ctx := context.Background()
os.Setenv("KEDA_CLUSTER_OBJECT_NAMESPACE", clusterNamespace) // Inject test cluster namespace.
gotMap, gotPodIdentity, err := ResolveAuthRefAndPodIdentity(
ctx,
fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(test.existing...).Build(),
logf.Log.WithName("test"),
test.soar,
test.podTemplateSpec,
namespace,
secretsLister)
if diff := cmp.Diff(gotMap, test.expected); diff != "" {
t.Errorf("Returned authParams are different: %s", diff)
}
if gotPodIdentity != test.expectedPodIdentity {
t.Errorf("Unexpected podidentity, wanted: %q got: %q", test.expectedPodIdentity.Provider, gotPodIdentity.Provider)
}
if diff := cmp.Diff(err, test.expectedError); diff != "" {
t.Errorf("Returned error is different: %s", diff)
}
})
}
}

func TestResolveAuthRef(t *testing.T) {
if err := corev1.AddToScheme(scheme.Scheme); err != nil {
t.Errorf("Expected Error because: %v", err)
Expand All @@ -258,18 +308,21 @@ func TestResolveAuthRef(t *testing.T) {
comment string
}{
{
name: "foo",
expected: make(map[string]string),
name: "foo",
expected: make(map[string]string),
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "no triggerauth exists",
soar: &kedav1alpha1.AuthenticationRef{Name: "notthere"},
expected: make(map[string]string),
name: "no triggerauth exists",
soar: &kedav1alpha1.AuthenticationRef{Name: "notthere"},
expected: make(map[string]string),
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "no triggerauth exists",
soar: &kedav1alpha1.AuthenticationRef{Name: "notthere"},
expected: make(map[string]string),
name: "no triggerauth exists",
soar: &kedav1alpha1.AuthenticationRef{Name: "notthere"},
expected: make(map[string]string),
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "triggerauth exists, podidentity nil",
Expand All @@ -290,8 +343,9 @@ func TestResolveAuthRef(t *testing.T) {
},
},
},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName},
expected: map[string]string{"host": ""},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName},
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
expected: map[string]string{"host": ""},
},
{
name: "triggerauth exists and secret",
Expand Down Expand Up @@ -358,10 +412,11 @@ func TestResolveAuthRef(t *testing.T) {
},
},
},
isError: true,
comment: "\"my-vault-address-doesnt-exist/v1/auth/token/lookup-self\": unsupported protocol scheme \"\"",
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName},
expected: map[string]string{},
isError: true,
comment: "\"my-vault-address-doesnt-exist/v1/auth/token/lookup-self\": unsupported protocol scheme \"\"",
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName},
expected: map[string]string{},
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "triggerauth exists and config map",
Expand Down Expand Up @@ -461,8 +516,9 @@ func TestResolveAuthRef(t *testing.T) {
},
},
},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName, Kind: "ClusterTriggerAuthentication"},
expected: map[string]string{"host": ""},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName, Kind: "ClusterTriggerAuthentication"},
expected: map[string]string{"host": ""},
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "clustertriggerauth exists and secret",
Expand Down

0 comments on commit 4f9cdc9

Please sign in to comment.