Skip to content

Commit fa5c2a2

Browse files
committed
Test that only the expected files get generated when creating a domain or operator, remove .yaml-e files created by the create scripts
1 parent 99cae80 commit fa5c2a2

18 files changed

+254
-99
lines changed

kubernetes/internal/create-weblogic-domain.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ function createYamlFiles {
524524
sed -i -e "s:%DOMAIN_UID%:${domainUid}:g" ${traefikSecurityOutput}
525525
sed -i -e "s:%CLUSTER_NAME_LC%:${clusterNameLC}:g" ${traefikSecurityOutput}
526526

527+
# Remove any "...yaml-e" files left over from running sed
528+
rm -f ${domainOutputDir}/*.yaml-e
527529
}
528530

529531
#

kubernetes/internal/create-weblogic-operator.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ function createYamlFiles {
416416
echo Running the weblogic operator security customization script
417417
${genSecPolicyScript} ${serviceAccount} ${namespace} "${targetNamespaces}" -o ${oprSecurityFile}
418418

419+
# Remove any "...yaml-e" files left over from running sed
420+
rm -f ${oprOutputDir}/*.yaml-e
419421
}
420422

421423
#

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,53 @@ public static void tearDown() throws Exception {
8383
}
8484
}
8585

86+
@Test
87+
public void generatedCorrect_weblogicDomainInputsYaml() {
88+
// TBD
89+
}
90+
91+
@Test
92+
public void createWeblogicDomainJobYaml_hasCorrectNumberOfObjects() throws Exception {
93+
assertThat(
94+
getCreateWeblogicDomainJobYaml().getObjectCount(),
95+
is(getCreateWeblogicDomainJobYaml().getExpectedObjectCount()));
96+
}
97+
98+
@Test
99+
public void domainCustomResourceYaml_hasCorrectNumberOfObjects() throws Exception {
100+
assertThat(
101+
getDomainCustomResourceYaml().getObjectCount(),
102+
is(getDomainCustomResourceYaml().getExpectedObjectCount()));
103+
}
104+
105+
@Test
106+
public void traefikSecurityYaml_hasCorrectNumberOfObjects() throws Exception {
107+
assertThat(
108+
getTraefikSecurityYaml().getObjectCount(),
109+
is(getTraefikSecurityYaml().getExpectedObjectCount()));
110+
}
111+
112+
@Test
113+
public void traefikYaml_hasCorrectNumberOfObjects() throws Exception {
114+
assertThat(
115+
getTraefikYaml().getObjectCount(),
116+
is(getTraefikYaml().getExpectedObjectCount()));
117+
}
118+
119+
@Test
120+
public void weblogicDomainPersistentVolumeClaimYaml_hasCorrectNumberOfObjects() throws Exception {
121+
assertThat(
122+
getWeblogicDomainPersistentVolumeClaimYaml().getObjectCount(),
123+
is(getWeblogicDomainPersistentVolumeClaimYaml().getExpectedObjectCount()));
124+
}
125+
126+
@Test
127+
public void weblogicDomainPersistentVolumeYaml_hasCorrectNumberOfObjects() throws Exception {
128+
assertThat(
129+
getWeblogicDomainPersistentVolumeYaml().getObjectCount(),
130+
is(getWeblogicDomainPersistentVolumeYaml().getExpectedObjectCount()));
131+
}
132+
86133
@Test
87134
public void generatesCorrect_createWeblogicDomainJob() throws Exception {
88135
assertThat(

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

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

4+
import java.nio.file.Path;
5+
import java.nio.file.Files;
6+
import java.util.List;
7+
48
import org.junit.After;
59
import org.junit.Before;
610
import org.junit.Test;
7-
8-
import java.nio.file.Files;
9-
1011
import static oracle.kubernetes.operator.create.CreateDomainInputs.*;
1112
import static oracle.kubernetes.operator.create.ExecCreateDomain.*;
1213
import static oracle.kubernetes.operator.create.ExecResultMatcher.*;
@@ -77,15 +78,18 @@ public void createDomain_usesSpecifiedInputsFileAndSucceedsAndGeneratesExpectedY
7778
// customize the domain uid so that we can tell that it generated the yaml files based on this inputs
7879
CreateDomainInputs inputs = readDefaultInputsFile().domainUid("test-domain-uid");
7980
assertThat(execCreateDomain(userProjects.getPath(), inputs), succeedsAndPrints("Completed"));
81+
82+
// Make sure the generated directory has the correct list of files
8083
DomainFiles domainFiles = new DomainFiles(userProjects.getPath(), inputs);
81-
assertThat(Files.isRegularFile(domainFiles.getCreateWeblogicDomainInputsYamlPath()), is(true));
82-
assertThat(Files.isRegularFile(domainFiles.getCreateWeblogicDomainJobYamlPath()), is(true));
83-
assertThat(Files.isRegularFile(domainFiles.getDomainCustomResourceYamlPath()), is(true));
84-
assertThat(Files.isRegularFile(domainFiles.getTraefikYamlPath()), is(true));
85-
assertThat(Files.isRegularFile(domainFiles.getTraefikSecurityYamlPath()), is(true));
86-
assertThat(Files.isRegularFile(domainFiles.getWeblogicDomainPersistentVolumeYamlPath()), is(true));
87-
assertThat(Files.isRegularFile(domainFiles.getWeblogicDomainPersistentVolumeClaimYamlPath()), is(true));
88-
// TBD - assert that the generated per-domain directory doesn't contain any extra files?
89-
// TBD - assert that the copy of the inputs in generated per-domain directory matches the origin one
84+
List<Path> expectedFiles = domainFiles.getExpectedContents(true); // include the directory too
85+
List<Path> actualFiles = userProjects.getContents(domainFiles.getWeblogicDomainPath());
86+
assertThat(
87+
actualFiles,
88+
containsInAnyOrder(expectedFiles.toArray(new Path[expectedFiles.size()])));
89+
90+
// Make sure that the yaml files are regular files
91+
for (Path path : domainFiles.getExpectedContents(false)) { // don't include the directory too
92+
assertThat("Expect that " + path + " is a regular file", Files.isRegularFile(path), is(true));
93+
}
9094
}
9195
}

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

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ protected static GeneratedOperatorYamlFiles getGeneratedFiles() {
3838
return generatedFiles;
3939
}
4040

41-
protected ParsedWeblogicOperatorSecurityYaml weblogicOperatorSecurityYaml() {
41+
protected ParsedWeblogicOperatorSecurityYaml getWeblogicOperatorSecurityYaml() {
4242
return getGeneratedFiles().getWeblogicOperatorSecurityYaml();
4343
}
4444

45-
protected ParsedWeblogicOperatorYaml weblogicOperatorYaml() {
45+
protected ParsedWeblogicOperatorYaml getWeblogicOperatorYaml() {
4646
return getGeneratedFiles().getWeblogicOperatorYaml();
4747
}
4848

@@ -58,6 +58,25 @@ public static void tearDown() throws Exception {
5858
}
5959
}
6060

61+
@Test
62+
public void generatedCorrect_weblogicOperatorInputsYaml() {
63+
// TBD
64+
}
65+
66+
@Test
67+
public void weblogicOperatorYaml_hasCorrectNumberOfObjects() throws Exception {
68+
assertThat(
69+
getWeblogicOperatorYaml().getObjectCount(),
70+
is(getWeblogicOperatorYaml().getExpectedObjectCount()));
71+
}
72+
73+
@Test
74+
public void weblogicOperatorSecurityYaml_hasCorrectNumberOfObjects() throws Exception {
75+
assertThat(
76+
getWeblogicOperatorSecurityYaml().getObjectCount(),
77+
is(getWeblogicOperatorSecurityYaml().getExpectedObjectCount()));
78+
}
79+
6180
@Test
6281
public void generatesCorrect_operatorConfigMap() throws Exception {
6382
assertThat(
@@ -66,7 +85,7 @@ public void generatesCorrect_operatorConfigMap() throws Exception {
6685
}
6786

6887
protected V1ConfigMap getActualWeblogicOperatorConfigMap() {
69-
return weblogicOperatorYaml().getOperatorConfigMap();
88+
return getWeblogicOperatorYaml().getOperatorConfigMap();
7089
}
7190

7291
protected V1ConfigMap getExpectedWeblogicOperatorConfigMap() {
@@ -91,7 +110,7 @@ public void generatesCorrect_operatorSecrets() throws Exception {
91110
}
92111

93112
protected V1Secret getActualWeblogicOperatorSecrets() {
94-
return weblogicOperatorYaml().getOperatorSecrets();
113+
return getWeblogicOperatorYaml().getOperatorSecrets();
95114
}
96115

97116
protected V1Secret getExpectedWeblogicOperatorSecrets() {
@@ -115,7 +134,7 @@ public void generatesCorrect_operatorDeployment() throws Exception {
115134
}
116135

117136
protected ExtensionsV1beta1Deployment getActualWeblogicOperatorDeployment() {
118-
return weblogicOperatorYaml().getOperatorDeployment();
137+
return getWeblogicOperatorYaml().getOperatorDeployment();
119138
}
120139

121140
protected ExtensionsV1beta1Deployment getExpectedWeblogicOperatorDeployment() {
@@ -183,7 +202,7 @@ public void generatesCorrect_externalWeblogicOperatorService() throws Exception
183202
}
184203

185204
protected V1Service getActualExternalWeblogicOperatorService() {
186-
return weblogicOperatorYaml().getExternalOperatorService();
205+
return getWeblogicOperatorYaml().getExternalOperatorService();
187206
}
188207

189208
protected abstract V1Service getExpectedExternalWeblogicOperatorService();
@@ -223,7 +242,7 @@ public void generatesCorrect_internalWeblogicOperatorService() throws Exception
223242
}
224243

225244
protected V1Service getActualInternalWeblogicOperatorService() {
226-
return weblogicOperatorYaml().getInternalOperatorService();
245+
return getWeblogicOperatorYaml().getInternalOperatorService();
227246
}
228247

229248
protected V1Service getExpectedInternalWeblogicOperatorService() {
@@ -248,7 +267,7 @@ public void generatesCorrect_weblogicOperatorNamespace() throws Exception {
248267
}
249268

250269
protected V1Namespace getActualWeblogicOperatorNamespace() {
251-
return weblogicOperatorSecurityYaml().getOperatorNamespace();
270+
return getWeblogicOperatorSecurityYaml().getOperatorNamespace();
252271
}
253272

254273
protected V1Namespace getExpectedWeblogicOperatorNamespace() {
@@ -266,7 +285,7 @@ public void generatesCorrect_weblogicOperatorServiceAccount() throws Exception {
266285
}
267286

268287
protected V1ServiceAccount getActualWeblogicOperatorServiceAccount() {
269-
return weblogicOperatorSecurityYaml().getOperatorServiceAccount();
288+
return getWeblogicOperatorSecurityYaml().getOperatorServiceAccount();
270289
}
271290

272291
protected V1ServiceAccount getExpectedWeblogicOperatorServiceAccount() {
@@ -285,7 +304,7 @@ public void generatesCorrect_weblogicOperatorClusterRole() throws Exception {
285304
}
286305

287306
protected V1beta1ClusterRole getActualWeblogicOperatorClusterRole() {
288-
return weblogicOperatorSecurityYaml().getWeblogicOperatorClusterRole();
307+
return getWeblogicOperatorSecurityYaml().getWeblogicOperatorClusterRole();
289308
}
290309

291310
protected V1beta1ClusterRole getExpectedWeblogicOperatorClusterRole() {
@@ -323,7 +342,7 @@ public void generatesCorrect_weblogicOperatorClusterRoleNonResource() throws Exc
323342
}
324343

325344
protected V1beta1ClusterRole getActualWeblogicOperatorClusterRoleNonResource() {
326-
return weblogicOperatorSecurityYaml().getWeblogicOperatorClusterRoleNonResource();
345+
return getWeblogicOperatorSecurityYaml().getWeblogicOperatorClusterRoleNonResource();
327346
}
328347

329348
protected V1beta1ClusterRole getExpectedWeblogicOperatorClusterRoleNonResource() {
@@ -339,7 +358,7 @@ protected V1beta1ClusterRole getExpectedWeblogicOperatorClusterRoleNonResource()
339358
@Test
340359
public void generatesCorrect_operatorRoleBinding() throws Exception {
341360
assertThat(
342-
weblogicOperatorSecurityYaml().getOperatorRoleBinding(),
361+
getWeblogicOperatorSecurityYaml().getOperatorRoleBinding(),
343362
yamlEqualTo(
344363
newClusterRoleBinding()
345364
.metadata(newObjectMeta()
@@ -362,7 +381,7 @@ public void generatesCorrect_operatorRoleBindingNonResource() throws Exception {
362381
}
363382

364383
protected V1beta1ClusterRoleBinding getActualOperatorRoleBindingNonResource() {
365-
return weblogicOperatorSecurityYaml().getOperatorRoleBindingNonResource();
384+
return getWeblogicOperatorSecurityYaml().getOperatorRoleBindingNonResource();
366385
}
367386

368387
protected V1beta1ClusterRoleBinding getExpectedOperatorRoleBindingNonResource() {
@@ -388,7 +407,7 @@ public void generatesCorrect_operatorRoleBindingDiscovery() throws Exception {
388407
}
389408

390409
protected V1beta1ClusterRoleBinding getActualOperatorRoleBindingDiscovery() {
391-
return weblogicOperatorSecurityYaml().getOperatorRoleBindingDiscovery();
410+
return getWeblogicOperatorSecurityYaml().getOperatorRoleBindingDiscovery();
392411
}
393412

394413
protected V1beta1ClusterRoleBinding getExpectedOperatorRoleBindingDiscovery() {
@@ -414,7 +433,7 @@ public void generatesCorrect_operatorRoleBindingAuthDelegator() throws Exception
414433
}
415434

416435
protected V1beta1ClusterRoleBinding getActualOperatorRoleBindingAuthDelegator() {
417-
return weblogicOperatorSecurityYaml().getOperatorRoleBindingAuthDelegator();
436+
return getWeblogicOperatorSecurityYaml().getOperatorRoleBindingAuthDelegator();
418437
}
419438

420439
protected V1beta1ClusterRoleBinding getExpectedOperatorRoleBindingAuthDelegator() {
@@ -440,7 +459,7 @@ public void generatesCorrect_weblogicOperatorNamespaceRole() throws Exception {
440459
}
441460

442461
protected V1beta1ClusterRole getActualWeblogicOperatorNamespaceRole() {
443-
return weblogicOperatorSecurityYaml().getWeblogicOperatorNamespaceRole();
462+
return getWeblogicOperatorSecurityYaml().getWeblogicOperatorNamespaceRole();
444463
}
445464

446465
protected V1beta1ClusterRole getExpectedWeblogicOperatorNamespaceRole() {
@@ -481,7 +500,7 @@ public void generatesCorrect_targetNamespaces_weblogicOperatorRoleBindings() thr
481500
}
482501

483502
protected V1beta1RoleBinding getActualWeblogicOperatorRoleBinding(String namespace) {
484-
return weblogicOperatorSecurityYaml().getWeblogicOperatorRoleBinding(namespace);
503+
return getWeblogicOperatorSecurityYaml().getWeblogicOperatorRoleBinding(namespace);
485504
}
486505

487506
protected V1beta1RoleBinding getExpectedWeblogicOperatorRoleBinding(String namespace) {

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

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

4+
import java.nio.file.Path;
5+
import java.nio.file.Files;
6+
import java.util.List;
7+
48
import org.junit.After;
59
import org.junit.Before;
610
import org.junit.Test;
7-
import java.nio.file.Files;
8-
911
import static oracle.kubernetes.operator.create.CreateOperatorInputs.*;
1012
import static oracle.kubernetes.operator.create.ExecCreateOperator.*;
1113
import static oracle.kubernetes.operator.create.ExecResultMatcher.*;
@@ -62,23 +64,29 @@ public void defaultInputsFile_hasCorrectContents() throws Exception {
6264
@Test
6365
public void createOperatorWithoutSpecifyingInputsFile_usesDefaultInputsFileAndSucceedsAndGeneratesExpectedYamlFiles() throws Exception {
6466
assertThat(execCreateOperator(" -g -o " + userProjects.getPath().toString()), succeedsAndPrints("Completed"));
65-
assertGeneratedYamlFilesExist(readDefaultInputsFile());
67+
assertThatOnlyTheExpectedGeneratedYamlFilesExist(readDefaultInputsFile());
6668
}
6769

6870
@Test
6971
public void createOperatorWithSpecifiedInputsFile_usesSpecifiedInputsFileAndSucceedsAndGeneratesExpectedYamlFiles() throws Exception {
7072
// customize the namespace name so that we can tell that it generated the yaml files based on this inputs instead of the default one
7173
CreateOperatorInputs inputs = readDefaultInputsFile().namespace("weblogic-operator-2");
7274
assertThat(execCreateOperator(userProjects.getPath(), inputs), succeedsAndPrints("Completed"));
73-
assertGeneratedYamlFilesExist(inputs);
75+
assertThatOnlyTheExpectedGeneratedYamlFilesExist(inputs);
7476
}
7577

76-
private void assertGeneratedYamlFilesExist(CreateOperatorInputs inputs) {
78+
private void assertThatOnlyTheExpectedGeneratedYamlFilesExist(CreateOperatorInputs inputs) throws Exception {
79+
// Make sure the generated directory has the correct list of files
7780
OperatorFiles operatorFiles = new OperatorFiles(userProjects.getPath(), inputs);
78-
assertThat(Files.isRegularFile(operatorFiles.getCreateWeblogicOperatorInputsYamlPath()), is(true));
79-
assertThat(Files.isRegularFile(operatorFiles.getWeblogicOperatorYamlPath()), is(true));
80-
assertThat(Files.isRegularFile(operatorFiles.getWeblogicOperatorSecurityYamlPath()), is(true));
81-
// TBD - assert that the generated per-operator directory doesn't contain any extra files?
82-
// TBD - assert that the copy of the inputs in generated per-operator directory matches the origin one
81+
List<Path> expectedFiles = operatorFiles.getExpectedContents(true); // include the directory too
82+
List<Path> actualFiles = userProjects.getContents(operatorFiles.getWeblogicOperatorPath());
83+
assertThat(
84+
actualFiles,
85+
containsInAnyOrder(expectedFiles.toArray(new Path[expectedFiles.size()])));
86+
87+
// Make sure that the yaml files are regular files
88+
for (Path path : operatorFiles.getExpectedContents(false)) { // don't include the directory too
89+
assertThat("Expect that " + path + " is a regular file", Files.isRegularFile(path), is(true));
90+
}
8391
}
8492
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
package oracle.kubernetes.operator.create;
33

44
import java.nio.file.Path;
5+
import java.util.ArrayList;
6+
import java.util.List;
57

68
/**
79
* Manages the input and generated files for a domain
@@ -58,4 +60,19 @@ public Path getWeblogicDomainPersistentVolumeClaimYamlPath() {
5860
public Path getWeblogicDomainPath() {
5961
return userProjectsPath().resolve("weblogic-domains").resolve(inputs.getDomainUid());
6062
}
63+
64+
public List<Path> getExpectedContents(boolean includeDirectory) {
65+
List<Path> rtn = new ArrayList();
66+
rtn.add(getCreateWeblogicDomainInputsYamlPath());
67+
rtn.add(getCreateWeblogicDomainJobYamlPath());
68+
rtn.add(getDomainCustomResourceYamlPath());
69+
rtn.add(getTraefikYamlPath());
70+
rtn.add(getTraefikSecurityYamlPath());
71+
rtn.add(getWeblogicDomainPersistentVolumeYamlPath());
72+
rtn.add(getWeblogicDomainPersistentVolumeClaimYamlPath());
73+
if (includeDirectory) {
74+
rtn.add(getWeblogicDomainPath());
75+
}
76+
return rtn;
77+
}
6178
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
package oracle.kubernetes.operator.create;
33

44
import java.nio.file.Path;
5+
import java.util.ArrayList;
6+
import java.util.List;
57

68
/**
79
* Manages the input and generated files for an operator
@@ -38,4 +40,15 @@ public Path getWeblogicOperatorSecurityYamlPath() {
3840
public Path getWeblogicOperatorPath() {
3941
return userProjectsPath().resolve("weblogic-operators").resolve(inputs.getNamespace());
4042
}
43+
44+
public List<Path> getExpectedContents(boolean includeDirectory) {
45+
List<Path> rtn = new ArrayList();
46+
rtn.add(getCreateWeblogicOperatorInputsYamlPath());
47+
rtn.add(getWeblogicOperatorYamlPath());
48+
rtn.add(getWeblogicOperatorSecurityYamlPath());
49+
if (includeDirectory) {
50+
rtn.add(getWeblogicOperatorPath());
51+
}
52+
return rtn;
53+
}
4154
}

0 commit comments

Comments
 (0)