github.com/hernad/nomad@v1.6.112/command/agent/consul/self_test.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package consul
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/hernad/nomad/ci"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  var (
    14  	ossFeatures = Features{
    15  		Enterprise: false,
    16  		Namespaces: false,
    17  	}
    18  )
    19  
    20  func TestSelf_SKU(t *testing.T) {
    21  	ci.Parallel(t)
    22  
    23  	t.Run("oss", func(t *testing.T) {
    24  		s, ok := SKU(Self{
    25  			"Config": {"Version": "v1.9.5"},
    26  		})
    27  		require.True(t, ok)
    28  		require.Equal(t, "oss", s)
    29  	})
    30  
    31  	t.Run("oss dev", func(t *testing.T) {
    32  		s, ok := SKU(Self{
    33  			"Config": {"Version": "v1.9.5-dev"},
    34  		})
    35  		require.True(t, ok)
    36  		require.Equal(t, "oss", s)
    37  	})
    38  
    39  	t.Run("ent", func(t *testing.T) {
    40  		s, ok := SKU(Self{
    41  			"Config": {"Version": "v1.9.5+ent"},
    42  		})
    43  		require.True(t, ok)
    44  		require.Equal(t, "ent", s)
    45  	})
    46  
    47  	t.Run("ent dev", func(t *testing.T) {
    48  		s, ok := SKU(Self{
    49  			"Config": {"Version": "v1.9.5+ent-dev"},
    50  		})
    51  		require.True(t, ok)
    52  		require.Equal(t, "ent", s)
    53  	})
    54  
    55  	t.Run("missing", func(t *testing.T) {
    56  		_, ok := SKU(Self{
    57  			"Config": {},
    58  		})
    59  		require.False(t, ok)
    60  	})
    61  
    62  	t.Run("malformed", func(t *testing.T) {
    63  		_, ok := SKU(Self{
    64  			"Config": {"Version": "***"},
    65  		})
    66  		require.False(t, ok)
    67  	})
    68  }
    69  
    70  func TestSelf_Namespaces(t *testing.T) {
    71  	ci.Parallel(t)
    72  
    73  	t.Run("supports namespaces", func(t *testing.T) {
    74  		enabled := Namespaces(Self{
    75  			"Stats": {"license": map[string]interface{}{"features": "Automated Backups, Automated Upgrades, Enhanced Read Scalability, Network Segments, Redundancy Zone, Advanced Network Federation, Namespaces, SSO, Audit Logging"}},
    76  		})
    77  		require.True(t, enabled)
    78  	})
    79  
    80  	t.Run("no namespaces", func(t *testing.T) {
    81  		enabled := Namespaces(Self{
    82  			"Stats": {"license": map[string]interface{}{"features": "Automated Backups, Automated Upgrades, Enhanced Read Scalability, Network Segments, Redundancy Zone, Advanced Network Federation, SSO, Audit Logging"}},
    83  		})
    84  		require.False(t, enabled)
    85  	})
    86  
    87  	t.Run("stats missing", func(t *testing.T) {
    88  		enabled := Namespaces(Self{})
    89  		require.False(t, enabled)
    90  	})
    91  
    92  	t.Run("license missing", func(t *testing.T) {
    93  		enabled := Namespaces(Self{"Stats": {}})
    94  		require.False(t, enabled)
    95  	})
    96  
    97  	t.Run("features missing", func(t *testing.T) {
    98  		enabled := Namespaces(Self{"Stats": {"license": map[string]interface{}{}}})
    99  		require.False(t, enabled)
   100  	})
   101  }