github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/run_dns_test.go (about) 1 package integration 2 3 import ( 4 "os" 5 6 . "github.com/hanks177/podman/v4/test/utils" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gexec" 10 ) 11 12 var _ = Describe("Podman run dns", func() { 13 var ( 14 tempdir string 15 err error 16 podmanTest *PodmanTestIntegration 17 ) 18 19 BeforeEach(func() { 20 tempdir, err = CreateTempDirInTempDir() 21 if err != nil { 22 os.Exit(1) 23 } 24 podmanTest = PodmanTestCreate(tempdir) 25 podmanTest.Setup() 26 }) 27 28 AfterEach(func() { 29 podmanTest.Cleanup() 30 f := CurrentGinkgoTestDescription() 31 processTestResult(f) 32 33 }) 34 35 It("podman run add search domain", func() { 36 session := podmanTest.Podman([]string{"run", "--dns-search=foobar.com", ALPINE, "cat", "/etc/resolv.conf"}) 37 session.WaitWithDefaultTimeout() 38 Expect(session).Should(Exit(0)) 39 Expect(session.OutputToStringArray()).To(ContainElement(HavePrefix("search foobar.com"))) 40 }) 41 42 It("podman run remove all search domain", func() { 43 session := podmanTest.Podman([]string{"run", "--dns-search=.", ALPINE, "cat", "/etc/resolv.conf"}) 44 session.WaitWithDefaultTimeout() 45 Expect(session).Should(Exit(0)) 46 Expect(session.OutputToStringArray()).To(Not(ContainElement(HavePrefix("search")))) 47 }) 48 49 It("podman run add bad dns server", func() { 50 session := podmanTest.Podman([]string{"run", "--dns=foobar", ALPINE, "ls"}) 51 session.WaitWithDefaultTimeout() 52 Expect(session).To(ExitWithError()) 53 }) 54 55 It("podman run add dns server", func() { 56 session := podmanTest.Podman([]string{"run", "--dns=1.2.3.4", ALPINE, "cat", "/etc/resolv.conf"}) 57 session.WaitWithDefaultTimeout() 58 Expect(session).Should(Exit(0)) 59 Expect(session.OutputToStringArray()).To(ContainElement(HavePrefix("nameserver 1.2.3.4"))) 60 61 }) 62 63 It("podman run add dns option", func() { 64 session := podmanTest.Podman([]string{"run", "--dns-opt=debug", ALPINE, "cat", "/etc/resolv.conf"}) 65 session.WaitWithDefaultTimeout() 66 Expect(session).Should(Exit(0)) 67 Expect(session.OutputToStringArray()).To(ContainElement(HavePrefix("options debug"))) 68 }) 69 70 It("podman run add bad host", func() { 71 session := podmanTest.Podman([]string{"run", "--add-host=foo:1.2", ALPINE, "ls"}) 72 session.WaitWithDefaultTimeout() 73 Expect(session).To(ExitWithError()) 74 }) 75 76 It("podman run add host", func() { 77 session := podmanTest.Podman([]string{"run", "--add-host=foobar:1.1.1.1", "--add-host=foobaz:2001:db8::68", ALPINE, "cat", "/etc/hosts"}) 78 session.WaitWithDefaultTimeout() 79 Expect(session).Should(Exit(0)) 80 Expect(session.OutputToStringArray()).To(ContainElements(HavePrefix("1.1.1.1\tfoobar"), HavePrefix("2001:db8::68\tfoobaz"))) 81 }) 82 83 It("podman run add hostname", func() { 84 session := podmanTest.Podman([]string{"run", "--hostname=foobar", ALPINE, "cat", "/etc/hostname"}) 85 session.WaitWithDefaultTimeout() 86 Expect(session).Should(Exit(0)) 87 Expect(session.OutputToString()).To(Equal("foobar")) 88 89 session = podmanTest.Podman([]string{"run", "--hostname=foobar", ALPINE, "hostname"}) 90 session.WaitWithDefaultTimeout() 91 Expect(session).Should(Exit(0)) 92 Expect(session.OutputToString()).To(Equal("foobar")) 93 }) 94 95 It("podman run add hostname sets /etc/hosts", func() { 96 session := podmanTest.Podman([]string{"run", "-t", "-i", "--hostname=foobar", ALPINE, "cat", "/etc/hosts"}) 97 session.WaitWithDefaultTimeout() 98 Expect(session).Should(Exit(0)) 99 Expect(session.OutputToString()).To(ContainSubstring("foobar")) 100 }) 101 102 It("podman run mutually excludes --dns* and --network", func() { 103 session := podmanTest.Podman([]string{"run", "--dns=1.2.3.4", "--network", "container:ALPINE", ALPINE}) 104 session.WaitWithDefaultTimeout() 105 Expect(session).To(ExitWithError()) 106 107 session = podmanTest.Podman([]string{"run", "--dns-opt=1.2.3.4", "--network", "container:ALPINE", ALPINE}) 108 session.WaitWithDefaultTimeout() 109 Expect(session).To(ExitWithError()) 110 111 session = podmanTest.Podman([]string{"run", "--dns-search=foobar.com", "--network", "none", ALPINE}) 112 session.WaitWithDefaultTimeout() 113 Expect(session).To(ExitWithError()) 114 115 session = podmanTest.Podman([]string{"run", "--dns=1.2.3.4", "--network", "host", ALPINE}) 116 session.WaitWithDefaultTimeout() 117 Expect(session).Should(Exit(0)) 118 }) 119 })