Skip to content

Commit

Permalink
p/u/a/r/useridentitymapping/test:add NamespaceNone
Browse files Browse the repository at this point in the history
Add WithNamespace NamespaceNone as it is now required by upstream.

Signed-off-by: Krzysztof Ostrowski <kostrows@redhat.com>
  • Loading branch information
ibihim committed Sep 13, 2022
1 parent 5eba7e0 commit dd0c134
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions pkg/user/apiserver/registry/useridentitymapping/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ func TestCreate(t *testing.T) {
}

actions, _, _, rest := setupRegistries(unassociatedIdentity, unassociatedUser)
createdMapping, err := rest.Create(apirequest.NewContext(), mapping, apiserverrest.ValidateAllObjectFunc, &metav1.CreateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
createdMapping, err := rest.Create(ctx, mapping, apiserverrest.ValidateAllObjectFunc, &metav1.CreateOptions{})

if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand All @@ -268,7 +269,8 @@ func TestCreateExists(t *testing.T) {
}

actions, _, _, rest := setupRegistries(identity, user)
_, err := rest.Create(apirequest.NewContext(), mapping, apiserverrest.ValidateAllObjectFunc, &metav1.CreateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
_, err := rest.Create(ctx, mapping, apiserverrest.ValidateAllObjectFunc, &metav1.CreateOptions{})

if err == nil {
t.Errorf("Expected error, got none")
Expand All @@ -291,7 +293,8 @@ func TestCreateMissingIdentity(t *testing.T) {
}

actions, _, _, rest := setupRegistries(nil, user)
_, err := rest.Create(apirequest.NewContext(), mapping, apiserverrest.ValidateAllObjectFunc, &metav1.CreateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
_, err := rest.Create(ctx, mapping, apiserverrest.ValidateAllObjectFunc, &metav1.CreateOptions{})

if err == nil {
t.Errorf("Expected error, got none")
Expand All @@ -315,7 +318,8 @@ func TestCreateMissingUser(t *testing.T) {
}

actions, _, _, rest := setupRegistries(identity)
_, err := rest.Create(apirequest.NewContext(), mapping, apiserverrest.ValidateAllObjectFunc, &metav1.CreateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
_, err := rest.Create(ctx, mapping, apiserverrest.ValidateAllObjectFunc, &metav1.CreateOptions{})

if err == nil {
t.Errorf("Expected error, got none")
Expand Down Expand Up @@ -343,7 +347,8 @@ func TestCreateUserUpdateError(t *testing.T) {

actions, userRegistry, _, rest := setupRegistries(unassociatedIdentity, unassociatedUser)
userRegistry.UpdateErr[associatedUser.Name] = expectedErr
_, err := rest.Create(apirequest.NewContext(), mapping, apiserverrest.ValidateAllObjectFunc, &metav1.CreateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
_, err := rest.Create(ctx, mapping, apiserverrest.ValidateAllObjectFunc, &metav1.CreateOptions{})

if err == nil {
t.Errorf("Expected error, got none")
Expand Down Expand Up @@ -371,7 +376,8 @@ func TestCreateIdentityUpdateError(t *testing.T) {

actions, _, identityRegistry, rest := setupRegistries(unassociatedIdentity, unassociatedUser)
identityRegistry.UpdateErr = errors.New("UpdateUser error")
_, err := rest.Create(apirequest.NewContext(), mapping, apiserverrest.ValidateAllObjectFunc, &metav1.CreateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
_, err := rest.Create(ctx, mapping, apiserverrest.ValidateAllObjectFunc, &metav1.CreateOptions{})

if err == nil {
t.Errorf("Expected error, got none")
Expand Down Expand Up @@ -411,7 +417,8 @@ func TestUpdate(t *testing.T) {
}

actions, _, _, rest := setupRegistries(associatedIdentity1User1, associatedUser1, unassociatedUser2)
createdMapping, created, err := rest.Update(apirequest.NewContext(), mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
createdMapping, created, err := rest.Update(ctx, mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})

if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand Down Expand Up @@ -442,7 +449,8 @@ func TestUpdateMissingIdentity(t *testing.T) {
}

actions, _, _, rest := setupRegistries(nil, associatedUser1, unassociatedUser2)
_, _, err := rest.Update(apirequest.NewContext(), mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
_, _, err := rest.Update(ctx, mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})

if err == nil {
t.Errorf("Expected error: %v", err)
Expand Down Expand Up @@ -475,7 +483,8 @@ func TestUpdateMissingUser(t *testing.T) {
}

actions, _, _, rest := setupRegistries(associatedIdentity1User1, associatedUser1)
_, _, err := rest.Update(apirequest.NewContext(), mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
_, _, err := rest.Update(ctx, mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})

if err == nil {
t.Errorf("Expected error: %v", err)
Expand All @@ -502,7 +511,8 @@ func TestUpdateOldUserMatches(t *testing.T) {
}

actions, _, _, rest := setupRegistries(identity, user)
createdMapping, created, err := rest.Update(apirequest.NewContext(), mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
createdMapping, created, err := rest.Update(ctx, mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})

if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand Down Expand Up @@ -533,7 +543,8 @@ func TestUpdateWithEmptyResourceVersion(t *testing.T) {
}

actions, _, _, rest := setupRegistries(associatedIdentity1User1, associatedUser1, unassociatedUser2)
_, _, err := rest.Update(apirequest.NewContext(), mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
_, _, err := rest.Update(ctx, mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})

if err == nil {
t.Errorf("Expected error")
Expand Down Expand Up @@ -564,7 +575,8 @@ func TestUpdateWithMismatchedResourceVersion(t *testing.T) {
}

actions, _, _, rest := setupRegistries(associatedIdentity1User1, associatedUser1, unassociatedUser2)
_, _, err := rest.Update(apirequest.NewContext(), mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
_, _, err := rest.Update(ctx, mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})

if err == nil {
t.Errorf("Expected error")
Expand Down Expand Up @@ -606,7 +618,8 @@ func TestUpdateOldUserUpdateError(t *testing.T) {

actions, userRegistry, _, rest := setupRegistries(associatedIdentity1User1, associatedUser1, unassociatedUser2)
userRegistry.UpdateErr[unassociatedUser1.Name] = expectedErr
createdMapping, created, err := rest.Update(apirequest.NewContext(), mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
createdMapping, created, err := rest.Update(ctx, mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})

// An error cleaning up the old user shouldn't manifest as an update failure, since the mapping was successfully updated
if err != nil {
Expand Down Expand Up @@ -646,7 +659,8 @@ func TestUpdateUserUpdateError(t *testing.T) {

actions, userRegistry, _, rest := setupRegistries(associatedIdentity1User1, associatedUser1, unassociatedUser2)
userRegistry.UpdateErr[associatedUser2.Name] = expectedErr
_, _, err := rest.Update(apirequest.NewContext(), mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
_, _, err := rest.Update(ctx, mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})

if err == nil {
t.Errorf("Expected error")
Expand Down Expand Up @@ -686,7 +700,8 @@ func TestUpdateIdentityUpdateError(t *testing.T) {

actions, _, identityRegistry, rest := setupRegistries(associatedIdentity1User1, associatedUser1, unassociatedUser2)
identityRegistry.UpdateErr = expectedErr
_, _, err := rest.Update(apirequest.NewContext(), mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})
ctx := apirequest.WithNamespace(apirequest.NewContext(), metav1.NamespaceNone)
_, _, err := rest.Update(ctx, mapping.Name, kapirest.DefaultUpdatedObjectInfo(mapping), apiserverrest.ValidateAllObjectFunc, apiserverrest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})

if err == nil {
t.Errorf("Expected error")
Expand Down

0 comments on commit dd0c134

Please sign in to comment.