Skip to content

Commit

Permalink
fix: fix assertion test
Browse files Browse the repository at this point in the history
  • Loading branch information
lll-lll-lll-lll authored and AlexVulaj committed May 4, 2024
1 parent be699f4 commit a377fd6
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2238,7 +2238,6 @@ func TestInvalidDefaultElementInSliceRaiseError(t *testing.T) {
d := D{}

data := map[string][]string{}
eng := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

decoder := NewDecoder()

Expand All @@ -2248,17 +2247,20 @@ func TestInvalidDefaultElementInSliceRaiseError(t *testing.T) {
t.Error("if a different type exists, error should be raised")
}

dType := reflect.TypeOf(d)

e, ok := err.(MultiError)
if !ok || len(e) != 14 {
t.Errorf("Expected 14 errors, got %#v", err)
}
for _, v := range eng {
fieldKey := "default-" + string(v)
errMsg := fmt.Sprintf("failed setting default: notInt is not compatible with field %s type", string(v))
if ferr, ok := e[fieldKey]; ok {
if strings.Compare(ferr.Error(), errMsg) != 0 {
t.Errorf("%s: expected %s, got %#v", fieldKey, ferr.Error(), errMsg)
}
if !ok || len(e) != dType.NumField() {
t.Errorf("Expected %d errors, got %#v", dType.NumField(), err)
}

for i := 0; i < dType.NumField(); i++ {
v := dType.Field(i)
fieldKey := "default-" + string(v.Name)
errMsg := fmt.Sprintf("failed setting default: notInt is not compatible with field %s type", string(v.Name))
ferr := e[fieldKey]
if strings.Compare(ferr.Error(), errMsg) != 0 {
t.Errorf("%s: expected %s, got %#v\n", fieldKey, ferr.Error(), errMsg)
}
}
}
Expand Down

0 comments on commit a377fd6

Please sign in to comment.