Skip to content

Commit a0cd140

Browse files
committed
Switch to testing that the sorted yaml is equal so that the test results are predictable
1 parent fbe5391 commit a0cd140

14 files changed

+182
-123
lines changed

src/test/java/oracle/kubernetes/operator/create/CreateDomainGeneratedFilesOptionalFeaturesDisabledTest.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
22
package oracle.kubernetes.operator.create;
33

4-
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
4+
import static oracle.kubernetes.operator.create.YamlUtils.*;
55
import static org.hamcrest.MatcherAssert.assertThat;
6-
import static org.hamcrest.Matchers.*;
76
import org.junit.AfterClass;
87
import org.junit.BeforeClass;
98
import org.junit.Test;
@@ -33,73 +32,73 @@ public static void tearDown() throws Exception {
3332

3433
@Test
3534
public void generatesCorrect_createWeblogicDomainYaml_createWeblogicDomainJob() throws Exception {
36-
//System.out.println("MOREAUT_DEBUG create domain job =\n" + YamlUtils.newYaml().dump(generatedFiles.getCreateWeblogicDomainJobYaml().getCreateWeblogicDomainJob()));
35+
//System.out.println("MOREAUT_DEBUG create domain job =\n" + newYaml().dump(generatedFiles.getCreateWeblogicDomainJobYaml().getCreateWeblogicDomainJob()));
3736
// TBD
3837
}
3938

4039
@Test
4140
public void generatesCorrect_createWeblogicDomainYaml_createWeblogicDomainConfigMap() throws Exception {
42-
//System.out.println("MOREAUT_DEBUG create domain config map =\n" + YamlUtils.newYaml().dump(generatedFiles.getCreateWeblogicDomainJobYaml().getCreateWeblogicDomainConfigMap()));
41+
//System.out.println("MOREAUT_DEBUG create domain config map =\n" + newYaml().dump(generatedFiles.getCreateWeblogicDomainJobYaml().getCreateWeblogicDomainConfigMap()));
4342
// TBD
4443
}
4544

4645
@Test
4746
public void generatesCorrect_domainCustomResourceYaml_domain() throws Exception {
48-
//System.out.println("MOREAUT_DEBUG domain custom resource =\n" + YamlUtils.newYaml().dump(generatedFiles.getDomainCustomResourceYaml().getDomain()));
47+
//System.out.println("MOREAUT_DEBUG domain custom resource =\n" + newYaml().dump(generatedFiles.getDomainCustomResourceYaml().getDomain()));
4948
// TBD
5049
}
5150

5251
@Test
5352
public void generatesCorrect_traefikYaml_traefikServiceAccount() throws Exception {
54-
//System.out.println("MOREAUT_DEBUG traefik service account =\n" + YamlUtils.newYaml().dump(generatedFiles.getTraefikYaml().getTraefikServiceAccount()));
53+
//System.out.println("MOREAUT_DEBUG traefik service account =\n" + newYaml().dump(generatedFiles.getTraefikYaml().getTraefikServiceAccount()));
5554
// TBD
5655
}
5756

5857
@Test
5958
public void generatesCorrect_traefikYaml_traefikDeployment() throws Exception {
60-
//System.out.println("MOREAUT_DEBUG traefik deployment =\n" + YamlUtils.newYaml().dump(generatedFiles.getTraefikYaml().getTraefikDeployment()));
59+
//System.out.println("MOREAUT_DEBUG traefik deployment =\n" + newYaml().dump(generatedFiles.getTraefikYaml().getTraefikDeployment()));
6160
// TBD
6261
}
6362

6463
@Test
6564
public void generatesCorrect_traefikYaml_traefikConfigMap() throws Exception {
66-
//System.out.println("MOREAUT_DEBUG traefik config map =\n" + YamlUtils.newYaml().dump(generatedFiles.getTraefikYaml().getTraefikConfigMap()));
65+
//System.out.println("MOREAUT_DEBUG traefik config map =\n" + newYaml().dump(generatedFiles.getTraefikYaml().getTraefikConfigMap()));
6766
// TBD
6867
}
6968

7069
@Test
7170
public void generatesCorrect_traefikYaml_traefikService() throws Exception {
72-
//System.out.println("MOREAUT_DEBUG traefik service =\n" + YamlUtils.newYaml().dump(generatedFiles.getTraefikYaml().getTraefikService()));
71+
//System.out.println("MOREAUT_DEBUG traefik service =\n" + newYaml().dump(generatedFiles.getTraefikYaml().getTraefikService()));
7372
// TBD
7473
}
7574

7675
@Test
7776
public void generatesCorrect_traefikYaml_traefikDashboardService() throws Exception {
78-
//System.out.println("MOREAUT_DEBUG traefik dashboard service =\n" + YamlUtils.newYaml().dump(generatedFiles.getTraefikYaml().getTraefikDashboardService()));
77+
//System.out.println("MOREAUT_DEBUG traefik dashboard service =\n" + newYaml().dump(generatedFiles.getTraefikYaml().getTraefikDashboardService()));
7978
// TBD
8079
}
8180

8281
@Test
8382
public void generatesCorrect_traefikSecurityYaml_traefikClusterRole() throws Exception {
84-
//System.out.println("MOREAUT_DEBUG traefik cluster role =\n" + YamlUtils.newYaml().dump(generatedFiles.getTraefikSecurityYaml().getTraefikClusterRole()));
83+
//System.out.println("MOREAUT_DEBUG traefik cluster role =\n" + newYaml().dump(generatedFiles.getTraefikSecurityYaml().getTraefikClusterRole()));
8584
// TBD
8685
}
8786

8887
@Test
8988
public void generatesCorrect_traefikSecurityYaml_traefikDashboardClusterRoleBinding() throws Exception {
90-
//System.out.println("MOREAUT_DEBUG traefik dashboard cluster role binding =\n" + YamlUtils.newYaml().dump(generatedFiles.getTraefikSecurityYaml().getTraefikDashboardClusterRoleBinding()));
89+
//System.out.println("MOREAUT_DEBUG traefik dashboard cluster role binding =\n" + newYaml().dump(generatedFiles.getTraefikSecurityYaml().getTraefikDashboardClusterRoleBinding()));
9190
// TBD
9291
}
9392

9493
@Test
9594
public void generatesCorrect_weblogicDomainPersistentVolumeYaml_weblogicDomainPersistentVolume() throws Exception {
96-
//System.out.println("MOREAUT_DEBUG weblogic domain persistent volume =\n" + YamlUtils.newYaml().dump(generatedFiles.getWeblogicDomainPersistentVolumeYaml().getWeblogicDomainPersistentVolume()));
95+
//System.out.println("MOREAUT_DEBUG weblogic domain persistent volume =\n" + newYaml().dump(generatedFiles.getWeblogicDomainPersistentVolumeYaml().getWeblogicDomainPersistentVolume()));
9796
// TBD
9897
}
9998

10099
@Test
101100
public void generatesCorrect_weblogicDomainPersistentVolumeClaimYaml_weblogicDomainPersistentVolumeClaim() throws Exception {
102-
//System.out.println("MOREAUT_DEBUG weblogic domain persistent volume claim =\n" + YamlUtils.newYaml().dump(generatedFiles.getWeblogicDomainPersistentVolumeClaimYaml().getWeblogicDomainPersistentVolumeClaim()));
101+
//System.out.println("MOREAUT_DEBUG weblogic domain persistent volume claim =\n" + newYaml().dump(generatedFiles.getWeblogicDomainPersistentVolumeClaimYaml().getWeblogicDomainPersistentVolumeClaim()));
103102
// TBD
104103
}
105104
}

