Skip to content

Commit

Permalink
Update configmap test per 1.32.0 change in client-go
Browse files Browse the repository at this point in the history
  • Loading branch information
shizuchanw committed Dec 16, 2024
1 parent 9860541 commit 4afdfe0
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions pkg/mapper/configmap/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"testing"
"time"

core_v1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"

v1 "k8s.io/client-go/kubernetes/typed/core/v1"
corev1 "k8s.io/client-go/applyconfigurations/core/v1"
gentype "k8s.io/client-go/gentype"
typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/kubernetes/typed/core/v1/fake"
k8stesting "k8s.io/client-go/testing"
"sigs.k8s.io/aws-iam-authenticator/pkg/config"
Expand All @@ -30,14 +32,14 @@ func makeStore() MapStore {
return ms
}

func makeStoreWClient() (MapStore, *fake.FakeConfigMaps) {
fakeConfigMaps := &fake.FakeConfigMaps{}
fakeConfigMaps.Fake = &fake.FakeCoreV1{}
fakeConfigMaps.Fake.Fake = &k8stesting.Fake{}
func makeStoreWClient() (MapStore, *fakeConfigMaps) {
fakeCore := &fake.FakeCoreV1{}
fakeCore.Fake = &k8stesting.Fake{}
fakeConfigMaps := newFakeConfigMaps(fakeCore, "")
ms := MapStore{
users: make(map[string]config.UserMapping),
roles: make(map[string]config.RoleMapping),
configMap: v1.ConfigMapInterface(fakeConfigMaps),
configMap: typedcorev1.ConfigMapInterface(fakeConfigMaps),
}
return ms, fakeConfigMaps
}
Expand Down Expand Up @@ -168,7 +170,7 @@ func TestLoadConfigMap(t *testing.T) {
data["mapRoles"] = roleMapping
data["mapAccounts"] = autoMappedAWSAccountsYAML

watcher.Add(&core_v1.ConfigMap{ObjectMeta: meta, Data: data})
watcher.Add(&v1.ConfigMap{ObjectMeta: meta, Data: data})

time.Sleep(2 * time.Millisecond)

Expand Down Expand Up @@ -198,7 +200,7 @@ func TestLoadConfigMap(t *testing.T) {
updateData["mapUsers"] = updatedUserMapping
updateData["mapRoles"] = updatedRoleMapping
updateData["mapAccounts"] = updatedAWSAccountsYAML
watcher.Modify(&core_v1.ConfigMap{ObjectMeta: meta, Data: updateData})
watcher.Modify(&v1.ConfigMap{ObjectMeta: meta, Data: updateData})

//TODO: Sync without using sleep
time.Sleep(10 * time.Millisecond)
Expand Down Expand Up @@ -329,3 +331,25 @@ func TestBadParseMapSingleQuote(t *testing.T) {
t.Fatalf("unexpected %v != %v", emptyMap, m2)
}
}

type fakeConfigMaps struct {
*gentype.FakeClientWithListAndApply[*v1.ConfigMap, *v1.ConfigMapList, *corev1.ConfigMapApplyConfiguration]
Fake *fake.FakeCoreV1
}

func newFakeConfigMaps(fake *fake.FakeCoreV1, namespace string) *fakeConfigMaps {
return &fakeConfigMaps{
gentype.NewFakeClientWithListAndApply[*v1.ConfigMap, *v1.ConfigMapList, *corev1.ConfigMapApplyConfiguration](
fake.Fake,
namespace,
v1.SchemeGroupVersion.WithResource("configmaps"),
v1.SchemeGroupVersion.WithKind("ConfigMap"),
func() *v1.ConfigMap { return &v1.ConfigMap{} },
func() *v1.ConfigMapList { return &v1.ConfigMapList{} },
func(dst, src *v1.ConfigMapList) { dst.ListMeta = src.ListMeta },
func(list *v1.ConfigMapList) []*v1.ConfigMap { return gentype.ToPointerSlice(list.Items) },
func(list *v1.ConfigMapList, items []*v1.ConfigMap) { list.Items = gentype.FromPointerSlice(items) },
),
fake,
}
}

0 comments on commit 4afdfe0

Please sign in to comment.