github.com/hernad/nomad@v1.6.112/nomad/structs/consul_test.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package structs
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/hernad/nomad/ci"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestConsul_Copy(t *testing.T) {
    14  	ci.Parallel(t)
    15  
    16  	t.Run("nil", func(t *testing.T) {
    17  		result := (*Consul)(nil).Copy()
    18  		require.Nil(t, result)
    19  	})
    20  
    21  	t.Run("set", func(t *testing.T) {
    22  		result := (&Consul{
    23  			Namespace: "one",
    24  		}).Copy()
    25  		require.Equal(t, &Consul{Namespace: "one"}, result)
    26  	})
    27  }
    28  
    29  func TestConsul_Equals(t *testing.T) {
    30  	ci.Parallel(t)
    31  
    32  	t.Run("nil and nil", func(t *testing.T) {
    33  		result := (*Consul)(nil).Equal((*Consul)(nil))
    34  		require.True(t, result)
    35  	})
    36  
    37  	t.Run("nil and set", func(t *testing.T) {
    38  		result := (*Consul)(nil).Equal(&Consul{Namespace: "one"})
    39  		require.False(t, result)
    40  	})
    41  
    42  	t.Run("same", func(t *testing.T) {
    43  		result := (&Consul{Namespace: "one"}).Equal(&Consul{Namespace: "one"})
    44  		require.True(t, result)
    45  	})
    46  
    47  	t.Run("different", func(t *testing.T) {
    48  		result := (&Consul{Namespace: "one"}).Equal(&Consul{Namespace: "two"})
    49  		require.False(t, result)
    50  	})
    51  }
    52  
    53  func TestConsul_Validate(t *testing.T) {
    54  	ci.Parallel(t)
    55  
    56  	t.Run("empty ns", func(t *testing.T) {
    57  		result := (&Consul{Namespace: ""}).Validate()
    58  		require.Nil(t, result)
    59  	})
    60  
    61  	t.Run("with ns", func(t *testing.T) {
    62  		result := (&Consul{Namespace: "one"}).Validate()
    63  		require.Nil(t, result)
    64  	})
    65  }