2021-03-16 18:22:21 +00:00
|
|
|
package structs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2021-03-16 18:22:21 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConsul_Copy(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
|
|
|
|
2021-03-16 18:22:21 +00:00
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
result := (*Consul)(nil).Copy()
|
|
|
|
require.Nil(t, result)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("set", func(t *testing.T) {
|
|
|
|
result := (&Consul{
|
|
|
|
Namespace: "one",
|
|
|
|
}).Copy()
|
|
|
|
require.Equal(t, &Consul{Namespace: "one"}, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsul_Equals(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
|
|
|
|
2021-03-16 18:22:21 +00:00
|
|
|
t.Run("nil and nil", func(t *testing.T) {
|
2022-10-10 14:28:46 +00:00
|
|
|
result := (*Consul)(nil).Equal((*Consul)(nil))
|
2021-03-16 18:22:21 +00:00
|
|
|
require.True(t, result)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("nil and set", func(t *testing.T) {
|
2022-10-10 14:28:46 +00:00
|
|
|
result := (*Consul)(nil).Equal(&Consul{Namespace: "one"})
|
2021-03-16 18:22:21 +00:00
|
|
|
require.False(t, result)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("same", func(t *testing.T) {
|
2022-10-10 14:28:46 +00:00
|
|
|
result := (&Consul{Namespace: "one"}).Equal(&Consul{Namespace: "one"})
|
2021-03-16 18:22:21 +00:00
|
|
|
require.True(t, result)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("different", func(t *testing.T) {
|
2022-10-10 14:28:46 +00:00
|
|
|
result := (&Consul{Namespace: "one"}).Equal(&Consul{Namespace: "two"})
|
2021-03-16 18:22:21 +00:00
|
|
|
require.False(t, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConsul_Validate(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
|
|
|
|
2021-03-16 18:22:21 +00:00
|
|
|
t.Run("empty ns", func(t *testing.T) {
|
|
|
|
result := (&Consul{Namespace: ""}).Validate()
|
|
|
|
require.Nil(t, result)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("with ns", func(t *testing.T) {
|
|
|
|
result := (&Consul{Namespace: "one"}).Validate()
|
|
|
|
require.Nil(t, result)
|
|
|
|
})
|
|
|
|
}
|