1package bpdoc 2 3import ( 4 "reflect" 5 "testing" 6) 7 8type parentProps struct { 9 A string 10 11 Child *childProps 12 13 Mutated *mutatedProps `blueprint:"mutated"` 14} 15 16type childProps struct { 17 B int 18 19 Child *grandchildProps 20} 21 22type grandchildProps struct { 23 C bool 24} 25 26type mutatedProps struct { 27 D int 28} 29 30func TestNestedPropertyStructs(t *testing.T) { 31 parent := parentProps{Child: &childProps{Child: &grandchildProps{}}, Mutated: &mutatedProps{}} 32 33 allStructs := nestedPropertyStructs(reflect.ValueOf(parent)) 34 35 // mutated shouldn't be found because it's a mutated property. 36 expected := []string{"child", "child.child"} 37 if len(allStructs) != len(expected) { 38 t.Errorf("expected %d structs, got %d, all entries: %q", 39 len(expected), len(allStructs), allStructs) 40 } 41 for _, e := range expected { 42 if _, ok := allStructs[e]; !ok { 43 t.Errorf("missing entry %q, all entries: %q", e, allStructs) 44 } 45 } 46} 47