src/test/java/oracle/kubernetes/operator/create/CreateDomainGeneratedFilesOptionalFeaturesEnabledTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
22
package oracle.kubernetes.operator.create;
33

4-
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
4+
import static oracle.kubernetes.operator.create.YamlUtils.*;
55
import static org.hamcrest.MatcherAssert.assertThat;
6-
import static org.hamcrest.Matchers.*;
76
import org.junit.AfterClass;
87
import org.junit.BeforeClass;
98
import org.junit.Test;
@@ -39,13 +38,13 @@ public static void tearDown() throws Exception {
3938

4039
@Test
4140
public void generatesCorrect_createWeblogicDomainYaml_createWeblogicDomainJob() throws Exception {
42-
//System.out.println("MOREAUT_DEBUG create domain job =\n" + YamlUtils.newYaml().dump(generatedFiles.getCreateWeblogicDomainJobYaml().getCreateWeblogicDomainJob()));
41+
//System.out.println("MOREAUT_DEBUG create domain job =\n" + newYaml().dump(generatedFiles.getCreateWeblogicDomainJobYaml().getCreateWeblogicDomainJob()));
4342
// TBD
4443
}
4544

4645
@Test
4746
public void generatesCorrect_domainCustomResourceYaml_domain() throws Exception {
48-
//System.out.println("MOREAUT_DEBUG domain custom resource =\n" + YamlUtils.newYaml().dump(generatedFiles.getDomainCustomResourceYaml().getDomain()));
47+
//System.out.println("MOREAUT_DEBUG domain custom resource =\n" + newYaml().dump(generatedFiles.getDomainCustomResourceYaml().getDomain()));
4948
// TBD
5049
}
5150
}

