Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
komuw committed Feb 22, 2024
1 parent e6f0793 commit ff2b237
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
13 changes: 13 additions & 0 deletions testdata/vars_test/TestCircularRef-DoNotShowPrivateFields.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

[
NAME: github.com/komuw/kama.ClientTestCircularRef
KIND: struct
SIGNATURE: [*kama.ClientTestCircularRef kama.ClientTestCircularRef]
FIELDS: [
Public string
]
METHODS: []
SNIPPET: &ClientTestCircularRef{
Public: "PublicName",
}
]
53 changes: 53 additions & 0 deletions vars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,56 @@ func TestPublicPrivate(t *testing.T) {
})
}
}

type ConfTestCircularRef struct {
Path string
Hclient *http.Client
}

type ClientTestCircularRef struct {
Public string
c *ConfTestCircularRef
s srvTestCircularRef
}

type srvTestCircularRef struct {
cli *ClientTestCircularRef
}

func TestCircularRef(t *testing.T) {
// t.Parallel() // This cannot be ran in Parallel since it mutates a global var.

oldCfg := cfg

x := &ClientTestCircularRef{Public: "PublicName", c: &ConfTestCircularRef{Path: "path", Hclient: http.DefaultClient}}
x.s.cli = x

{ // Set the new config and schedule to return old config.
onceCfg = &sync.Once{}
t.Cleanup(func() {
cfg = oldCfg
})
}

for _, name := range []string{"ShowPrivateFields", "DoNotShowPrivateFields"} {
name := name
tName := fmt.Sprintf("TestCircularRef-%s", name)

t.Run(tName, func(t *testing.T) {
// t.Parallel() // This cannot be ran in Parallel since it mutates a global var.

var res string
switch name {
default:
t.Fatalf("option `%s` is not expected", name)
case "ShowPrivateFields":
res = Dir(x, Config{ShowPrivateFields: true})
case "DoNotShowPrivateFields":
res = Dir(x, Config{ShowPrivateFields: false})
}

path := getDataPath(t, "vars_test.go", tName)
dealWithTestData(t, path, res)
})
}
}

0 comments on commit ff2b237

Please sign in to comment.