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