Browse code

Add integration tests for build with network opts

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2016/10/25 08:28:14
Showing 1 changed files
... ...
@@ -7042,3 +7042,31 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) {
7042 7042
 	}
7043 7043
 	c.Assert(layers1[len(layers1)-1], checker.Not(checker.Equals), layers2[len(layers1)-1])
7044 7044
 }
7045
+
7046
+func (s *DockerSuite) TestBuildNetNone(c *check.C) {
7047
+	testRequires(c, DaemonIsLinux)
7048
+
7049
+	name := "testbuildnetnone"
7050
+	_, out, err := buildImageWithOut(name, `
7051
+  FROM busybox
7052
+  RUN ping -c 1 8.8.8.8
7053
+  `, true, "--network=none")
7054
+	c.Assert(err, checker.NotNil)
7055
+	c.Assert(out, checker.Contains, "unreachable")
7056
+}
7057
+
7058
+func (s *DockerSuite) TestBuildNetContainer(c *check.C) {
7059
+	testRequires(c, DaemonIsLinux)
7060
+
7061
+	id, _ := dockerCmd(c, "run", "--hostname", "foobar", "-d", "busybox", "nc", "-ll", "-p", "1234", "-e", "hostname")
7062
+
7063
+	name := "testbuildnetcontainer"
7064
+	out, err := buildImage(name, `
7065
+  FROM busybox
7066
+  RUN nc localhost 1234 > /otherhost
7067
+  `, true, "--network=container:"+strings.TrimSpace(id))
7068
+	c.Assert(err, checker.IsNil, check.Commentf("out: %v", out))
7069
+
7070
+	host, _ := dockerCmd(c, "run", "testbuildnetcontainer", "cat", "/otherhost")
7071
+	c.Assert(strings.TrimSpace(host), check.Equals, "foobar")
7072
+}