Skip to content

Commit 05419ab

Browse files
committed
Add more CLI tests
1 parent c80736a commit 05419ab

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

java/coherence-operator/src/main/java/com/oracle/coherence/k8s/CoherenceOperatorLifecycleListener.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,17 @@ && tryCreateConfig(new File(cohCtlHome), connectionType, protocol, port, cluster
305305
if (fileUserHome.exists() && fileUserHome.isDirectory()) {
306306
// use ${user.home}/.cohctl
307307
fileCohCtlHome = new File(fileUserHome, ".cohctl");
308+
if (!fileCohCtlHome.exists()) {
309+
try {
310+
if (!fileCohCtlHome.mkdirs()) {
311+
fileCohCtlHome = null;
312+
}
313+
}
314+
catch (Exception e) {
315+
LOGGER.error("CoherenceOperator: Failed to create cohctl home directory at " + fileCohCtlHome, e);
316+
fileCohCtlHome = null;
317+
}
318+
}
308319
}
309320

310321
boolean success = false;

test/e2e/local/cli_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,30 @@ func TestCoherenceCLI(t *testing.T) {
3535
t.Log(string(out))
3636
g.Expect(err).NotTo(HaveOccurred())
3737
}
38+
39+
// Test that the Coherence CLI can be executed in a Pod
40+
func TestCoherenceCLIWithCustomHome(t *testing.T) {
41+
// Make sure we defer clean-up when we're done!!
42+
testContext.CleanupAfterTest(t)
43+
g := NewWithT(t)
44+
45+
deployments, _ := helper.AssertDeployments(testContext, t, "deployment-cli-home.yaml")
46+
47+
data, ok := deployments["storage"]
48+
g.Expect(ok).To(BeTrue(), "did not find expected 'storage' deployment")
49+
50+
hasFinalizer := controllerutil.ContainsFinalizer(&data, coh.CoherenceFinalizer)
51+
g.Expect(hasFinalizer).To(BeTrue())
52+
53+
out, err := exec.Command("kubectl", "-n", data.Namespace, "exec", "storage-0",
54+
"-c", "coherence", "--", "/coherence-operator/utils/cohctl", "get", "members").CombinedOutput()
55+
t.Log("CLI Output:")
56+
t.Log(string(out))
57+
g.Expect(err).NotTo(HaveOccurred())
58+
59+
out, err = exec.Command("kubectl", "-n", data.Namespace, "exec", "storage-0",
60+
"-c", "coherence", "--", "/coherence-operator/utils/cohctl", "--config-dir", "/test/cli", "get", "members").CombinedOutput()
61+
t.Log("CLI Output:")
62+
t.Log(string(out))
63+
g.Expect(err).NotTo(HaveOccurred())
64+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: coherence.oracle.com/v1
2+
kind: Coherence
3+
metadata:
4+
name: storage
5+
spec:
6+
env:
7+
- name: COH_SKIP_SITE
8+
value: "true"
9+
- name: COHCTL_HOME
10+
value: /test/cli
11+
volumeMounts:
12+
- mountPath: /test/cli
13+
name: cli
14+
readOnly: false
15+
volumes:
16+
- name: cli
17+
emptyDir: {}
18+
19+
20+
21+

0 commit comments

Comments
 (0)