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

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package consul
     5  
     6  import (
     7  	"encoding/json"
     8  	"testing"
     9  
    10  	"github.com/hernad/nomad/ci"
    11  )
    12  
    13  func TestConsulSupportsTLSSkipVerify(t *testing.T) {
    14  	ci.Parallel(t)
    15  
    16  	assertSupport := func(expected bool, blob string) {
    17  		self := map[string]map[string]interface{}{}
    18  		if err := json.Unmarshal([]byte("{"+blob+"}"), &self); err != nil {
    19  			t.Fatalf("invalid json: %v", err)
    20  		}
    21  		actual := supportsTLSSkipVerify(self)
    22  		if actual != expected {
    23  			t.Errorf("expected %t but got %t for:\n%s\n", expected, actual, blob)
    24  		}
    25  	}
    26  
    27  	// 0.6.4
    28  	assertSupport(false, `"Member": {
    29          "Addr": "127.0.0.1",
    30          "DelegateCur": 4,
    31          "DelegateMax": 4,
    32          "DelegateMin": 2,
    33          "Name": "rusty",
    34          "Port": 8301,
    35          "ProtocolCur": 2,
    36          "ProtocolMax": 3,
    37          "ProtocolMin": 1,
    38          "Status": 1,
    39          "Tags": {
    40              "build": "0.6.4:26a0ef8c",
    41              "dc": "dc1",
    42              "port": "8300",
    43              "role": "consul",
    44              "vsn": "2",
    45              "vsn_max": "3",
    46              "vsn_min": "1"
    47          }}`)
    48  
    49  	// 0.7.0
    50  	assertSupport(false, `"Member": {
    51          "Addr": "127.0.0.1",
    52          "DelegateCur": 4,
    53          "DelegateMax": 4,
    54          "DelegateMin": 2,
    55          "Name": "rusty",
    56          "Port": 8301,
    57          "ProtocolCur": 2,
    58          "ProtocolMax": 4,
    59          "ProtocolMin": 1,
    60          "Status": 1,
    61          "Tags": {
    62              "build": "0.7.0:'a189091",
    63              "dc": "dc1",
    64              "port": "8300",
    65              "role": "consul",
    66              "vsn": "2",
    67              "vsn_max": "3",
    68              "vsn_min": "2"
    69          }}`)
    70  
    71  	// 0.7.2
    72  	assertSupport(true, `"Member": {
    73          "Addr": "127.0.0.1",
    74          "DelegateCur": 4,
    75          "DelegateMax": 4,
    76          "DelegateMin": 2,
    77          "Name": "rusty",
    78          "Port": 8301,
    79          "ProtocolCur": 2,
    80          "ProtocolMax": 5,
    81          "ProtocolMin": 1,
    82          "Status": 1,
    83          "Tags": {
    84              "build": "0.7.2:'a9afa0c",
    85              "dc": "dc1",
    86              "port": "8300",
    87              "role": "consul",
    88              "vsn": "2",
    89              "vsn_max": "3",
    90              "vsn_min": "2"
    91          }}`)
    92  
    93  	// 0.8.1
    94  	assertSupport(true, `"Member": {
    95          "Addr": "127.0.0.1",
    96          "DelegateCur": 4,
    97          "DelegateMax": 5,
    98          "DelegateMin": 2,
    99          "Name": "rusty",
   100          "Port": 8301,
   101          "ProtocolCur": 2,
   102          "ProtocolMax": 5,
   103          "ProtocolMin": 1,
   104          "Status": 1,
   105          "Tags": {
   106              "build": "0.8.1:'e9ca44d",
   107              "dc": "dc1",
   108              "id": "3ddc1b59-460e-a100-1d5c-ce3972122664",
   109              "port": "8300",
   110              "raft_vsn": "2",
   111              "role": "consul",
   112              "vsn": "2",
   113              "vsn_max": "3",
   114              "vsn_min": "2",
   115              "wan_join_port": "8302"
   116          }}`)
   117  }