(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestTranslateStruct(t *testing.T) { |
| 10 | |
| 11 | type InnerStruct struct { |
| 12 | Description string |
| 13 | DisplayName *string |
| 14 | } |
| 15 | |
| 16 | type TopLevelStruct struct { |
| 17 | Description string |
| 18 | DisplayName *string |
| 19 | SubStruct *InnerStruct |
| 20 | } |
| 21 | |
| 22 | type WrapperStruct struct { |
| 23 | Description string |
| 24 | StructList []*InnerStruct |
| 25 | } |
| 26 | |
| 27 | toStrPointer := func(str string) *string { |
| 28 | return &str |
| 29 | } |
| 30 | |
| 31 | tests := []struct { |
| 32 | name string |
| 33 | entity any |
| 34 | args []TranslateOption |
| 35 | expected any |
| 36 | wantErr bool |
| 37 | }{ |
| 38 | { |
| 39 | name: "top level slice of struct", |
| 40 | entity: []*InnerStruct{ |
| 41 | { |
| 42 | Description: "inner 1", |
| 43 | DisplayName: toStrPointer("innerDisplayName 1"), |
| 44 | }, |
| 45 | { |
| 46 | Description: "inner 2", |
| 47 | DisplayName: toStrPointer("innerDisplayName 2"), |
| 48 | }, |
| 49 | }, |
| 50 | args: []TranslateOption{ |
| 51 | TranslateField("Description"), |
| 52 | TranslateField("DisplayName"), |
| 53 | }, |
| 54 | expected: []*InnerStruct{ |
| 55 | { |
| 56 | Description: "new Inner 1", |
| 57 | DisplayName: toStrPointer("new InnerDisplayName 1"), |
| 58 | }, |
| 59 | { |
| 60 | Description: "new Inner 2", |
| 61 | DisplayName: toStrPointer("new InnerDisplayName 2"), |
| 62 | }, |
| 63 | }, |
| 64 | }, |
| 65 | { |
| 66 | name: "top level slice of string", |
nothing calls this directly
no test coverage detected