|
1 | 1 | package helpers |
2 | 2 |
|
3 | 3 | import ( |
4 | | - opsterv1 "github.com/Opster/opensearch-k8s-operator/opensearch-operator/api/v1" |
| 4 | + opsterv1 "github.com/Opster/opensearch-k8s-operator/opensearch-operator/api/v1" |
5 | 5 | . "github.com/onsi/ginkgo/v2" |
6 | 6 | . "github.com/onsi/gomega" |
7 | 7 | corev1 "k8s.io/api/core/v1" |
@@ -133,4 +133,32 @@ var _ = Describe("Helper Functions", func() { |
133 | 133 | }) |
134 | 134 | }) |
135 | 135 | }) |
| 136 | + |
| 137 | + Describe("MergeConfigs mutation behavior", func() { |
| 138 | + It("should merge the maps such that right is higher priority than left, and not mutate either argument when merging", func() { |
| 139 | + generalConfig := map[string]string{"http.compression": "true"} |
| 140 | + poolConfig := map[string]string{"node.data": "false"} |
| 141 | + |
| 142 | + // Save a copy of the original |
| 143 | + original := map[string]string{"http.compression": "true"} |
| 144 | + |
| 145 | + // Merge and check result |
| 146 | + merged := MergeConfigs(generalConfig, poolConfig) |
| 147 | + expected := map[string]string{"http.compression": "true", "node.data": "false"} |
| 148 | + Expect(merged).To(Equal(expected)) |
| 149 | + |
| 150 | + // Check that longLived was not mutated |
| 151 | + Expect(generalConfig).To(Equal(original)) |
| 152 | + |
| 153 | + // Merge again with a new config |
| 154 | + poolConfig2 := map[string]string{"node.master": "false", "http.compression": "false"} |
| 155 | + expected2 := map[string]string{"http.compression": "false", "node.master": "false"} |
| 156 | + merged2 := MergeConfigs(generalConfig, poolConfig2) |
| 157 | + Expect(merged2).To(Equal(expected2)) |
| 158 | + |
| 159 | + // Still not mutated |
| 160 | + Expect(generalConfig).To(Equal(original)) |
| 161 | + }) |
| 162 | + }) |
| 163 | + |
136 | 164 | }) |
0 commit comments