-
Notifications
You must be signed in to change notification settings - Fork 24.3k
/
TemporaryDirectoryConfigTests.java
114 lines (93 loc) · 4.17 KB
/
TemporaryDirectoryConfigTests.java
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.packaging.test;
import org.apache.http.client.fluent.Request;
import org.elasticsearch.core.CheckedConsumer;
import org.elasticsearch.packaging.util.Distribution;
import org.elasticsearch.packaging.util.ServerUtils;
import org.elasticsearch.packaging.util.Shell;
import org.elasticsearch.packaging.util.docker.DockerRun;
import org.junit.After;
import org.junit.Before;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.elasticsearch.packaging.util.FileUtils.append;
import static org.elasticsearch.packaging.util.docker.Docker.removeContainer;
import static org.elasticsearch.packaging.util.docker.Docker.runContainer;
import static org.elasticsearch.packaging.util.docker.Docker.runContainerExpectingFailure;
import static org.elasticsearch.packaging.util.docker.Docker.waitForElasticsearch;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
public class TemporaryDirectoryConfigTests extends PackagingTestCase {
@Before
public void onlyLinux() {
assumeTrue("only Linux", distribution.platform == Distribution.Platform.LINUX);
}
@After
public void cleanupContainer() {
if (distribution().isDocker()) {
removeContainer();
}
}
public void test10Install() throws Exception {
install();
}
public void test20AcceptsCustomPath() throws Exception {
assumeFalse(distribution().isDocker());
final Path tmpDir = createTempDir("libffi");
sh.getEnv().put("LIBFFI_TMPDIR", tmpDir.toString());
withLibffiTmpdir(
tmpDir.toString(),
confPath -> assertWhileRunning(() -> ServerUtils.makeRequest(Request.Get("http://localhost:9200/")))
); // just checking it doesn't throw
}
public void test21AcceptsCustomPathInDocker() throws Exception {
assumeTrue(distribution().isDocker());
final Path tmpDir = createTempDir("libffi");
installation = runContainer(
distribution(),
DockerRun.builder()
// There's no actual need for this to be a bind-mounted dir, but it's the quickest
// way to create a directory in the container before the entrypoint runs.
.volume(tmpDir, tmpDir)
.envVar("ELASTIC_PASSWORD", "nothunter2")
.envVar("LIBFFI_TMPDIR", tmpDir.toString())
);
waitForElasticsearch("green", null, installation, "elastic", "nothunter2");
}
public void test30VerifiesCustomPath() throws Exception {
assumeFalse(distribution().isDocker());
final Path tmpFile = createTempDir("libffi").resolve("file");
Files.createFile(tmpFile);
withLibffiTmpdir(
tmpFile.toString(),
confPath -> assertElasticsearchFailure(runElasticsearchStartCommand(null, false, false), "LIBFFI_TMPDIR", null)
);
}
public void test31VerifiesCustomPathInDocker() throws Exception {
assumeTrue(distribution().isDocker());
final Path tmpDir = createTempDir("libffi");
final Path tmpFile = tmpDir.resolve("file");
Files.createFile(tmpFile);
final Shell.Result result = runContainerExpectingFailure(
distribution(),
DockerRun.builder().volume(tmpDir, tmpDir).envVar("LIBFFI_TMPDIR", tmpFile.toString())
);
assertThat(result.stderr, containsString("LIBFFI_TMPDIR"));
}
private void withLibffiTmpdir(String tmpDir, CheckedConsumer<Path, Exception> action) throws Exception {
sh.getEnv().put("LIBFFI_TMPDIR", tmpDir);
withCustomConfig(confPath -> {
if (distribution.isPackage()) {
append(installation.envFile, "LIBFFI_TMPDIR=" + tmpDir);
}
action.accept(confPath);
});
}
}