2021-06-07 15:54:33 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2021-06-07 15:54:33 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ossFeatures = Features{
|
|
|
|
Enterprise: false,
|
|
|
|
Namespaces: false,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSelf_SKU(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-06-07 15:54:33 +00:00
|
|
|
|
|
|
|
t.Run("oss", func(t *testing.T) {
|
|
|
|
s, ok := SKU(Self{
|
|
|
|
"Config": {"Version": "v1.9.5"},
|
|
|
|
})
|
|
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, "oss", s)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("oss dev", func(t *testing.T) {
|
|
|
|
s, ok := SKU(Self{
|
|
|
|
"Config": {"Version": "v1.9.5-dev"},
|
|
|
|
})
|
|
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, "oss", s)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("ent", func(t *testing.T) {
|
|
|
|
s, ok := SKU(Self{
|
|
|
|
"Config": {"Version": "v1.9.5+ent"},
|
|
|
|
})
|
|
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, "ent", s)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("ent dev", func(t *testing.T) {
|
|
|
|
s, ok := SKU(Self{
|
|
|
|
"Config": {"Version": "v1.9.5+ent-dev"},
|
|
|
|
})
|
|
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, "ent", s)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("missing", func(t *testing.T) {
|
|
|
|
_, ok := SKU(Self{
|
|
|
|
"Config": {},
|
|
|
|
})
|
|
|
|
require.False(t, ok)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("malformed", func(t *testing.T) {
|
|
|
|
_, ok := SKU(Self{
|
|
|
|
"Config": {"Version": "***"},
|
|
|
|
})
|
|
|
|
require.False(t, ok)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSelf_Namespaces(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-06-07 15:54:33 +00:00
|
|
|
|
|
|
|
t.Run("supports namespaces", func(t *testing.T) {
|
2021-06-07 20:22:26 +00:00
|
|
|
enabled := Namespaces(Self{
|
2021-06-07 15:54:33 +00:00
|
|
|
"Stats": {"license": map[string]interface{}{"features": "Automated Backups, Automated Upgrades, Enhanced Read Scalability, Network Segments, Redundancy Zone, Advanced Network Federation, Namespaces, SSO, Audit Logging"}},
|
|
|
|
})
|
2021-06-07 20:22:26 +00:00
|
|
|
require.True(t, enabled)
|
2021-06-07 15:54:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no namespaces", func(t *testing.T) {
|
2021-06-07 20:22:26 +00:00
|
|
|
enabled := Namespaces(Self{
|
2021-06-07 15:54:33 +00:00
|
|
|
"Stats": {"license": map[string]interface{}{"features": "Automated Backups, Automated Upgrades, Enhanced Read Scalability, Network Segments, Redundancy Zone, Advanced Network Federation, SSO, Audit Logging"}},
|
|
|
|
})
|
2021-06-07 20:22:26 +00:00
|
|
|
require.False(t, enabled)
|
2021-06-07 15:54:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("stats missing", func(t *testing.T) {
|
2021-06-07 20:22:26 +00:00
|
|
|
enabled := Namespaces(Self{})
|
|
|
|
require.False(t, enabled)
|
2021-06-07 15:54:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("license missing", func(t *testing.T) {
|
2021-06-07 20:22:26 +00:00
|
|
|
enabled := Namespaces(Self{"Stats": {}})
|
|
|
|
require.False(t, enabled)
|
2021-06-07 15:54:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("features missing", func(t *testing.T) {
|
2021-06-07 20:22:26 +00:00
|
|
|
enabled := Namespaces(Self{"Stats": {"license": map[string]interface{}{}}})
|
|
|
|
require.False(t, enabled)
|
2021-06-07 15:54:33 +00:00
|
|
|
})
|
|
|
|
}
|