blob: f5a661c8a665c50eb4be9acde2092dba702cb1ab (
plain) (
blame)
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.util;
import static com.yahoo.vespa.defaults.Defaults.getDefaults;
import com.yahoo.vespa.hosted.dockerapi.ContainerName;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author freva
*/
public class EnvironmentTest {
private final Environment environment = new Environment.Builder().pathResolver(new PathResolver()).build();
@Test
public void testPathInNodeToPathInNodeAdminAndHost() {
ContainerName containerName = new ContainerName("docker1-1");
assertEquals(
"/host/home/docker/container-storage/" + containerName.asString(),
environment.pathInNodeAdminFromPathInNode(containerName, "/").toString());
assertEquals(
"/home/docker/container-storage/" + containerName.asString(),
environment.pathInHostFromPathInNode(containerName, "/").toString());
}
@Test
public void testAbsolutePathInNodeConversion() {
String varPath = getDefaults().underVespaHome("var");
ContainerName containerName = new ContainerName("docker1-1");
String expected = "/host/home/docker/container-storage/" + containerName.asString() + varPath;
String[] absolutePathsInContainer = {"/" + varPath, varPath, varPath + "/"};
for (String pathInContainer : absolutePathsInContainer) {
assertEquals(expected, environment.pathInNodeAdminFromPathInNode(containerName, pathInContainer).toString());
}
}
@Test(expected=IllegalArgumentException.class)
public void testNonAbsolutePathInNodeConversion() {
String varPath = getDefaults().underVespaHome("var").substring(1);
environment.pathInNodeAdminFromPathInNode(new ContainerName("container-1"), varPath);
}
}
|