Skip to content

Commit 3bb6ed7

Browse files
committed
merge main
Signed-off-by: wind57 <[email protected]>
1 parent 6d2c1af commit 3bb6ed7

File tree

1 file changed

+0
-329
lines changed

1 file changed

+0
-329
lines changed

spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigUtilsTests.java

Lines changed: 0 additions & 329 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020
import java.util.Set;
2121

2222
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
23-
<<<<<<< HEAD
24-
import org.junit.jupiter.api.Assertions;
25-
=======
2623
import org.assertj.core.api.Assertions;
27-
import org.junit.jupiter.api.AfterEach;
28-
>>>>>>> fix-1715-drop-profiles-support
2924
import org.junit.jupiter.api.Test;
3025

3126
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
@@ -38,330 +33,6 @@
3833
@EnableKubernetesMockClient(crud = true, https = false)
3934
class Fabric8ConfigUtilsTests {
4035

41-
<<<<<<< HEAD
42-
=======
43-
private KubernetesClient client;
44-
45-
@AfterEach
46-
void afterEach() {
47-
new Fabric8ConfigMapsCache().discardAll();
48-
new Fabric8SecretsCache().discardAll();
49-
}
50-
51-
// secret "my-secret" is deployed without any labels; we search for it by labels
52-
// "color=red" and do not find it.
53-
@Test
54-
void testSecretDataByLabelsSecretNotFound() {
55-
client.secrets()
56-
.inNamespace("spring-k8s")
57-
.resource(new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName("my-secret").build()).build())
58-
.create();
59-
MultipleSourcesContainer result = Fabric8ConfigUtils.secretsDataByLabels(client, "spring-k8s",
60-
Map.of("color", "red"), new MockEnvironment());
61-
Assertions.assertThat(result.data()).isEmpty();
62-
Assertions.assertThat(result.names()).isEmpty();
63-
}
64-
65-
// secret "my-secret" is deployed with label {color:pink}; we search for it by same
66-
// label and find it.
67-
@Test
68-
void testSecretDataByLabelsSecretFound() {
69-
client.secrets()
70-
.inNamespace("spring-k8s")
71-
.resource(new SecretBuilder()
72-
.withMetadata(new ObjectMetaBuilder().withName("my-secret").withLabels(Map.of("color", "pink")).build())
73-
.addToData(Map.of("property", Base64.getEncoder().encodeToString("value".getBytes())))
74-
.build())
75-
.create();
76-
77-
MultipleSourcesContainer result = Fabric8ConfigUtils.secretsDataByLabels(client, "spring-k8s",
78-
Map.of("color", "pink"), new MockEnvironment());
79-
Assertions.assertThat(result.names()).containsExactlyInAnyOrder("my-secret");
80-
Assertions.assertThat(result.data()).containsExactlyInAnyOrderEntriesOf(Map.of("property", "value"));
81-
}
82-
83-
// secret "my-secret" is deployed with label {color:pink}; we search for it by same
84-
// label and find it. This secret contains a single .yaml property, as such
85-
// it gets some special treatment.
86-
@Test
87-
void testSecretDataByLabelsSecretFoundWithPropertyFile() {
88-
client.secrets()
89-
.inNamespace("spring-k8s")
90-
.resource(new SecretBuilder()
91-
.withMetadata(new ObjectMetaBuilder().withName("my-secret").withLabels(Map.of("color", "pink")).build())
92-
.addToData(Map.of(APPLICATION_YAML, Base64.getEncoder().encodeToString("key1: value1".getBytes())))
93-
.build())
94-
.create();
95-
96-
MultipleSourcesContainer result = Fabric8ConfigUtils.secretsDataByLabels(client, "spring-k8s",
97-
Map.of("color", "pink"), new MockEnvironment());
98-
Assertions.assertThat(result.names()).containsExactlyInAnyOrder("my-secret");
99-
Assertions.assertThat(result.data()).containsExactlyInAnyOrderEntriesOf(Map.of("key1", "value1"));
100-
}
101-
102-
// secrets "my-secret" and "my-secret-2" are deployed with label {color:pink};
103-
// we search for them by same label and find them.
104-
@Test
105-
void testSecretDataByLabelsTwoSecretsFound() {
106-
client.secrets()
107-
.inNamespace("spring-k8s")
108-
.resource(new SecretBuilder()
109-
.withMetadata(new ObjectMetaBuilder().withName("my-secret").withLabels(Map.of("color", "pink")).build())
110-
.addToData(Map.of("property", Base64.getEncoder().encodeToString("value".getBytes())))
111-
.build())
112-
.create();
113-
114-
client.secrets()
115-
.inNamespace("spring-k8s")
116-
.resource(new SecretBuilder()
117-
.withMetadata(
118-
new ObjectMetaBuilder().withName("my-secret-2").withLabels(Map.of("color", "pink")).build())
119-
.addToData(Map.of("property-2", Base64.getEncoder().encodeToString("value-2".getBytes())))
120-
.build())
121-
.create();
122-
123-
MultipleSourcesContainer result = Fabric8ConfigUtils.secretsDataByLabels(client, "spring-k8s",
124-
Map.of("color", "pink"), new MockEnvironment());
125-
Assertions.assertThat(result.names()).contains("my-secret");
126-
Assertions.assertThat(result.names()).contains("my-secret-2");
127-
128-
Assertions.assertThat(result.data())
129-
.containsExactlyInAnyOrderEntriesOf(Map.of("property-2", "value-2", "property", "value"));
130-
}
131-
132-
/**
133-
* <pre>
134-
* - secret deployed with name "blue-circle-secret" and labels "color=blue, shape=circle, tag=fit"
135-
* - secret deployed with name "blue-square-secret" and labels "color=blue, shape=square, tag=fit"
136-
* - secret deployed with name "blue-triangle-secret" and labels "color=blue, shape=triangle, tag=no-fit"
137-
* - secret deployed with name "blue-square-secret-k8s" and labels "color=blue, shape=triangle, tag=no-fit"
138-
*
139-
* - we search by labels "color=blue, tag=fits", as such find two secrets: "blue-circle-secret"
140-
* and "blue-square-secret".
141-
* </pre>
142-
*/
143-
@Test
144-
void testSecretDataByLabelsThreeSecretsFound() {
145-
client.secrets()
146-
.inNamespace("spring-k8s")
147-
.resource(new SecretBuilder()
148-
.withMetadata(new ObjectMetaBuilder().withName("blue-circle-secret")
149-
.withLabels(Map.of("color", "blue", "shape", "circle", "tag", "fit"))
150-
.build())
151-
.addToData(Map.of("one", Base64.getEncoder().encodeToString("1".getBytes())))
152-
.build())
153-
.create();
154-
155-
client.secrets()
156-
.inNamespace("spring-k8s")
157-
.resource(new SecretBuilder()
158-
.withMetadata(new ObjectMetaBuilder().withName("blue-square-secret")
159-
.withLabels(Map.of("color", "blue", "shape", "square", "tag", "fit"))
160-
.build())
161-
.addToData(Map.of("two", Base64.getEncoder().encodeToString("2".getBytes())))
162-
.build())
163-
.create();
164-
165-
client.secrets()
166-
.inNamespace("spring-k8s")
167-
.resource(new SecretBuilder()
168-
.withMetadata(new ObjectMetaBuilder().withName("blue-triangle-secret")
169-
.withLabels(Map.of("color", "blue", "shape", "triangle", "tag", "no-fit"))
170-
.build())
171-
.addToData(Map.of("three", Base64.getEncoder().encodeToString("3".getBytes())))
172-
.build())
173-
.create();
174-
175-
client.secrets()
176-
.inNamespace("spring-k8s")
177-
.resource(new SecretBuilder()
178-
.withMetadata(new ObjectMetaBuilder().withName("blue-square-secret-k8s")
179-
.withLabels(Map.of("color", "blue", "shape", "triangle", "tag", "no-fit"))
180-
.build())
181-
.addToData(Map.of("four", Base64.getEncoder().encodeToString("4".getBytes())))
182-
.build())
183-
.create();
184-
185-
MultipleSourcesContainer result = Fabric8ConfigUtils.secretsDataByLabels(client, "spring-k8s",
186-
Map.of("tag", "fit", "color", "blue"), new MockEnvironment());
187-
Assertions.assertThat(result.names()).contains("blue-circle-secret");
188-
Assertions.assertThat(result.names()).contains("blue-square-secret");
189-
Assertions.assertThat(result.names()).contains("blue-square-secret-k8s");
190-
191-
Assertions.assertThat(result.data())
192-
.containsExactlyInAnyOrderEntriesOf(Map.of("one", "1", "two", "2", "four", "4"));
193-
}
194-
195-
// secret "my-secret" is deployed; we search for it by name and do not find it.
196-
@Test
197-
void testSecretDataByNameSecretNotFound() {
198-
client.secrets()
199-
.inNamespace("spring-k8s")
200-
.resource(new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName("my-secret").build()).build())
201-
.create();
202-
LinkedHashSet<String> names = new LinkedHashSet<>();
203-
names.add("nope");
204-
MultipleSourcesContainer result = Fabric8ConfigUtils.secretsDataByName(client, "spring-k8s", names,
205-
new MockEnvironment());
206-
Assertions.assertThat(result.names()).isEmpty();
207-
Assertions.assertThat(result.data()).isEmpty();
208-
}
209-
210-
// secret "my-secret" is deployed; we search for it by name and find it.
211-
@Test
212-
void testSecretDataByNameSecretFound() {
213-
client.secrets()
214-
.inNamespace("spring-k8s")
215-
.resource(new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName("my-secret").build())
216-
.addToData(Map.of("property", Base64.getEncoder().encodeToString("value".getBytes())))
217-
.build())
218-
.create();
219-
LinkedHashSet<String> names = new LinkedHashSet<>();
220-
names.add("my-secret");
221-
222-
MultipleSourcesContainer result = Fabric8ConfigUtils.secretsDataByName(client, "spring-k8s", names,
223-
new MockEnvironment());
224-
Assertions.assertThat(result.names().size()).isEqualTo(1);
225-
Assertions.assertThat(result.data().get("property")).isEqualTo("value");
226-
}
227-
228-
// secrets "my-secret" and "my-secret-2" are deployed;
229-
// we search for them by name label and find them.
230-
@Test
231-
void testSecretDataByNameTwoSecretsFound() {
232-
client.secrets()
233-
.inNamespace("spring-k8s")
234-
.resource(new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName("my-secret").build())
235-
.addToData(Map.of("property", Base64.getEncoder().encodeToString("value".getBytes())))
236-
.build())
237-
.create();
238-
239-
client.secrets()
240-
.inNamespace("spring-k8s")
241-
.resource(new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName("my-secret-2").build())
242-
.addToData(Map.of("property-2", Base64.getEncoder().encodeToString("value-2".getBytes())))
243-
.build())
244-
.create();
245-
LinkedHashSet<String> names = new LinkedHashSet<>();
246-
names.add("my-secret");
247-
names.add("my-secret-2");
248-
249-
MultipleSourcesContainer result = Fabric8ConfigUtils.secretsDataByName(client, "spring-k8s", names,
250-
new MockEnvironment());
251-
Assertions.assertThat(result.names()).contains("my-secret");
252-
Assertions.assertThat(result.names()).contains("my-secret-2");
253-
254-
Assertions.assertThat(result.data().size()).isEqualTo(2);
255-
Assertions.assertThat(result.data().get("property")).isEqualTo("value");
256-
Assertions.assertThat(result.data().get("property-2")).isEqualTo("value-2");
257-
}
258-
259-
// config-map "my-config-map" is deployed without any data; we search for it by name
260-
// and find it; but it has no data.
261-
@Test
262-
void testConfigMapsDataByNameFoundNoData() {
263-
client.configMaps()
264-
.inNamespace("spring-k8s")
265-
.resource(new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map").build())
266-
.build())
267-
.create();
268-
LinkedHashSet<String> names = new LinkedHashSet<>();
269-
names.add("my-config-map");
270-
271-
MultipleSourcesContainer result = Fabric8ConfigUtils.configMapsDataByName(client, "spring-k8s", names,
272-
new MockEnvironment());
273-
Assertions.assertThat(result.names()).containsExactlyInAnyOrder("my-config-map");
274-
Assertions.assertThat(result.data()).isEmpty();
275-
}
276-
277-
// config-map "my-config-map" is deployed; we search for it and do not find it.
278-
@Test
279-
void testConfigMapsDataByNameNotFound() {
280-
client.configMaps()
281-
.inNamespace("spring-k8s")
282-
.resource(new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map").build())
283-
.build())
284-
.create();
285-
LinkedHashSet<String> names = new LinkedHashSet<>();
286-
names.add("my-config-map-not-found");
287-
MultipleSourcesContainer result = Fabric8ConfigUtils.configMapsDataByName(client, "spring-k8s", names,
288-
new MockEnvironment());
289-
Assertions.assertThat(result.names()).isEmpty();
290-
Assertions.assertThat(result.data()).isEmpty();
291-
}
292-
293-
// config-map "my-config-map" is deployed; we search for it and find it
294-
@Test
295-
void testConfigMapDataByNameFound() {
296-
client.configMaps()
297-
.inNamespace("spring-k8s")
298-
.resource(new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map").build())
299-
.addToData(Map.of("property", "value"))
300-
.build())
301-
.create();
302-
303-
LinkedHashSet<String> names = new LinkedHashSet<>();
304-
names.add("my-config-map");
305-
306-
MultipleSourcesContainer result = Fabric8ConfigUtils.configMapsDataByName(client, "spring-k8s", names,
307-
new MockEnvironment());
308-
Assertions.assertThat(result.names()).containsExactlyInAnyOrder("my-config-map");
309-
Assertions.assertThat(result.data()).containsExactlyInAnyOrderEntriesOf(Map.of("property", "value"));
310-
}
311-
312-
// config-map "my-config-map" is deployed; we search for it and find it.
313-
// It contains a single .yaml property, as such it gets some special treatment.
314-
@Test
315-
void testConfigMapDataByNameFoundWithPropertyFile() {
316-
client.configMaps()
317-
.inNamespace("spring-k8s")
318-
.resource(new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map").build())
319-
.addToData(Map.of(APPLICATION_YAML, "key1: value1"))
320-
.build())
321-
.create();
322-
323-
LinkedHashSet<String> names = new LinkedHashSet<>();
324-
names.add("my-config-map");
325-
326-
MultipleSourcesContainer result = Fabric8ConfigUtils.configMapsDataByName(client, "spring-k8s", names,
327-
new MockEnvironment());
328-
Assertions.assertThat(result.names()).containsExactlyInAnyOrder("my-config-map");
329-
Assertions.assertThat(result.data()).containsExactlyInAnyOrderEntriesOf(Map.of("key1", "value1"));
330-
}
331-
332-
// config-map "my-config-map" and "my-config-map-2" are deployed;
333-
// we search and find them.
334-
@Test
335-
void testConfigMapDataByNameTwoFound() {
336-
client.configMaps()
337-
.inNamespace("spring-k8s")
338-
.resource(new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map").build())
339-
.addToData(Map.of("property", "value"))
340-
.build())
341-
.create();
342-
343-
client.configMaps()
344-
.inNamespace("spring-k8s")
345-
.resource(new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("my-config-map-2").build())
346-
.addToData(Map.of("property-2", "value-2"))
347-
.build())
348-
.create();
349-
350-
LinkedHashSet<String> names = new LinkedHashSet<>();
351-
names.add("my-config-map");
352-
names.add("my-config-map-2");
353-
354-
MultipleSourcesContainer result = Fabric8ConfigUtils.configMapsDataByName(client, "spring-k8s", names,
355-
new MockEnvironment());
356-
Assertions.assertThat(result.names()).contains("my-config-map");
357-
Assertions.assertThat(result.names()).contains("my-config-map-2");
358-
359-
Assertions.assertThat(result.data().size()).isEqualTo(2);
360-
Assertions.assertThat(result.data().get("property")).isEqualTo("value");
361-
Assertions.assertThat(result.data().get("property-2")).isEqualTo("value-2");
362-
}
363-
364-
>>>>>>> fix-1715-drop-profiles-support
36536
@Test
36637
void testNamespacesFromProperties() {
36738
ConfigReloadProperties configReloadProperties = new ConfigReloadProperties(false, true, false,

0 commit comments

Comments
 (0)