engine: resources, lang: Set resource fields more accurately

There were some bugs about setting resource fields that were structs
with various fields. This makes things more strict and correct. Now we
check for duplicate field names earlier (duplicates due to identical
aliases) and we also don't try and set private fields, or incorrectly
set partial structs.

Most interestingly, this also cleans up all of the resources and ensures
that each one has nicer docs and a clear struct tag for fields that we
want to use in mcl. These are mandatory now, and if you're missing the
tag, then we will ignore the field.
This commit is contained in:
James Shubin
2023-08-23 00:52:21 -04:00
parent b8d87e2d5a
commit c1850e0e20
24 changed files with 394 additions and 212 deletions

View File

@@ -170,8 +170,8 @@ func TestStructTagToFieldName2(t *testing.T) {
}
type testEngineRes struct {
PublicProp1 string
PublicProp2 map[string][]map[string]int
PublicProp1 string `lang:"PublicProp1" yaml:"PublicProp1"`
PublicProp2 map[string][]map[string]int `lang:"PublicProp2" yaml:"PublicProp2"`
privateProp1 bool
privateProp2 []int
}
@@ -204,11 +204,11 @@ func (t *testEngineRes) Validate() error { return nil }
func (t *testEngineRes) Watch(context.Context) error { return nil }
func TestStructKindToFieldNameTypeMap(t *testing.T) {
func TestLangFieldNameToStructType(t *testing.T) {
k := "test-kind"
engine.RegisterResource(k, func() engine.Res { return &testEngineRes{} })
res, err := StructKindToFieldNameTypeMap(k)
res, err := LangFieldNameToStructType(k)
expected := map[string]*types.Type{
"PublicProp1": types.TypeStr,