forked from jenkinsci/kubernetes-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractGoldenFileTest.java
More file actions
45 lines (37 loc) · 1.74 KB
/
Copy pathAbstractGoldenFileTest.java
File metadata and controls
45 lines (37 loc) · 1.74 KB
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
package org.csanchez.jenkins.plugins.kubernetes;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.umd.cs.findbugs.annotations.NonNull;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.client.utils.Serialization;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.csanchez.jenkins.plugins.kubernetes.pod.decorator.PodDecorator;
import org.junit.jupiter.api.BeforeEach;
abstract class AbstractGoldenFileTest {
protected KubernetesCloud cloud;
protected PodDecorator decorator;
@BeforeEach
void beforeEach() {
decorator = newDecorator();
cloud = new KubernetesCloud("test");
}
protected abstract PodDecorator newDecorator();
protected void test(String name) throws Exception {
var beforeYAML = loadFileAsStream(name + "-before.yaml");
var before = Serialization.unmarshal(beforeYAML, Pod.class);
assertEquals(Serialization.asYaml(before), beforeYAML, name + "-before.yaml is not normalized");
var afterYAML = loadFileAsStream(name + "-after.yaml");
var after = decorator.decorate(cloud, before);
assertEquals(Serialization.asYaml(after), afterYAML, name + "-after.yaml processed");
}
@NonNull
private String loadFileAsStream(String name) throws Exception {
var is = getClass().getResourceAsStream(getClass().getSimpleName() + "/" + name);
if (is == null) {
throw new IllegalStateException("Test file \"src/test/resources/"
+ getClass().getPackageName().replace(".", "/") + "/"
+ getClass().getSimpleName() + "/" + name + "\" not found");
}
return IOUtils.toString(is, StandardCharsets.UTF_8);
}
}