github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/structs/config/ui_test.go (about) 1 package config 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/nomad/ci" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestUIConfig_Merge(t *testing.T) { 11 ci.Parallel(t) 12 13 fullConfig := &UIConfig{ 14 Enabled: true, 15 Consul: &ConsulUIConfig{ 16 BaseUIURL: "http://consul.example.com:8500", 17 }, 18 Vault: &VaultUIConfig{ 19 BaseUIURL: "http://vault.example.com:8200", 20 }, 21 } 22 23 testCases := []struct { 24 name string 25 left *UIConfig 26 right *UIConfig 27 expect *UIConfig 28 }{ 29 { 30 name: "merge onto empty config", 31 left: &UIConfig{}, 32 right: fullConfig, 33 expect: fullConfig, 34 }, 35 { 36 name: "merge in a nil config", 37 left: fullConfig, 38 right: nil, 39 expect: fullConfig, 40 }, 41 { 42 name: "merge onto zero-values", 43 left: &UIConfig{ 44 Enabled: false, 45 Consul: &ConsulUIConfig{ 46 BaseUIURL: "http://consul-other.example.com:8500", 47 }, 48 }, 49 right: fullConfig, 50 expect: fullConfig, 51 }, 52 { 53 name: "merge from zero-values", 54 left: &UIConfig{ 55 Enabled: true, 56 Consul: &ConsulUIConfig{ 57 BaseUIURL: "http://consul-other.example.com:8500", 58 }, 59 }, 60 right: &UIConfig{}, 61 expect: &UIConfig{ 62 Enabled: false, 63 Consul: &ConsulUIConfig{ 64 BaseUIURL: "http://consul-other.example.com:8500", 65 }, 66 Vault: &VaultUIConfig{}, 67 }, 68 }, 69 } 70 71 for _, tc := range testCases { 72 tc := tc 73 t.Run(tc.name, func(t *testing.T) { 74 ci.Parallel(t) 75 result := tc.left.Merge(tc.right) 76 require.Equal(t, tc.expect, result) 77 }) 78 } 79 80 }