Merge pull request #5580 from XiShanYongYe-Chang/fix-ut-failed-in-federatedresourcequota

fix ut failed in federatedresourcequota
This commit is contained in:
karmada-bot 2024-09-23 12:13:07 +08:00 committed by GitHub
commit 9864a29684
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View File

@ -78,9 +78,11 @@ func (f *fakeValidationDecoder) DecodeRaw(_ runtime.RawExtension, obj runtime.Ob
return nil
}
// sortAndJoinMessages sorts and joins error message parts to ensure consistent ordering.
// normalizedMessages trim the square brackets, and sorted error message parts to ensure consistent ordering.
// This prevents test flakiness caused by varying error message order.
func sortAndJoinMessages(message string) string {
func normalizedMessages(message string) string {
message = strings.TrimLeft(message, "[")
message = strings.TrimRight(message, "]")
parts := strings.Split(message, ", ")
sort.Strings(parts)
return strings.Join(parts, ", ")
@ -421,8 +423,8 @@ func TestValidatingAdmission_Handle(t *testing.T) {
Decoder: tt.decoder,
}
got := v.Handle(context.Background(), tt.req)
got.Result.Message = sortAndJoinMessages(got.Result.Message)
tt.want.Message = sortAndJoinMessages(tt.want.Message)
got.Result.Message = normalizedMessages(got.Result.Message)
tt.want.Message = normalizedMessages(tt.want.Message)
// Extract type and message from the actual response.
gotType := extractResponseType(got)

View File

@ -1,5 +1,5 @@
/*
Copyright 2023 The Karmada Authors.
Copyright 2024 The Karmada Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.