MCPcopy
hub / github.com/opencloud-eu/opencloud / TestTranslateStruct

Function TestTranslateStruct

pkg/l10n/l10n_test.go:9–390  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func 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",

Callers

nothing calls this directly

Calls 7

TranslateFieldFunction · 0.85
TranslateStructFunction · 0.85
TranslateEachFunction · 0.85
mockFunction · 0.85
ErrorfMethod · 0.80
TranslateEntityFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected