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