src/test/java/oracle/kubernetes/operator/create/CreateDomainInputsFileTest.java

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
import java.nio.file.Files;
99

1010
import static oracle.kubernetes.operator.create.CreateDomainInputs.*;
11-
import static oracle.kubernetes.operator.create.ExecCreateDomain.execCreateDomain;
12-
import static oracle.kubernetes.operator.create.ExecResultMatcher.succeedsAndPrints;
11+
import static oracle.kubernetes.operator.create.ExecCreateDomain.*;
12+
import static oracle.kubernetes.operator.create.ExecResultMatcher.*;
13+
import static oracle.kubernetes.operator.create.YamlUtils.*;
1314
import static org.hamcrest.MatcherAssert.assertThat;
1415
import static org.hamcrest.Matchers.*;
1516

@@ -36,34 +37,37 @@ public void tearDown() throws Exception {
3637

3738
@Test
3839
public void defaultInputsFile_hasCorrectContents() throws Exception {
39-
CreateDomainInputs i = readDefaultInputsFile();
40-
assertThat(i.getAdminNodePort(), equalTo("30701"));
41-
assertThat(i.getAdminPort(), equalTo("7001"));
42-
assertThat(i.getAdminServerName(), equalTo("admin-server"));
43-
assertThat(i.getClusterName(), equalTo("cluster-1"));
44-
assertThat(i.getCreateDomainScript(), equalTo("/u01/weblogic/create-domain-script.sh"));
45-
assertThat(i.getDomainName(), equalTo("base_domain"));
46-
assertThat(i.getDomainUid(), equalTo("domain1"));
47-
assertThat(i.getExposeAdminNodePort(), equalTo("false"));
48-
assertThat(i.getExposeAdminT3Channel(), equalTo("false"));
49-
assertThat(i.getImagePullSecretName(), equalTo(""));
50-
assertThat(i.getJavaOptions(), equalTo("-Dweblogic.StdoutDebugEnabled=false"));
51-
assertThat(i.getLoadBalancer(), equalTo("traefik"));
52-
assertThat(i.getLoadBalancerAdminPort(), equalTo("30315"));
53-
assertThat(i.getLoadBalancerWebPort(), equalTo("30305"));
54-
assertThat(i.getManagedServerCount(), equalTo("2"));
55-
assertThat(i.getManagedServerNameBase(), equalTo("managed-server"));
56-
assertThat(i.getManagedServerPort(), equalTo("8001"));
57-
assertThat(i.getManagedServerStartCount(), equalTo("2"));
58-
assertThat(i.getNamespace(), equalTo("default"));
59-
assertThat(i.getPersistencePath(), equalTo("/scratch/k8s_dir/persistentVolume001"));
60-
assertThat(i.getPersistenceSize(), equalTo("10Gi"));
61-
assertThat(i.getPersistenceVolumeClaimName(), equalTo("pv001-claim"));
62-
assertThat(i.getPersistenceVolumeName(), equalTo("pv001"));
63-
assertThat(i.getProductionModeEnabled(), equalTo("true"));
64-
assertThat(i.getSecretName(), equalTo("domain1-weblogic-credentials"));
65-
assertThat(i.getStartupControl(), equalTo("AUTO"));
66-
assertThat(i.getT3ChannelPort(), equalTo("30012"));
40+
assertThat(
41+
readDefaultInputsFile(),
42+
yamlEqualTo((new CreateDomainInputs())
43+
.adminNodePort("30701")
44+
.adminPort("7001")
45+
.adminServerName("admin-server")
46+
.clusterName("cluster-1")
47+
.createDomainScript("/u01/weblogic/create-domain-script.sh")
48+
.domainName("base_domain")
49+
.domainUid("domain1")
50+
.exposeAdminNodePort("false")
51+
.exposeAdminT3Channel("false")
52+
.imagePullSecretName("")
53+
.javaOptions("-Dweblogic.StdoutDebugEnabled=false")
54+
.loadBalancer("traefik")
55+
.loadBalancerAdminPort("30315")
56+
.loadBalancerWebPort("30305")
57+
.managedServerCount("2")
58+
.managedServerNameBase("managed-server")
59+
.managedServerPort("8001")
60+
.managedServerStartCount("2")
61+
.namespace("default")
62+
.persistencePath("/scratch/k8s_dir/persistentVolume001")
63+
.persistenceSize("10Gi")
64+
.persistenceVolumeClaimName("pv001-claim")
65+
.persistenceVolumeName("pv001")
66+
.productionModeEnabled("true")
67+
.secretName("domain1-weblogic-credentials")
68+
.startupControl("AUTO")
69+
.t3ChannelPort("30012")
70+
.t3PublicAddress("kubernetes")));
6771
}
6872

6973
@Test
@@ -72,11 +76,14 @@ public void createDomain_usesSpecifiedInputsFileAndSucceedsAndGeneratesExpectedY
7276
CreateDomainInputs inputs = readDefaultInputsFile().domainUid("test-domain-uid");
7377
assertThat(execCreateDomain(userProjects.getPath(), inputs), succeedsAndPrints("Completed"));
7478
DomainFiles domainFiles = new DomainFiles(userProjects.getPath(), inputs);
79+
assertThat(Files.isRegularFile(domainFiles.getCreateWeblogicDomainInputsYamlPath()), is(true));
7580
assertThat(Files.isRegularFile(domainFiles.getCreateWeblogicDomainJobYamlPath()), is(true));
7681
assertThat(Files.isRegularFile(domainFiles.getDomainCustomResourceYamlPath()), is(true));
7782
assertThat(Files.isRegularFile(domainFiles.getTraefikYamlPath()), is(true));
7883
assertThat(Files.isRegularFile(domainFiles.getTraefikSecurityYamlPath()), is(true));
7984
assertThat(Files.isRegularFile(domainFiles.getWeblogicDomainPersistentVolumeYamlPath()), is(true));
8085
assertThat(Files.isRegularFile(domainFiles.getWeblogicDomainPersistentVolumeClaimYamlPath()), is(true));
86+
// TBD - assert that the generated per-domain directory doesn't contain any extra files?
87+
// TBD - assert that the copy of the inputs in generated per-domain directory matches the origin one
8188
}
8289
}

src/test/java/oracle/kubernetes/operator/create/CreateOperatorGeneratedFilesELKEnabledTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import io.kubernetes.client.models.V1Container;
66

77
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
8+
import static oracle.kubernetes.operator.create.YamlUtils.*;
89
import static org.hamcrest.MatcherAssert.assertThat;
9-
import static org.hamcrest.Matchers.*;
1010
import org.junit.AfterClass;
1111
import org.junit.BeforeClass;
1212
import org.junit.Test;
@@ -62,7 +62,7 @@ public void generatesCorrect_weblogicOperatorYaml_operatorDeployment() throws Ex
6262
.medium("Memory")));
6363
assertThat(
6464
weblogicOperatorYaml().getOperatorDeployment(),
65-
equalTo(want));
65+
yamlEqualTo(want));
6666
}
6767

6868
private ParsedWeblogicOperatorYaml weblogicOperatorYaml() {

src/test/java/oracle/kubernetes/operator/create/CreateOperatorGeneratedFilesExtRestCustomDebugOffTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import org.junit.AfterClass;
55
import org.junit.BeforeClass;
66
import org.junit.Test;
7+
78
import static oracle.kubernetes.operator.create.YamlUtils.*;
89
import static org.hamcrest.MatcherAssert.assertThat;
9-
import static org.hamcrest.Matchers.*;
1010

1111
/**
1212
* Tests that the artifacts in the yaml files that create-weblogic-operator.sh
@@ -35,22 +35,22 @@ public static void tearDown() throws Exception {
3535
public void generatesCorrect_weblogicOperatorYaml_operatorConfigMap() throws Exception {
3636
assertThat(
3737
weblogicOperatorYaml().getOperatorConfigMap(),
38-
equalTo(weblogicOperatorYaml().getExpectedOperatorConfigMap(inputs.externalOperatorCustomCertPem())));
38+
yamlEqualTo(weblogicOperatorYaml().getExpectedOperatorConfigMap(inputs.externalOperatorCustomCertPem())));
3939
}
4040

4141
@Test
4242
public void generatesCorrect_weblogicOperatorYaml_operatorSecrets() throws Exception {
4343
// Need to compare the yamls since Secret.equal only works for the same instance
44-
assertThat_yamlIsEqual(
44+
assertThat(
4545
weblogicOperatorYaml().getOperatorSecrets(),
46-
weblogicOperatorYaml().getExpectedOperatorSecrets(inputs.externalOperatorCustomKeyPem()));
46+
yamlEqualTo(weblogicOperatorYaml().getExpectedOperatorSecrets(inputs.externalOperatorCustomKeyPem())));
4747
}
4848

4949
@Test
5050
public void generatesCorrect_weblogicOperatorYaml_externalOperatorService() throws Exception {
5151
assertThat(
5252
weblogicOperatorYaml().getExternalOperatorService(),
53-
equalTo(weblogicOperatorYaml().getExpectedExternalOperatorService(false, true)));
53+
yamlEqualTo(weblogicOperatorYaml().getExpectedExternalOperatorService(false, true)));
5454
}
5555

5656
private ParsedWeblogicOperatorYaml weblogicOperatorYaml() {

src/test/java/oracle/kubernetes/operator/create/CreateOperatorGeneratedFilesExtRestCustomDebugOnTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
22
package oracle.kubernetes.operator.create;
33

4+
import static oracle.kubernetes.operator.create.YamlUtils.*;
45
import static org.hamcrest.MatcherAssert.assertThat;
5-
import static org.hamcrest.Matchers.*;
66
import org.junit.AfterClass;
77
import org.junit.BeforeClass;
88
import org.junit.Test;
@@ -34,7 +34,7 @@ public static void tearDown() throws Exception {
3434
public void generatesCorrect_weblogicOperatorYaml_externalOperatorService() throws Exception {
3535
assertThat(
3636
weblogicOperatorYaml().getExternalOperatorService(),
37-
equalTo(weblogicOperatorYaml().getExpectedExternalOperatorService(true, true)));
37+
yamlEqualTo(weblogicOperatorYaml().getExpectedExternalOperatorService(true, true)));
3838
}
3939

4040
private ParsedWeblogicOperatorYaml weblogicOperatorYaml() {

0 commit comments

Comments
 (0)