1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package types_test
import (
"reflect"
"testing"
. "sigs.k8s.io/kustomize/api/types"
)
func TestMergeGlobalOptionsIntoLocal(t *testing.T) {
tests := []struct {
name string
local *GeneratorOptions
global *GeneratorOptions
expected *GeneratorOptions
}{
{
name: "everything nil",
local: nil,
global: nil,
expected: nil,
},
{
name: "nil global",
local: &GeneratorOptions{
Labels: map[string]string{"pet": "dog"},
Annotations: map[string]string{"fruit": "apple"},
},
global: nil,
expected: &GeneratorOptions{
Labels: map[string]string{"pet": "dog"},
Annotations: map[string]string{"fruit": "apple"},
DisableNameSuffixHash: false,
Immutable: false,
},
},
{
name: "nil local",
local: nil,
global: &GeneratorOptions{
Labels: map[string]string{"pet": "dog"},
Annotations: map[string]string{"fruit": "apple"},
},
expected: &GeneratorOptions{
Labels: map[string]string{"pet": "dog"},
Annotations: map[string]string{"fruit": "apple"},
DisableNameSuffixHash: false,
Immutable: false,
},
},
{
name: "global doesn't damage local",
local: &GeneratorOptions{
Labels: map[string]string{"pet": "dog"},
Annotations: map[string]string{
"fruit": "apple"},
},
global: &GeneratorOptions{
Labels: map[string]string{
"pet": "cat",
"simpson": "homer",
},
Annotations: map[string]string{
"fruit": "peach",
"tesla": "Y",
},
},
expected: &GeneratorOptions{
Labels: map[string]string{
"pet": "dog",
"simpson": "homer",
},
Annotations: map[string]string{
"fruit": "apple",
"tesla": "Y",
},
DisableNameSuffixHash: false,
Immutable: false,
},
},
{
name: "global disable trumps local",
local: &GeneratorOptions{
DisableNameSuffixHash: false,
Immutable: false,
},
global: &GeneratorOptions{
DisableNameSuffixHash: true,
Immutable: true,
},
expected: &GeneratorOptions{
DisableNameSuffixHash: true,
Immutable: true,
},
},
{
name: "local disable works",
local: &GeneratorOptions{
DisableNameSuffixHash: true,
Immutable: true,
},
global: &GeneratorOptions{
DisableNameSuffixHash: false,
Immutable: false,
},
expected: &GeneratorOptions{
DisableNameSuffixHash: true,
Immutable: true,
},
},
{
name: "everyone wants disable",
local: &GeneratorOptions{
DisableNameSuffixHash: true,
Immutable: true,
},
global: &GeneratorOptions{
DisableNameSuffixHash: true,
Immutable: true,
},
expected: &GeneratorOptions{
DisableNameSuffixHash: true,
Immutable: true,
},
},
}
for _, tc := range tests {
actual := MergeGlobalOptionsIntoLocal(tc.local, tc.global)
if !reflect.DeepEqual(tc.expected, actual) {
t.Fatalf("%s annotations: Expected '%v', got '%v'",
tc.name, tc.expected, *actual)
}
}
}
|