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

     1  package config
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/hashicorp/nomad/ci"
     9  )
    10  
    11  func TestAutopilotConfig_Merge(t *testing.T) {
    12  	ci.Parallel(t)
    13  
    14  	trueValue, falseValue := true, false
    15  
    16  	c1 := &AutopilotConfig{
    17  		CleanupDeadServers:      &falseValue,
    18  		ServerStabilizationTime: 1 * time.Second,
    19  		LastContactThreshold:    1 * time.Second,
    20  		MaxTrailingLogs:         1,
    21  		MinQuorum:               1,
    22  		EnableRedundancyZones:   &trueValue,
    23  		DisableUpgradeMigration: &falseValue,
    24  		EnableCustomUpgrades:    &trueValue,
    25  	}
    26  
    27  	c2 := &AutopilotConfig{
    28  		CleanupDeadServers:      &trueValue,
    29  		ServerStabilizationTime: 2 * time.Second,
    30  		LastContactThreshold:    2 * time.Second,
    31  		MaxTrailingLogs:         2,
    32  		MinQuorum:               2,
    33  		EnableRedundancyZones:   nil,
    34  		DisableUpgradeMigration: nil,
    35  		EnableCustomUpgrades:    nil,
    36  	}
    37  
    38  	e := &AutopilotConfig{
    39  		CleanupDeadServers:      &trueValue,
    40  		ServerStabilizationTime: 2 * time.Second,
    41  		LastContactThreshold:    2 * time.Second,
    42  		MaxTrailingLogs:         2,
    43  		MinQuorum:               2,
    44  		EnableRedundancyZones:   &trueValue,
    45  		DisableUpgradeMigration: &falseValue,
    46  		EnableCustomUpgrades:    &trueValue,
    47  	}
    48  
    49  	result := c1.Merge(c2)
    50  	if !reflect.DeepEqual(result, e) {
    51  		t.Fatalf("bad:\n%#v\n%#v", result, e)
    52  	}
    53  }