github.com/hernad/nomad@v1.6.112/nomad/structs/check_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  	"time"
     9  
    10  	"github.com/hernad/nomad/ci"
    11  	"github.com/shoenig/test/must"
    12  )
    13  
    14  func TestChecks_NomadCheckID(t *testing.T) {
    15  	ci.Parallel(t)
    16  
    17  	orig := ServiceCheck{
    18  		Name:        "c1",
    19  		Type:        "http",
    20  		Path:        "/health",
    21  		Protocol:    "https",
    22  		PortLabel:   "web",
    23  		AddressMode: "host",
    24  		Interval:    1 * time.Minute,
    25  		Timeout:     10 * time.Second,
    26  		Method:      "GET",
    27  		TaskName:    "t1",
    28  		OnUpdate:    OnUpdateIgnore,
    29  	}
    30  
    31  	different := func(a, b ServiceCheck) bool {
    32  		idA := NomadCheckID("id", "group", &a)
    33  		idB := NomadCheckID("id", "group", &b)
    34  		return idA != idB
    35  	}
    36  
    37  	t.Run("same", func(t *testing.T) {
    38  		c := orig
    39  		must.False(t, different(orig, c))
    40  	})
    41  
    42  	t.Run("different name", func(t *testing.T) {
    43  		c := orig
    44  		c.Name = "c2"
    45  		must.True(t, different(orig, c))
    46  	})
    47  
    48  	t.Run("different type", func(t *testing.T) {
    49  		c := orig
    50  		c.Type = "tcp"
    51  		must.True(t, different(orig, c))
    52  	})
    53  
    54  	t.Run("different path", func(t *testing.T) {
    55  		c := orig
    56  		c.Path = "/metrics"
    57  		must.True(t, different(orig, c))
    58  	})
    59  
    60  	t.Run("different protocol", func(t *testing.T) {
    61  		c := orig
    62  		c.Protocol = "http"
    63  		must.True(t, different(orig, c))
    64  	})
    65  
    66  	t.Run("different port label", func(t *testing.T) {
    67  		c := orig
    68  		c.PortLabel = "ingress"
    69  		must.True(t, different(orig, c))
    70  	})
    71  
    72  	t.Run("different address mode", func(t *testing.T) {
    73  		c := orig
    74  		c.AddressMode = "bridge"
    75  		must.True(t, different(orig, c))
    76  	})
    77  
    78  	t.Run("different interval", func(t *testing.T) {
    79  		c := orig
    80  		c.Interval = 1 * time.Second
    81  		must.True(t, different(orig, c))
    82  	})
    83  
    84  	t.Run("different timeout", func(t *testing.T) {
    85  		c := orig
    86  		c.Timeout = 5 * time.Second
    87  		must.True(t, different(orig, c))
    88  	})
    89  
    90  	t.Run("different method", func(t *testing.T) {
    91  		c := orig
    92  		c.Method = "POST"
    93  		must.True(t, different(orig, c))
    94  	})
    95  
    96  	t.Run("different task", func(t *testing.T) {
    97  		c := orig
    98  		c.TaskName = "task2"
    99  		must.True(t, different(orig, c))
   100  	})
   101  
   102  	t.Run("different on update", func(t *testing.T) {
   103  		c := orig
   104  		c.OnUpdate = "checks"
   105  		must.True(t, different(orig, c))
   106  	})
   107  }