github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/structs/config/vault_test.go (about)

     1  package config
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/hashicorp/nomad/ci"
     9  	"github.com/hashicorp/nomad/helper/pointer"
    10  	"github.com/shoenig/test/must"
    11  )
    12  
    13  func TestVaultConfig_Merge(t *testing.T) {
    14  	ci.Parallel(t)
    15  
    16  	c1 := &VaultConfig{
    17  		Enabled:              pointer.Of(false),
    18  		Token:                "1",
    19  		Role:                 "1",
    20  		AllowUnauthenticated: pointer.Of(true),
    21  		TaskTokenTTL:         "1",
    22  		Addr:                 "1",
    23  		TLSCaFile:            "1",
    24  		TLSCaPath:            "1",
    25  		TLSCertFile:          "1",
    26  		TLSKeyFile:           "1",
    27  		TLSSkipVerify:        pointer.Of(true),
    28  		TLSServerName:        "1",
    29  	}
    30  
    31  	c2 := &VaultConfig{
    32  		Enabled:              pointer.Of(true),
    33  		Token:                "2",
    34  		Role:                 "2",
    35  		AllowUnauthenticated: pointer.Of(false),
    36  		TaskTokenTTL:         "2",
    37  		Addr:                 "2",
    38  		TLSCaFile:            "2",
    39  		TLSCaPath:            "2",
    40  		TLSCertFile:          "2",
    41  		TLSKeyFile:           "2",
    42  		TLSSkipVerify:        nil,
    43  		TLSServerName:        "2",
    44  	}
    45  
    46  	e := &VaultConfig{
    47  		Enabled:              pointer.Of(true),
    48  		Token:                "2",
    49  		Role:                 "2",
    50  		AllowUnauthenticated: pointer.Of(false),
    51  		TaskTokenTTL:         "2",
    52  		Addr:                 "2",
    53  		TLSCaFile:            "2",
    54  		TLSCaPath:            "2",
    55  		TLSCertFile:          "2",
    56  		TLSKeyFile:           "2",
    57  		TLSSkipVerify:        pointer.Of(true),
    58  		TLSServerName:        "2",
    59  	}
    60  
    61  	result := c1.Merge(c2)
    62  	if !reflect.DeepEqual(result, e) {
    63  		t.Fatalf("bad:\n%#v\n%#v", result, e)
    64  	}
    65  }
    66  
    67  func TestVaultConfig_Equals(t *testing.T) {
    68  	ci.Parallel(t)
    69  
    70  	c1 := &VaultConfig{
    71  		Enabled:              pointer.Of(false),
    72  		Token:                "1",
    73  		Role:                 "1",
    74  		Namespace:            "1",
    75  		AllowUnauthenticated: pointer.Of(true),
    76  		TaskTokenTTL:         "1",
    77  		Addr:                 "1",
    78  		ConnectionRetryIntv:  time.Second,
    79  		TLSCaFile:            "1",
    80  		TLSCaPath:            "1",
    81  		TLSCertFile:          "1",
    82  		TLSKeyFile:           "1",
    83  		TLSSkipVerify:        pointer.Of(true),
    84  		TLSServerName:        "1",
    85  	}
    86  
    87  	c2 := &VaultConfig{
    88  		Enabled:              pointer.Of(false),
    89  		Token:                "1",
    90  		Role:                 "1",
    91  		Namespace:            "1",
    92  		AllowUnauthenticated: pointer.Of(true),
    93  		TaskTokenTTL:         "1",
    94  		Addr:                 "1",
    95  		ConnectionRetryIntv:  time.Second,
    96  		TLSCaFile:            "1",
    97  		TLSCaPath:            "1",
    98  		TLSCertFile:          "1",
    99  		TLSKeyFile:           "1",
   100  		TLSSkipVerify:        pointer.Of(true),
   101  		TLSServerName:        "1",
   102  	}
   103  
   104  	must.Equal(t, c1, c2)
   105  
   106  	c3 := &VaultConfig{
   107  		Enabled:              pointer.Of(true),
   108  		Token:                "1",
   109  		Role:                 "1",
   110  		Namespace:            "1",
   111  		AllowUnauthenticated: pointer.Of(true),
   112  		TaskTokenTTL:         "1",
   113  		Addr:                 "1",
   114  		ConnectionRetryIntv:  time.Second,
   115  		TLSCaFile:            "1",
   116  		TLSCaPath:            "1",
   117  		TLSCertFile:          "1",
   118  		TLSKeyFile:           "1",
   119  		TLSSkipVerify:        pointer.Of(true),
   120  		TLSServerName:        "1",
   121  	}
   122  
   123  	c4 := &VaultConfig{
   124  		Enabled:              pointer.Of(false),
   125  		Token:                "1",
   126  		Role:                 "1",
   127  		Namespace:            "1",
   128  		AllowUnauthenticated: pointer.Of(true),
   129  		TaskTokenTTL:         "1",
   130  		Addr:                 "1",
   131  		ConnectionRetryIntv:  time.Second,
   132  		TLSCaFile:            "1",
   133  		TLSCaPath:            "1",
   134  		TLSCertFile:          "1",
   135  		TLSKeyFile:           "1",
   136  		TLSSkipVerify:        pointer.Of(true),
   137  		TLSServerName:        "1",
   138  	}
   139  
   140  	must.NotEqual(t, c3, c4)
   141  }