agent: add additional tests for defaulting in AddProxy

This commit is contained in:
Mitchell Hashimoto 2018-05-03 12:51:47 -07:00
parent 171bf8d599
commit ba00fa3548
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 56 additions and 5 deletions

View File

@ -2334,6 +2334,14 @@ func TestAgent_AddProxy(t *testing.T) {
t.Parallel() t.Parallel()
a := NewTestAgent(t.Name(), ` a := NewTestAgent(t.Name(), `
node_name = "node1" node_name = "node1"
connect {
proxy_defaults {
exec_mode = "script"
daemon_command = ["foo", "bar"]
script_command = ["bar", "foo"]
}
}
`) `)
defer a.Shutdown() defer a.Shutdown()
@ -2346,7 +2354,7 @@ func TestAgent_AddProxy(t *testing.T) {
tests := []struct { tests := []struct {
desc string desc string
proxy *structs.ConnectManagedProxy proxy, wantProxy *structs.ConnectManagedProxy
wantErr bool wantErr bool
}{ }{
{ {
@ -2374,6 +2382,45 @@ func TestAgent_AddProxy(t *testing.T) {
}, },
wantErr: false, wantErr: false,
}, },
{
desc: "default global exec mode",
proxy: &structs.ConnectManagedProxy{
Command: []string{"consul", "connect", "proxy"},
TargetServiceID: "web",
},
wantProxy: &structs.ConnectManagedProxy{
ExecMode: structs.ProxyExecModeScript,
Command: []string{"consul", "connect", "proxy"},
TargetServiceID: "web",
},
wantErr: false,
},
{
desc: "default daemon command",
proxy: &structs.ConnectManagedProxy{
ExecMode: structs.ProxyExecModeDaemon,
TargetServiceID: "web",
},
wantProxy: &structs.ConnectManagedProxy{
ExecMode: structs.ProxyExecModeDaemon,
Command: []string{"foo", "bar"},
TargetServiceID: "web",
},
wantErr: false,
},
{
desc: "default script command",
proxy: &structs.ConnectManagedProxy{
ExecMode: structs.ProxyExecModeScript,
TargetServiceID: "web",
},
wantProxy: &structs.ConnectManagedProxy{
ExecMode: structs.ProxyExecModeScript,
Command: []string{"bar", "foo"},
TargetServiceID: "web",
},
wantErr: false,
},
} }
for _, tt := range tests { for _, tt := range tests {
@ -2389,8 +2436,12 @@ func TestAgent_AddProxy(t *testing.T) {
// Test the ID was created as we expect. // Test the ID was created as we expect.
got := a.State.Proxy("web-proxy") got := a.State.Proxy("web-proxy")
tt.proxy.ProxyService = got.Proxy.ProxyService wantProxy := tt.wantProxy
require.Equal(tt.proxy, got.Proxy) if wantProxy == nil {
wantProxy = tt.proxy
}
wantProxy.ProxyService = got.Proxy.ProxyService
require.Equal(wantProxy, got.Proxy)
}) })
} }
} }