connect/native: update connect native hook tests

This commit is contained in:
Seth Hoenig 2020-06-23 12:07:35 -05:00
parent c5d3f58bee
commit 6154181a64
1 changed files with 18 additions and 14 deletions

View File

@ -148,9 +148,9 @@ func TestConnectNativeHook_tlsEnv(t *testing.T) {
result := fullHook.tlsEnv(nil) result := fullHook.tlsEnv(nil)
require.Equal(t, map[string]string{ require.Equal(t, map[string]string{
// ca files are specifically copied into FS namespace // ca files are specifically copied into FS namespace
"CONSUL_CACERT": "/secrets/consul_ca_file", "CONSUL_CACERT": "/secrets/consul_ca_file.pem",
"CONSUL_CLIENT_CERT": "/secrets/consul_cert_file", "CONSUL_CLIENT_CERT": "/secrets/consul_cert_file.pem",
"CONSUL_CLIENT_KEY": "/secrets/consul_key_file", "CONSUL_CLIENT_KEY": "/secrets/consul_key_file.pem",
"CONSUL_HTTP_SSL": "true", "CONSUL_HTTP_SSL": "true",
"CONSUL_HTTP_SSL_VERIFY": "true", "CONSUL_HTTP_SSL_VERIFY": "true",
}, result) }, result)
@ -209,9 +209,10 @@ func TestTaskRunner_ConnectNativeHook_Ok(t *testing.T) {
alloc.AllocatedResources.Shared.Networks = []*structs.NetworkResource{{Mode: "host", IP: "1.1.1.1"}} alloc.AllocatedResources.Shared.Networks = []*structs.NetworkResource{{Mode: "host", IP: "1.1.1.1"}}
tg := alloc.Job.TaskGroups[0] tg := alloc.Job.TaskGroups[0]
tg.Services = []*structs.Service{{ tg.Services = []*structs.Service{{
Name: "cn-service", Name: "cn-service",
TaskName: tg.Tasks[0].Name,
Connect: &structs.ConsulConnect{ Connect: &structs.ConsulConnect{
Native: tg.Tasks[0].Name, Native: true,
}}, }},
} }
tg.Tasks[0].Kind = structs.NewTaskKind("connect-native", "cn-service") tg.Tasks[0].Kind = structs.NewTaskKind("connect-native", "cn-service")
@ -272,9 +273,10 @@ func TestTaskRunner_ConnectNativeHook_with_SI_token(t *testing.T) {
alloc.AllocatedResources.Shared.Networks = []*structs.NetworkResource{{Mode: "host", IP: "1.1.1.1"}} alloc.AllocatedResources.Shared.Networks = []*structs.NetworkResource{{Mode: "host", IP: "1.1.1.1"}}
tg := alloc.Job.TaskGroups[0] tg := alloc.Job.TaskGroups[0]
tg.Services = []*structs.Service{{ tg.Services = []*structs.Service{{
Name: "cn-service", Name: "cn-service",
TaskName: tg.Tasks[0].Name,
Connect: &structs.ConsulConnect{ Connect: &structs.ConsulConnect{
Native: tg.Tasks[0].Name, Native: true,
}}, }},
} }
tg.Tasks[0].Kind = structs.NewTaskKind("connect-native", "cn-service") tg.Tasks[0].Kind = structs.NewTaskKind("connect-native", "cn-service")
@ -347,9 +349,10 @@ func TestTaskRunner_ConnectNativeHook_shareTLS(t *testing.T) {
alloc.AllocatedResources.Shared.Networks = []*structs.NetworkResource{{Mode: "host", IP: "1.1.1.1"}} alloc.AllocatedResources.Shared.Networks = []*structs.NetworkResource{{Mode: "host", IP: "1.1.1.1"}}
tg := alloc.Job.TaskGroups[0] tg := alloc.Job.TaskGroups[0]
tg.Services = []*structs.Service{{ tg.Services = []*structs.Service{{
Name: "cn-service", Name: "cn-service",
TaskName: tg.Tasks[0].Name,
Connect: &structs.ConsulConnect{ Connect: &structs.ConsulConnect{
Native: tg.Tasks[0].Name, Native: true,
}}, }},
} }
tg.Tasks[0].Kind = structs.NewTaskKind("connect-native", "cn-service") tg.Tasks[0].Kind = structs.NewTaskKind("connect-native", "cn-service")
@ -403,9 +406,9 @@ func TestTaskRunner_ConnectNativeHook_shareTLS(t *testing.T) {
// Assert environment variable for token is set // Assert environment variable for token is set
require.NotEmpty(t, response.Env) require.NotEmpty(t, response.Env)
require.Equal(t, map[string]string{ require.Equal(t, map[string]string{
"CONSUL_CACERT": "/secrets/consul_ca_file", "CONSUL_CACERT": "/secrets/consul_ca_file.pem",
"CONSUL_CLIENT_CERT": "/secrets/consul_cert_file", "CONSUL_CLIENT_CERT": "/secrets/consul_cert_file.pem",
"CONSUL_CLIENT_KEY": "/secrets/consul_key_file", "CONSUL_CLIENT_KEY": "/secrets/consul_key_file.pem",
"CONSUL_HTTP_SSL": "true", "CONSUL_HTTP_SSL": "true",
"CONSUL_HTTP_SSL_VERIFY": "true", "CONSUL_HTTP_SSL_VERIFY": "true",
}, response.Env) }, response.Env)
@ -462,9 +465,10 @@ func TestTaskRunner_ConnectNativeHook_shareTLS_override(t *testing.T) {
alloc.AllocatedResources.Shared.Networks = []*structs.NetworkResource{{Mode: "host", IP: "1.1.1.1"}} alloc.AllocatedResources.Shared.Networks = []*structs.NetworkResource{{Mode: "host", IP: "1.1.1.1"}}
tg := alloc.Job.TaskGroups[0] tg := alloc.Job.TaskGroups[0]
tg.Services = []*structs.Service{{ tg.Services = []*structs.Service{{
Name: "cn-service", Name: "cn-service",
TaskName: tg.Tasks[0].Name,
Connect: &structs.ConsulConnect{ Connect: &structs.ConsulConnect{
Native: tg.Tasks[0].Name, Native: true,
}}, }},
} }
tg.Tasks[0].Kind = structs.NewTaskKind("connect-native", "cn-service") tg.Tasks[0].Kind = structs.NewTaskKind("connect-native", "cn-service")