2021-03-16 18:22:21 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2022-03-24 08:08:45 +00:00
|
|
|
"time"
|
2021-03-16 18:22:21 +00:00
|
|
|
|
2022-03-17 13:34:57 +00:00
|
|
|
"github.com/hashicorp/nomad/api/internal/testutil"
|
2023-01-01 18:57:26 +00:00
|
|
|
"github.com/shoenig/test/must"
|
2021-03-16 18:22:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConsul_Canonicalize(t *testing.T) {
|
2022-03-17 13:34:57 +00:00
|
|
|
testutil.Parallel(t)
|
2023-01-01 18:57:26 +00:00
|
|
|
|
2021-03-16 18:22:21 +00:00
|
|
|
t.Run("missing ns", func(t *testing.T) {
|
|
|
|
c := new(Consul)
|
|
|
|
c.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, "", c.Namespace)
|
2021-03-16 18:22:21 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("complete", func(t *testing.T) {
|
|
|
|
c := &Consul{Namespace: "foo"}
|
|
|
|
c.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, "foo", c.Namespace)
|
2021-03-16 18:22:21 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsul_Copy(t *testing.T) {
|
2022-03-17 13:34:57 +00:00
|
|
|
testutil.Parallel(t)
|
2023-01-01 18:57:26 +00:00
|
|
|
|
2021-03-16 18:22:21 +00:00
|
|
|
t.Run("complete", func(t *testing.T) {
|
|
|
|
result := (&Consul{
|
|
|
|
Namespace: "foo",
|
|
|
|
}).Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, &Consul{
|
2021-03-16 18:22:21 +00:00
|
|
|
Namespace: "foo",
|
|
|
|
}, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsul_MergeNamespace(t *testing.T) {
|
2022-03-17 13:34:57 +00:00
|
|
|
testutil.Parallel(t)
|
2023-01-01 18:57:26 +00:00
|
|
|
|
2021-03-16 18:22:21 +00:00
|
|
|
t.Run("already set", func(t *testing.T) {
|
|
|
|
a := &Consul{Namespace: "foo"}
|
2022-08-17 16:26:34 +00:00
|
|
|
ns := pointerOf("bar")
|
2021-03-16 18:22:21 +00:00
|
|
|
a.MergeNamespace(ns)
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, "foo", a.Namespace)
|
|
|
|
must.Eq(t, "bar", *ns)
|
2021-03-16 18:22:21 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("inherit", func(t *testing.T) {
|
|
|
|
a := &Consul{Namespace: ""}
|
2022-08-17 16:26:34 +00:00
|
|
|
ns := pointerOf("bar")
|
2021-03-16 18:22:21 +00:00
|
|
|
a.MergeNamespace(ns)
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, "bar", a.Namespace)
|
|
|
|
must.Eq(t, "bar", *ns)
|
2021-03-16 18:22:21 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("parent is nil", func(t *testing.T) {
|
|
|
|
a := &Consul{Namespace: "foo"}
|
|
|
|
ns := (*string)(nil)
|
|
|
|
a.MergeNamespace(ns)
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, "foo", a.Namespace)
|
|
|
|
must.Nil(t, ns)
|
2021-03-16 18:22:21 +00:00
|
|
|
})
|
|
|
|
}
|
2022-03-24 08:08:45 +00:00
|
|
|
|
|
|
|
func TestConsulConnect_Canonicalize(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil connect", func(t *testing.T) {
|
|
|
|
cc := (*ConsulConnect)(nil)
|
|
|
|
cc.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, cc)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty connect", func(t *testing.T) {
|
|
|
|
cc := new(ConsulConnect)
|
|
|
|
cc.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.False(t, cc.Native)
|
|
|
|
must.Nil(t, cc.SidecarService)
|
|
|
|
must.Nil(t, cc.SidecarTask)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsulSidecarService_Canonicalize(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil sidecar_service", func(t *testing.T) {
|
|
|
|
css := (*ConsulSidecarService)(nil)
|
|
|
|
css.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, css)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty sidecar_service", func(t *testing.T) {
|
|
|
|
css := new(ConsulSidecarService)
|
|
|
|
css.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.SliceEmpty(t, css.Tags)
|
|
|
|
must.Nil(t, css.Proxy)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("non-empty sidecar_service", func(t *testing.T) {
|
|
|
|
css := &ConsulSidecarService{
|
|
|
|
Tags: make([]string, 0),
|
|
|
|
Port: "port",
|
|
|
|
Proxy: &ConsulProxy{
|
|
|
|
LocalServiceAddress: "lsa",
|
|
|
|
LocalServicePort: 80,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
css.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, &ConsulSidecarService{
|
2022-03-24 08:08:45 +00:00
|
|
|
Tags: nil,
|
|
|
|
Port: "port",
|
|
|
|
Proxy: &ConsulProxy{
|
|
|
|
LocalServiceAddress: "lsa",
|
|
|
|
LocalServicePort: 80},
|
|
|
|
}, css)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsulProxy_Canonicalize(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil proxy", func(t *testing.T) {
|
|
|
|
cp := (*ConsulProxy)(nil)
|
|
|
|
cp.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, cp)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty proxy", func(t *testing.T) {
|
|
|
|
cp := new(ConsulProxy)
|
|
|
|
cp.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, "", cp.LocalServiceAddress)
|
|
|
|
must.Zero(t, cp.LocalServicePort)
|
2023-01-30 15:31:16 +00:00
|
|
|
must.Nil(t, cp.Expose)
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, cp.Upstreams)
|
|
|
|
must.MapEmpty(t, cp.Config)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("non empty proxy", func(t *testing.T) {
|
|
|
|
cp := &ConsulProxy{
|
|
|
|
LocalServiceAddress: "127.0.0.1",
|
|
|
|
LocalServicePort: 80,
|
2023-01-30 15:31:16 +00:00
|
|
|
Expose: new(ConsulExposeConfig),
|
2022-03-24 08:08:45 +00:00
|
|
|
Upstreams: make([]*ConsulUpstream, 0),
|
|
|
|
Config: make(map[string]interface{}),
|
|
|
|
}
|
|
|
|
cp.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, "127.0.0.1", cp.LocalServiceAddress)
|
|
|
|
must.Eq(t, 80, cp.LocalServicePort)
|
2023-01-30 15:31:16 +00:00
|
|
|
must.Eq(t, &ConsulExposeConfig{}, cp.Expose)
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, cp.Upstreams)
|
|
|
|
must.Nil(t, cp.Config)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsulUpstream_Copy(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil upstream", func(t *testing.T) {
|
|
|
|
cu := (*ConsulUpstream)(nil)
|
|
|
|
result := cu.Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, result)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("complete upstream", func(t *testing.T) {
|
|
|
|
cu := &ConsulUpstream{
|
2022-05-25 20:05:15 +00:00
|
|
|
DestinationName: "dest1",
|
|
|
|
DestinationNamespace: "ns2",
|
|
|
|
Datacenter: "dc2",
|
|
|
|
LocalBindPort: 2000,
|
|
|
|
LocalBindAddress: "10.0.0.1",
|
|
|
|
MeshGateway: &ConsulMeshGateway{Mode: "remote"},
|
2023-01-12 14:20:54 +00:00
|
|
|
Config: map[string]any{"connect_timeout_ms": 5000},
|
2022-03-24 08:08:45 +00:00
|
|
|
}
|
|
|
|
result := cu.Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, cu, result)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsulUpstream_Canonicalize(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil upstream", func(t *testing.T) {
|
|
|
|
cu := (*ConsulUpstream)(nil)
|
|
|
|
cu.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, cu)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("complete", func(t *testing.T) {
|
|
|
|
cu := &ConsulUpstream{
|
2022-05-25 20:05:15 +00:00
|
|
|
DestinationName: "dest1",
|
|
|
|
DestinationNamespace: "ns2",
|
|
|
|
Datacenter: "dc2",
|
|
|
|
LocalBindPort: 2000,
|
|
|
|
LocalBindAddress: "10.0.0.1",
|
|
|
|
MeshGateway: &ConsulMeshGateway{Mode: ""},
|
2023-01-12 14:20:54 +00:00
|
|
|
Config: make(map[string]any),
|
2022-03-24 08:08:45 +00:00
|
|
|
}
|
|
|
|
cu.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, &ConsulUpstream{
|
2022-05-25 20:05:15 +00:00
|
|
|
DestinationName: "dest1",
|
|
|
|
DestinationNamespace: "ns2",
|
|
|
|
Datacenter: "dc2",
|
|
|
|
LocalBindPort: 2000,
|
|
|
|
LocalBindAddress: "10.0.0.1",
|
|
|
|
MeshGateway: &ConsulMeshGateway{Mode: ""},
|
2023-01-12 14:20:54 +00:00
|
|
|
Config: nil,
|
2022-03-24 08:08:45 +00:00
|
|
|
}, cu)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSidecarTask_Canonicalize(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil sidecar_task", func(t *testing.T) {
|
|
|
|
st := (*SidecarTask)(nil)
|
|
|
|
st.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, st)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty sidecar_task", func(t *testing.T) {
|
|
|
|
st := new(SidecarTask)
|
|
|
|
st.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, st.Config)
|
|
|
|
must.Nil(t, st.Env)
|
|
|
|
must.Eq(t, DefaultResources(), st.Resources)
|
|
|
|
must.Eq(t, DefaultLogConfig(), st.LogConfig)
|
|
|
|
must.Nil(t, st.Meta)
|
|
|
|
must.Eq(t, 5*time.Second, *st.KillTimeout)
|
|
|
|
must.Eq(t, 0*time.Second, *st.ShutdownDelay)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("non empty sidecar_task resources", func(t *testing.T) {
|
|
|
|
exp := DefaultResources()
|
2022-08-17 16:26:34 +00:00
|
|
|
exp.MemoryMB = pointerOf(333)
|
2022-03-24 08:08:45 +00:00
|
|
|
st := &SidecarTask{
|
2022-08-17 16:26:34 +00:00
|
|
|
Resources: &Resources{MemoryMB: pointerOf(333)},
|
2022-03-24 08:08:45 +00:00
|
|
|
}
|
|
|
|
st.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, exp, st.Resources)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsulGateway_Canonicalize(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
cg := (*ConsulGateway)(nil)
|
|
|
|
cg.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, cg)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("set defaults", func(t *testing.T) {
|
|
|
|
cg := &ConsulGateway{
|
|
|
|
Proxy: &ConsulGatewayProxy{
|
|
|
|
ConnectTimeout: nil,
|
|
|
|
EnvoyGatewayBindTaggedAddresses: true,
|
|
|
|
EnvoyGatewayBindAddresses: make(map[string]*ConsulGatewayBindAddress, 0),
|
|
|
|
EnvoyGatewayNoDefaultBind: true,
|
|
|
|
Config: make(map[string]interface{}, 0),
|
|
|
|
},
|
|
|
|
Ingress: &ConsulIngressConfigEntry{
|
|
|
|
TLS: &ConsulGatewayTLSConfig{
|
|
|
|
Enabled: false,
|
|
|
|
},
|
|
|
|
Listeners: make([]*ConsulIngressListener, 0),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
cg.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, pointerOf(5*time.Second), cg.Proxy.ConnectTimeout)
|
|
|
|
must.True(t, cg.Proxy.EnvoyGatewayBindTaggedAddresses)
|
|
|
|
must.Nil(t, cg.Proxy.EnvoyGatewayBindAddresses)
|
|
|
|
must.True(t, cg.Proxy.EnvoyGatewayNoDefaultBind)
|
|
|
|
must.Eq(t, "", cg.Proxy.EnvoyDNSDiscoveryType)
|
|
|
|
must.Nil(t, cg.Proxy.Config)
|
|
|
|
must.Nil(t, cg.Ingress.Listeners)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsulGateway_Copy(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
result := (*ConsulGateway)(nil).Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, result)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
gateway := &ConsulGateway{
|
|
|
|
Proxy: &ConsulGatewayProxy{
|
2022-08-17 16:26:34 +00:00
|
|
|
ConnectTimeout: pointerOf(3 * time.Second),
|
2022-03-24 08:08:45 +00:00
|
|
|
EnvoyGatewayBindTaggedAddresses: true,
|
|
|
|
EnvoyGatewayBindAddresses: map[string]*ConsulGatewayBindAddress{
|
|
|
|
"listener1": {Address: "10.0.0.1", Port: 2000},
|
|
|
|
"listener2": {Address: "10.0.0.1", Port: 2001},
|
|
|
|
},
|
|
|
|
EnvoyGatewayNoDefaultBind: true,
|
|
|
|
EnvoyDNSDiscoveryType: "STRICT_DNS",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
"baz": 3,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Ingress: &ConsulIngressConfigEntry{
|
|
|
|
TLS: &ConsulGatewayTLSConfig{
|
|
|
|
Enabled: true,
|
|
|
|
},
|
|
|
|
Listeners: []*ConsulIngressListener{{
|
|
|
|
Port: 3333,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []*ConsulIngressService{{
|
|
|
|
Name: "service1",
|
|
|
|
Hosts: []string{
|
|
|
|
"127.0.0.1", "127.0.0.1:3333",
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Terminating: &ConsulTerminatingConfigEntry{
|
|
|
|
Services: []*ConsulLinkedService{{
|
|
|
|
Name: "linked-service1",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("complete", func(t *testing.T) {
|
|
|
|
result := gateway.Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, gateway, result)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsulIngressConfigEntry_Canonicalize(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
c := (*ConsulIngressConfigEntry)(nil)
|
|
|
|
c.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, c)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty fields", func(t *testing.T) {
|
|
|
|
c := &ConsulIngressConfigEntry{
|
|
|
|
TLS: nil,
|
|
|
|
Listeners: []*ConsulIngressListener{},
|
|
|
|
}
|
|
|
|
c.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, c.TLS)
|
|
|
|
must.Nil(t, c.Listeners)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("complete", func(t *testing.T) {
|
|
|
|
c := &ConsulIngressConfigEntry{
|
|
|
|
TLS: &ConsulGatewayTLSConfig{Enabled: true},
|
|
|
|
Listeners: []*ConsulIngressListener{{
|
|
|
|
Port: 9090,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []*ConsulIngressService{{
|
|
|
|
Name: "service1",
|
|
|
|
Hosts: []string{"1.1.1.1"},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
}
|
|
|
|
c.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, &ConsulIngressConfigEntry{
|
2022-03-24 08:08:45 +00:00
|
|
|
TLS: &ConsulGatewayTLSConfig{Enabled: true},
|
|
|
|
Listeners: []*ConsulIngressListener{{
|
|
|
|
Port: 9090,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []*ConsulIngressService{{
|
|
|
|
Name: "service1",
|
|
|
|
Hosts: []string{"1.1.1.1"},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
}, c)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsulIngressConfigEntry_Copy(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
result := (*ConsulIngressConfigEntry)(nil).Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, result)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
entry := &ConsulIngressConfigEntry{
|
|
|
|
TLS: &ConsulGatewayTLSConfig{
|
|
|
|
Enabled: true,
|
|
|
|
},
|
|
|
|
Listeners: []*ConsulIngressListener{{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []*ConsulIngressService{{
|
|
|
|
Name: "service1",
|
|
|
|
Hosts: []string{"1.1.1.1", "1.1.1.1:9000"},
|
|
|
|
}, {
|
|
|
|
Name: "service2",
|
|
|
|
Hosts: []string{"2.2.2.2"},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("complete", func(t *testing.T) {
|
|
|
|
result := entry.Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, entry, result)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsulTerminatingConfigEntry_Canonicalize(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
c := (*ConsulTerminatingConfigEntry)(nil)
|
|
|
|
c.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, c)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty services", func(t *testing.T) {
|
|
|
|
c := &ConsulTerminatingConfigEntry{
|
|
|
|
Services: []*ConsulLinkedService{},
|
|
|
|
}
|
|
|
|
c.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, c.Services)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsulTerminatingConfigEntry_Copy(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
result := (*ConsulIngressConfigEntry)(nil).Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, result)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
entry := &ConsulTerminatingConfigEntry{
|
|
|
|
Services: []*ConsulLinkedService{{
|
|
|
|
Name: "servic1",
|
|
|
|
}, {
|
|
|
|
Name: "service2",
|
|
|
|
CAFile: "ca_file.pem",
|
|
|
|
CertFile: "cert_file.pem",
|
|
|
|
KeyFile: "key_file.pem",
|
|
|
|
SNI: "sni.terminating.consul",
|
|
|
|
}},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("complete", func(t *testing.T) {
|
|
|
|
result := entry.Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, entry, result)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsulMeshConfigEntry_Canonicalize(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
ce := (*ConsulMeshConfigEntry)(nil)
|
|
|
|
ce.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, ce)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("instantiated", func(t *testing.T) {
|
|
|
|
ce := new(ConsulMeshConfigEntry)
|
|
|
|
ce.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.NotNil(t, ce)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsulMeshConfigEntry_Copy(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
ce := (*ConsulMeshConfigEntry)(nil)
|
|
|
|
ce2 := ce.Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, ce2)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("instantiated", func(t *testing.T) {
|
|
|
|
ce := new(ConsulMeshConfigEntry)
|
|
|
|
ce2 := ce.Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.NotNil(t, ce2)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsulMeshGateway_Canonicalize(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
c := (*ConsulMeshGateway)(nil)
|
|
|
|
c.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, c)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("unset mode", func(t *testing.T) {
|
|
|
|
c := &ConsulMeshGateway{Mode: ""}
|
|
|
|
c.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, "", c.Mode)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("set mode", func(t *testing.T) {
|
|
|
|
c := &ConsulMeshGateway{Mode: "remote"}
|
|
|
|
c.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, "remote", c.Mode)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsulMeshGateway_Copy(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
c := (*ConsulMeshGateway)(nil)
|
|
|
|
result := c.Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, result)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("instantiated", func(t *testing.T) {
|
|
|
|
c := &ConsulMeshGateway{
|
|
|
|
Mode: "local",
|
|
|
|
}
|
|
|
|
result := c.Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, c, result)
|
2022-03-24 08:08:45 +00:00
|
|
|
})
|
|
|
|
}
|
2022-06-02 22:43:58 +00:00
|
|
|
|
|
|
|
func TestConsulGatewayTLSConfig_Copy(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
|
|
|
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
c := (*ConsulGatewayTLSConfig)(nil)
|
|
|
|
result := c.Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Nil(t, result)
|
2022-06-02 22:43:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("enabled", func(t *testing.T) {
|
|
|
|
c := &ConsulGatewayTLSConfig{
|
|
|
|
Enabled: true,
|
|
|
|
}
|
|
|
|
result := c.Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, c, result)
|
2022-06-02 22:43:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("customized", func(t *testing.T) {
|
|
|
|
c := &ConsulGatewayTLSConfig{
|
|
|
|
Enabled: true,
|
|
|
|
TLSMinVersion: "TLSv1_2",
|
|
|
|
TLSMaxVersion: "TLSv1_3",
|
|
|
|
CipherSuites: []string{"foo", "bar"},
|
|
|
|
}
|
|
|
|
result := c.Copy()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, c, result)
|
2022-06-02 22:43:58 +00:00
|
|
|
})
|
|
|
|
}
|