MCPcopy Index your code
hub / github.com/GoogleCloudPlatform/cloud-sql-proxy / TestNewCommandWithConfigFile

Function TestNewCommandWithConfigFile

cmd/config_test.go:28–156  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26}
27
28func TestNewCommandWithConfigFile(t *testing.T) {
29 tcs := []struct {
30 desc string
31 args []string
32 setup func()
33 assert func(t *testing.T, c *Command)
34 }{
35 {
36 desc: "toml config file",
37 args: []string{"--config-file", "testdata/config-toml.toml"},
38 setup: func() {},
39 assert: func(t *testing.T, c *Command) {
40 assert(t, 1, len(c.conf.Instances))
41 assert(t, true, c.conf.Debug)
42 assert(t, 5555, c.conf.Port)
43 assert(t, true, c.conf.DebugLogs)
44 assert(t, true, c.conf.IAMAuthN)
45 },
46 },
47 {
48 desc: "yaml config file",
49 args: []string{"--config-file", "testdata/config-yaml.yaml"},
50 setup: func() {},
51 assert: func(t *testing.T, c *Command) {
52 assert(t, 1, len(c.conf.Instances))
53 assert(t, true, c.conf.Debug)
54 },
55 },
56 {
57 desc: "json config file",
58 args: []string{"--config-file", "testdata/config-json.json"},
59 setup: func() {},
60 assert: func(t *testing.T, c *Command) {
61 assert(t, 1, len(c.conf.Instances))
62 assert(t, true, c.conf.Debug)
63 },
64 },
65 {
66 desc: "config file with two instances",
67 args: []string{"--config-file", "testdata/two-instances.toml"},
68 setup: func() {},
69 assert: func(t *testing.T, c *Command) {
70 assert(t, 2, len(c.conf.Instances))
71 },
72 },
73 {
74 desc: "instance argument overrides env config precedence",
75 args: []string{"proj:region:inst"},
76 setup: func() {
77 t.Setenv("CSQL_PROXY_INSTANCE_CONNECTION_NAME", "p:r:i")
78 },
79 assert: func(t *testing.T, c *Command) {
80 assert(t, "proj:region:inst", c.conf.Instances[0].Name)
81 },
82 },
83 {
84 desc: "instance env overrides config file precedence",
85 args: []string{"--config-file", "testdata/config-json.json"},

Callers

nothing calls this directly

Calls 2

assertFunction · 0.85
invokeProxyCommandFunction · 0.85

Tested by

no test coverage detected