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

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