@@ -17,6 +17,7 @@ limitations under the License.
17
17
package merge_test
18
18
19
19
import (
20
+ "reflect"
20
21
"testing"
21
22
22
23
"sigs.k8s.io/structured-merge-diff/v4/fieldpath"
@@ -92,3 +93,44 @@ func TestToSet(t *testing.T) {
92
93
t .Fatalf ("expected\n %v\n , but got\n %v\n " , expected , actual )
93
94
}
94
95
}
96
+
97
+ func TestConflictsFromManagers (t * testing.T ) {
98
+ type args struct {
99
+ sets fieldpath.ManagedFields
100
+ }
101
+ tests := []struct {
102
+ name string
103
+ args args
104
+ want string
105
+ }{
106
+ {
107
+ name : "test with common prefix" ,
108
+ args : args {
109
+ sets : fieldpath.ManagedFields {
110
+ "Bob" : fieldpath .NewVersionedSet (
111
+ _NS (
112
+ _P ("spec" , "template" , "spec" , "containers" , _KBF ("name" , "probe" ), "livenessProbe" , "exec" , "command" ),
113
+ _P ("spec" , "template" , "spec" , "containers" , _KBF ("name" , "probe" ), "livenessProbe" , "periodSeconds" ),
114
+ _P ("spec" , "template" , "spec" , "containers" , _KBF ("name" , "probe" ), "readinessProbe" , "exec" , "command" ),
115
+ _P ("spec" , "template" , "spec" , "containers" , _KBF ("name" , "probe" ), "readinessProbe" , "periodSeconds" ),
116
+ ),
117
+ "v1" ,
118
+ false ,
119
+ ),
120
+ },
121
+ },
122
+ want : `conflicts with "Bob":
123
+ - .spec.template.spec.containers[name="probe"].livenessProbe.periodSeconds
124
+ - .spec.template.spec.containers[name="probe"].livenessProbe.exec.command
125
+ - .spec.template.spec.containers[name="probe"].readinessProbe.periodSeconds
126
+ - .spec.template.spec.containers[name="probe"].readinessProbe.exec.command` ,
127
+ },
128
+ }
129
+ for _ , tt := range tests {
130
+ t .Run (tt .name , func (t * testing.T ) {
131
+ if got := merge .ConflictsFromManagers (tt .args .sets ); ! reflect .DeepEqual (got .Error (), tt .want ) {
132
+ t .Errorf ("ConflictsFromManagers() = %v, want %v" , got , tt .want )
133
+ }
134
+ })
135
+ }
136
+ }
0 commit comments