open-nomad/api/consul_test.go
Seth Hoenig f17ba33f61 consul: plubming for specifying consul namespace in job/group
This PR adds the common OSS changes for adding support for Consul Namespaces,
which is going to be a Nomad Enterprise feature. There is no new functionality
provided by this changeset and hopefully no new bugs.
2021-04-05 10:03:19 -06:00

59 lines
1.2 KiB
Go

package api
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestConsul_Canonicalize(t *testing.T) {
t.Run("missing ns", func(t *testing.T) {
c := new(Consul)
c.Canonicalize()
require.Empty(t, c.Namespace)
})
t.Run("complete", func(t *testing.T) {
c := &Consul{Namespace: "foo"}
c.Canonicalize()
require.Equal(t, "foo", c.Namespace)
})
}
func TestConsul_Copy(t *testing.T) {
t.Run("complete", func(t *testing.T) {
result := (&Consul{
Namespace: "foo",
}).Copy()
require.Equal(t, &Consul{
Namespace: "foo",
}, result)
})
}
func TestConsul_MergeNamespace(t *testing.T) {
t.Run("already set", func(t *testing.T) {
a := &Consul{Namespace: "foo"}
ns := stringToPtr("bar")
a.MergeNamespace(ns)
require.Equal(t, "foo", a.Namespace)
require.Equal(t, "bar", *ns)
})
t.Run("inherit", func(t *testing.T) {
a := &Consul{Namespace: ""}
ns := stringToPtr("bar")
a.MergeNamespace(ns)
require.Equal(t, "bar", a.Namespace)
require.Equal(t, "bar", *ns)
})
t.Run("parent is nil", func(t *testing.T) {
a := &Consul{Namespace: "foo"}
ns := (*string)(nil)
a.MergeNamespace(ns)
require.Equal(t, "foo", a.Namespace)
require.Nil(t, ns)
})
}