Folders/apiserver: Fix mutate method for folders (#107819)
Signed-off-by: Maicon Costa <maiconscosta@gmail.com>
This commit is contained in:
@@ -236,7 +236,7 @@ func (b *FolderAPIBuilder) Mutate(ctx context.Context, a admission.Attributes, _
|
||||
if !ok {
|
||||
return fmt.Errorf("obj is not folders.Folder")
|
||||
}
|
||||
f.Spec.Title = strings.Trim(f.Spec.Title, "")
|
||||
f.Spec.Title = strings.Trim(f.Spec.Title, " ")
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -479,7 +479,7 @@ func TestFolderAPIBuilder_Mutate_Create(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := b.Validate(context.Background(), admission.NewAttributesRecord(
|
||||
admAttr := admission.NewAttributesRecord(
|
||||
tt.input,
|
||||
nil,
|
||||
folders.SchemeGroupVersion.WithKind("folder"),
|
||||
@@ -491,13 +491,18 @@ func TestFolderAPIBuilder_Mutate_Create(t *testing.T) {
|
||||
nil,
|
||||
true,
|
||||
&user.SignedInUser{},
|
||||
), nil)
|
||||
)
|
||||
|
||||
err := b.Validate(context.Background(), admAttr, nil)
|
||||
if tt.wantErr {
|
||||
require.Error(t, err)
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
err = b.Mutate(context.Background(), admAttr, nil)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tt.input, tt.expected)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -585,7 +590,7 @@ func TestFolderAPIBuilder_Mutate_Update(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := b.Validate(context.Background(), admission.NewAttributesRecord(
|
||||
admAttr := admission.NewAttributesRecord(
|
||||
tt.input,
|
||||
existingObj,
|
||||
folders.SchemeGroupVersion.WithKind("folder"),
|
||||
@@ -597,13 +602,18 @@ func TestFolderAPIBuilder_Mutate_Update(t *testing.T) {
|
||||
nil,
|
||||
true,
|
||||
&user.SignedInUser{},
|
||||
), nil)
|
||||
)
|
||||
|
||||
err := b.Validate(context.Background(), admAttr, nil)
|
||||
if tt.wantErr {
|
||||
require.Error(t, err)
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
err = b.Mutate(context.Background(), admAttr, nil)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tt.input, tt.expected)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user