github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/e2e/run_dns_test.go (about) 1 package integration 2 3 import ( 4 "os" 5 6 . "github.com/containers/podman/v3/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 podmanTest.SeedImages() 27 }) 28 29 AfterEach(func() { 30 podmanTest.Cleanup() 31 f := CurrentGinkgoTestDescription() 32 processTestResult(f) 33 34 }) 35 36 It("podman run add search domain", func() { 37 session := podmanTest.Podman([]string{"run", "--dns-search=foobar.com", ALPINE, "cat", "/etc/resolv.conf"}) 38 session.WaitWithDefaultTimeout() 39 Expect(session).Should(Exit(0)) 40 session.LineInOutputStartsWith("search foobar.com") 41 }) 42 43 It("podman run remove all search domain", func() { 44 session := podmanTest.Podman([]string{"run", "--dns-search=.", ALPINE, "cat", "/etc/resolv.conf"}) 45 session.WaitWithDefaultTimeout() 46 Expect(session).Should(Exit(0)) 47 Expect(session.LineInOutputStartsWith("search")).To(BeFalse()) 48 }) 49 50 It("podman run add bad dns server", func() { 51 session := podmanTest.Podman([]string{"run", "--dns=foobar", ALPINE, "ls"}) 52 session.WaitWithDefaultTimeout() 53 Expect(session).To(ExitWithError()) 54 }) 55 56 It("podman run add dns server", func() { 57 session := podmanTest.Podman([]string{"run", "--dns=1.2.3.4", ALPINE, "cat", "/etc/resolv.conf"}) 58 session.WaitWithDefaultTimeout() 59 Expect(session).Should(Exit(0)) 60 session.LineInOutputStartsWith("server 1.2.3.4") 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 session.LineInOutputStartsWith("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 session.LineInOutputStartsWith("1.1.1.1 foobar") 81 session.LineInOutputStartsWith("2001:db8::68 foobaz") 82 }) 83 84 It("podman run add hostname", func() { 85 session := podmanTest.Podman([]string{"run", "--hostname=foobar", ALPINE, "cat", "/etc/hostname"}) 86 session.WaitWithDefaultTimeout() 87 Expect(session).Should(Exit(0)) 88 Expect(session.OutputToString()).To(Equal("foobar")) 89 90 session = podmanTest.Podman([]string{"run", "--hostname=foobar", ALPINE, "hostname"}) 91 session.WaitWithDefaultTimeout() 92 Expect(session).Should(Exit(0)) 93 Expect(session.OutputToString()).To(Equal("foobar")) 94 }) 95 96 It("podman run add hostname sets /etc/hosts", func() { 97 session := podmanTest.Podman([]string{"run", "-t", "-i", "--hostname=foobar", ALPINE, "cat", "/etc/hosts"}) 98 session.WaitWithDefaultTimeout() 99 Expect(session).Should(Exit(0)) 100 Expect(session.LineInOutputContains("foobar")).To(BeTrue()) 101 }) 102 103 It("podman run mutually excludes --dns* and --network", func() { 104 session := podmanTest.Podman([]string{"run", "--dns=1.2.3.4", "--network", "container:ALPINE", ALPINE}) 105 session.WaitWithDefaultTimeout() 106 Expect(session).To(ExitWithError()) 107 108 session = podmanTest.Podman([]string{"run", "--dns-opt=1.2.3.4", "--network", "container:ALPINE", ALPINE}) 109 session.WaitWithDefaultTimeout() 110 Expect(session).To(ExitWithError()) 111 112 session = podmanTest.Podman([]string{"run", "--dns-search=foobar.com", "--network", "none", ALPINE}) 113 session.WaitWithDefaultTimeout() 114 Expect(session).To(ExitWithError()) 115 116 session = podmanTest.Podman([]string{"run", "--dns=1.2.3.4", "--network", "host", ALPINE}) 117 session.WaitWithDefaultTimeout() 118 Expect(session).Should(Exit(0)) 119 }) 120 })