Add error message for structs with no ksql tags

pull/10/head
Vinícius Garcia 2021-12-22 22:52:16 -03:00
parent b63990c9f6
commit d9f9d27266
2 changed files with 16 additions and 2 deletions

View File

@ -272,10 +272,12 @@ func getTagNames(t reflect.Type) (StructInfo, error) {
})
}
if len(info.byIndex) > 0 {
info.IsNestedStruct = true
if len(info.byIndex) == 0 {
return StructInfo{}, fmt.Errorf("the struct must contain at least one attribute with the ksql tag")
}
info.IsNestedStruct = true
return info, nil
}

View File

@ -99,6 +99,18 @@ func TestStructToMap(t *testing.T) {
assert.NotEqual(t, nil, err)
})
t.Run("should return error for structs with no ksql tags", func(t *testing.T) {
_, err := StructToMap(struct {
Name string
Age int `json:"age"`
}{
Name: "fake-name",
Age: 42,
})
assert.NotEqual(t, nil, err)
})
}
func TestFillStructWith(t *testing.T) {