Skip to content

Commit

Permalink
Fix the test
Browse files Browse the repository at this point in the history
Fix the test

Signed-off-by: kevin <tengkang@msn.com>
  • Loading branch information
kevinteng525 committed Sep 20, 2022
1 parent 1f5a85d commit 6c29648
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/scaling/resolver/scale_resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ package resolver

import (
"context"
"os"
"testing"

"github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
corev1listers "k8s.io/client-go/listers/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
logf "sigs.k8s.io/controller-runtime/pkg/log"

Expand Down Expand Up @@ -146,9 +148,10 @@ var testMetadatas = []testMetadata{
}

func TestResolveNonExistingConfigMapsOrSecretsEnv(t *testing.T) {
var secretsLister corev1listers.SecretLister
for _, testData := range testMetadatas {
ctx := context.Background()
_, err := resolveEnv(ctx, fake.NewClientBuilder().Build(), logf.Log.WithName("test"), testData.container, namespace)
_, err := resolveEnv(ctx, fake.NewClientBuilder().Build(), logf.Log.WithName("test"), testData.container, namespace, secretsLister)

if err != nil && !testData.isError {
t.Errorf("Expected success because %s got error, %s", testData.comment, err)
Expand Down Expand Up @@ -327,18 +330,20 @@ func TestResolveAuthRef(t *testing.T) {
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()
clusterObjectNamespaceCache = &clusterNamespace // Inject test cluster namespace.
os.Setenv("KEDA_CLUSTER_OBJECT_NAMESPACE", clusterNamespace) // Inject test cluster namespace.
gotMap, gotPodIdentity := resolveAuthRef(
ctx,
fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(test.existing...).Build(),
logf.Log.WithName("test"),
test.soar,
test.podSpec,
namespace)
namespace,
secretsLister)
if diff := cmp.Diff(gotMap, test.expected); diff != "" {
t.Errorf("Returned authParams are different: %s", diff)
}
Expand Down Expand Up @@ -452,11 +457,12 @@ func TestResolveDependentEnv(t *testing.T) {
},
},
}
var secretsLister corev1listers.SecretLister
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
ctx := context.Background()
envMap, _ := resolveEnv(ctx, fake.NewClientBuilder().Build(), logf.Log.WithName("test"), test.container, namespace)
envMap, _ := resolveEnv(ctx, fake.NewClientBuilder().Build(), logf.Log.WithName("test"), test.container, namespace, secretsLister)
if diff := cmp.Diff(envMap, test.expected); diff != "" {
t.Errorf("Returned authParams are different: %s", diff)
}
Expand Down

0 comments on commit 6c29648

Please sign in to comment.