open-nomad/api/consul_test.go
Seth Hoenig 3943dd1e16 ci: use serial testing for api in CI
This is a followup to running tests in serial in CI.
Since the API package cannot import anything outside of api/,
copy the ci.Parallel function into api/internal/testutil, and
have api tests use that.
2022-03-17 08:35:01 -05:00

63 lines
1.3 KiB
Go

package api
import (
"testing"
"github.com/hashicorp/nomad/api/internal/testutil"
"github.com/stretchr/testify/require"
)
func TestConsul_Canonicalize(t *testing.T) {
testutil.Parallel(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) {
testutil.Parallel(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) {
testutil.Parallel(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)
})
}