From 71f1055fed43852de124f09845ff4786cf6ac444 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Thu, 9 Nov 2023 14:45:50 +0100 Subject: [PATCH] lint: Stop using dot imports While convenient, they can make the code harder to read. https://github.com/golang/go/wiki/CodeReviewComments#import-dot This should fix: ``` pkg/services/dns/dns_test.go:8:2: dot-imports: should not use dot imports (revive) . "github.com/onsi/ginkgo" ^ pkg/services/dns/dns_test.go:9:2: dot-imports: should not use dot imports (revive) . "github.com/onsi/gomega" ^ test/port_forwarding_test.go:18:2: dot-imports: should not use dot imports (revive) . "github.com/onsi/ginkgo" ^ test/basic_test.go:10:2: dot-imports: should not use dot imports (revive) . "github.com/onsi/ginkgo" ^ test/basic_test.go:11:2: dot-imports: should not use dot imports (revive) . "github.com/onsi/gomega" ^ test/suite_test.go:16:2: dot-imports: should not use dot imports (revive) . "github.com/onsi/ginkgo" ^ test/suite_test.go:16:2: dot-imports: should not use dot imports (revive) . "github.com/onsi/ginkgo" ^ test/suite_test.go:17:2: dot-imports: should not use dot imports (revive) . "github.com/onsi/gomega" ^ ``` Signed-off-by: Christophe Fergeau --- pkg/services/dns/dns_test.go | 40 ++++---- test/basic_test.go | 130 ++++++++++++------------ test/port_forwarding_test.go | 186 +++++++++++++++++------------------ test/suite_test.go | 34 +++---- 4 files changed, 195 insertions(+), 195 deletions(-) diff --git a/pkg/services/dns/dns_test.go b/pkg/services/dns/dns_test.go index 3d97517e3..f01488d23 100644 --- a/pkg/services/dns/dns_test.go +++ b/pkg/services/dns/dns_test.go @@ -5,33 +5,33 @@ import ( "testing" "github.com/containers/gvisor-tap-vsock/pkg/types" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" ) func TestSuite(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "gvisor-tap-vsock dns suit") + gomega.RegisterFailHandler(ginkgo.Fail) + ginkgo.RunSpecs(t, "gvisor-tap-vsock dns suit") } -var _ = Describe("dns add test", func() { +var _ = ginkgo.Describe("dns add test", func() { var server *Server - BeforeEach(func() { + ginkgo.BeforeEach(func() { server, _ = New(nil, nil, []types.Zone{}) }) - It("should add dns zone with ip", func() { + ginkgo.It("should add dns zone with ip", func() { req := types.Zone{ Name: "internal.", DefaultIP: net.ParseIP("192.168.0.1"), } server.addZone(req) - Expect(server.handler.zones).To(Equal([]types.Zone{req})) + gomega.Expect(server.handler.zones).To(gomega.Equal([]types.Zone{req})) }) - It("should add dns zone with record", func() { + ginkgo.It("should add dns zone with record", func() { req := types.Zone{ Name: "internal.", Records: []types.Record{{ @@ -41,10 +41,10 @@ var _ = Describe("dns add test", func() { } server.addZone(req) - Expect(server.handler.zones).To(Equal([]types.Zone{req})) + gomega.Expect(server.handler.zones).To(gomega.Equal([]types.Zone{req})) }) - It("should add dns zone with record and ip", func() { + ginkgo.It("should add dns zone with record and ip", func() { ipReq := types.Zone{ Name: "dynamic.internal.", DefaultIP: net.ParseIP("192.168.0.1"), @@ -59,10 +59,10 @@ var _ = Describe("dns add test", func() { server.addZone(ipReq) server.addZone(recordReq) - Expect(server.handler.zones).To(Equal([]types.Zone{ipReq, recordReq})) + gomega.Expect(server.handler.zones).To(gomega.Equal([]types.Zone{ipReq, recordReq})) }) - It("should add new zone to existing zone with default ip", func() { + ginkgo.It("should add new zone to existing zone with default ip", func() { ipReq := types.Zone{ Name: "internal.", DefaultIP: net.ParseIP("192.168.0.1"), @@ -77,7 +77,7 @@ var _ = Describe("dns add test", func() { } server.addZone(recordReq) - Expect(server.handler.zones).To(Equal([]types.Zone{{ + gomega.Expect(server.handler.zones).To(gomega.Equal([]types.Zone{{ Name: "internal.", Records: []types.Record{{ Name: "crc.testing", @@ -86,7 +86,7 @@ var _ = Describe("dns add test", func() { }})) }) - It("should add new zone to existing zone with records", func() { + ginkgo.It("should add new zone to existing zone with records", func() { ipReq := types.Zone{ Name: "internal.", Records: []types.Record{{ @@ -104,7 +104,7 @@ var _ = Describe("dns add test", func() { } server.addZone(recordReq) - Expect(server.handler.zones).To(Equal([]types.Zone{{ + gomega.Expect(server.handler.zones).To(gomega.Equal([]types.Zone{{ Name: "internal.", Records: []types.Record{{ Name: "crc.testing", @@ -116,7 +116,7 @@ var _ = Describe("dns add test", func() { }})) }) - It("should add new zone to existing zone with records", func() { + ginkgo.It("should add new zone to existing zone with records", func() { ipReq := types.Zone{ Name: "internal.", Records: []types.Record{{ @@ -134,7 +134,7 @@ var _ = Describe("dns add test", func() { } server.addZone(recordReq) - Expect(server.handler.zones).To(Equal([]types.Zone{{ + gomega.Expect(server.handler.zones).To(gomega.Equal([]types.Zone{{ Name: "internal.", Records: []types.Record{{ Name: "crc.testing", @@ -146,7 +146,7 @@ var _ = Describe("dns add test", func() { }})) }) - It("should retain the order of zones", func() { + ginkgo.It("should retain the order of zones", func() { server, _ = New(nil, nil, []types.Zone{ { Name: "crc.testing.", @@ -171,7 +171,7 @@ var _ = Describe("dns add test", func() { }, }, }) - Expect(server.handler.zones).To(Equal([]types.Zone{ + gomega.Expect(server.handler.zones).To(gomega.Equal([]types.Zone{ { Name: "crc.testing.", DefaultIP: net.ParseIP("192.168.127.2"), diff --git a/test/basic_test.go b/test/basic_test.go index ab44b0c28..ad96b9007 100644 --- a/test/basic_test.go +++ b/test/basic_test.go @@ -7,92 +7,92 @@ import ( gvproxyclient "github.com/containers/gvisor-tap-vsock/pkg/client" "github.com/containers/gvisor-tap-vsock/pkg/types" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" ) -var _ = Describe("connectivity", func() { - It("should configure the interface", func() { +var _ = ginkgo.Describe("connectivity", func() { + ginkgo.It("should configure the interface", func() { out, err := sshExec("ifconfig $(route | grep '^default' | grep -o '[^ ]*$')") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("mtu 1500")) - Expect(string(out)).To(ContainSubstring("inet 192.168.127.2")) - Expect(string(out)).To(ContainSubstring("netmask 255.255.255.0")) - Expect(string(out)).To(ContainSubstring("broadcast 192.168.127.255")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("mtu 1500")) + gomega.Expect(string(out)).To(gomega.ContainSubstring("inet 192.168.127.2")) + gomega.Expect(string(out)).To(gomega.ContainSubstring("netmask 255.255.255.0")) + gomega.Expect(string(out)).To(gomega.ContainSubstring("broadcast 192.168.127.255")) }) - It("should configure the default route", func() { + ginkgo.It("should configure the default route", func() { out, err := sshExec("ip route show") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(MatchRegexp(`default via 192\.168\.127\.1 dev (.*?) proto dhcp (src 192\.168\.127\.2 )?metric 100`)) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.MatchRegexp(`default via 192\.168\.127\.1 dev (.*?) proto dhcp (src 192\.168\.127\.2 )?metric 100`)) }) - It("should configure dns settings", func() { + ginkgo.It("should configure dns settings", func() { out, err := sshExec("cat /etc/resolv.conf") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("nameserver 192.168.127.1")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("nameserver 192.168.127.1")) }) - It("should ping the tap device", func() { + ginkgo.It("should ping the tap device", func() { out, err := sshExec("ping -c2 192.168.127.2") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("2 packets transmitted, 2 received, 0% packet loss")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("2 packets transmitted, 2 received, 0% packet loss")) }) - It("should ping the gateway", func() { + ginkgo.It("should ping the gateway", func() { out, err := sshExec("ping -c2 192.168.127.1") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("2 packets transmitted, 2 received, 0% packet loss")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("2 packets transmitted, 2 received, 0% packet loss")) }) }) -var _ = Describe("dns", func() { - It("should resolve redhat.com", func() { +var _ = ginkgo.Describe("dns", func() { + ginkgo.It("should resolve redhat.com", func() { out, err := sshExec("nslookup redhat.com") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("Address: 52.200.142.250")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 52.200.142.250")) }) - It("should resolve CNAME record for www.wikipedia.org", func() { + ginkgo.It("should resolve CNAME record for www.wikipedia.org", func() { out, err := sshExec("nslookup -query=cname www.wikipedia.org") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("www.wikipedia.org canonical name = dyna.wikimedia.org.")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("www.wikipedia.org canonical name = dyna.wikimedia.org.")) }) - It("should resolve MX record for wikipedia.org", func() { + ginkgo.It("should resolve MX record for wikipedia.org", func() { out, err := sshExec("nslookup -query=mx wikipedia.org") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("wikipedia.org mail exchanger = 10 mx1001.wikimedia.org.")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("wikipedia.org mail exchanger = 10 mx1001.wikimedia.org.")) }) - It("should resolve NS record for wikipedia.org", func() { + ginkgo.It("should resolve NS record for wikipedia.org", func() { out, err := sshExec("nslookup -query=ns wikipedia.org") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("wikipedia.org nameserver = ns0.wikimedia.org.")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("wikipedia.org nameserver = ns0.wikimedia.org.")) }) - It("should resolve LDAP SRV record for google.com", func() { + ginkgo.It("should resolve LDAP SRV record for google.com", func() { out, err := sshExec("nslookup -query=srv _ldap._tcp.google.com") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring(`_ldap._tcp.google.com service = 5 0 389 ldap.google.com.`)) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring(`_ldap._tcp.google.com service = 5 0 389 ldap.google.com.`)) }) - It("should resolve TXT for wikipedia.org", func() { + ginkgo.It("should resolve TXT for wikipedia.org", func() { out, err := sshExec("nslookup -query=txt wikipedia.org") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring(`"v=spf1 include:wikimedia.org ~all"`)) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring(`"v=spf1 include:wikimedia.org ~all"`)) }) - It("should resolve gateway.containers.internal", func() { + ginkgo.It("should resolve gateway.containers.internal", func() { out, err := sshExec("nslookup gateway.containers.internal") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("Address: 192.168.127.1")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 192.168.127.1")) }) - It("should resolve host.containers.internal", func() { + ginkgo.It("should resolve host.containers.internal", func() { out, err := sshExec("nslookup host.containers.internal") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("Address: 192.168.127.254")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 192.168.127.254")) }) - It("should resolve dynamically added dns entry test.dynamic.internal", func() { + ginkgo.It("should resolve dynamically added dns entry test.dynamic.internal", func() { client := gvproxyclient.New(&http.Client{ Transport: &http.Transport{ DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { @@ -109,15 +109,15 @@ var _ = Describe("dns", func() { }, }, }) - Expect(err).ShouldNot(HaveOccurred()) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) out, err := sshExec("nslookup test.dynamic.internal") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("Address: 192.168.127.254")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 192.168.127.254")) }) - It("should resolve recently added dns entry test.dynamic.internal", func() { + ginkgo.It("should resolve recently added dns entry test.dynamic.internal", func() { client := gvproxyclient.New(&http.Client{ Transport: &http.Transport{ DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { @@ -134,7 +134,7 @@ var _ = Describe("dns", func() { }, }, }) - Expect(err).ShouldNot(HaveOccurred()) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) err = client.AddDNS(&types.Zone{ Name: "dynamic.internal.", @@ -145,15 +145,15 @@ var _ = Describe("dns", func() { }, }, }) - Expect(err).ShouldNot(HaveOccurred()) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) out, err := sshExec("nslookup test.dynamic.internal") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("Address: 192.168.127.253")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 192.168.127.253")) }) - It("should retain order of existing zone", func() { + ginkgo.It("should retain order of existing zone", func() { client := gvproxyclient.New(&http.Client{ Transport: &http.Transport{ DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { @@ -175,8 +175,8 @@ var _ = Describe("dns", func() { }, }) out, err := sshExec("nslookup test.dynamic.internal") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("Address: 192.168.127.2")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 192.168.127.2")) _ = client.AddDNS(&types.Zone{ Name: "testing.", @@ -188,17 +188,17 @@ var _ = Describe("dns", func() { }, }) out, err = sshExec("nslookup *.dynamic.testing") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("Address: 192.168.127.2")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 192.168.127.2")) out, err = sshExec("nslookup gateway.testing") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("Address: 192.168.127.1")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 192.168.127.1")) }) }) -var _ = Describe("command-line format", func() { - It("should convert Command to command line format", func() { +var _ = ginkgo.Describe("command-line format", func() { + ginkgo.It("should convert Command to command line format", func() { command := types.NewGvproxyCommand() command.AddEndpoint("unix:///tmp/network.sock") command.Debug = true @@ -207,7 +207,7 @@ var _ = Describe("command-line format", func() { command.AddForwardUser("demouser") cmd := command.ToCmdline() - Expect(cmd).To(Equal([]string{ + gomega.Expect(cmd).To(gomega.Equal([]string{ "-listen", "unix:///tmp/network.sock", "-debug", "-mtu", "1500", diff --git a/test/port_forwarding_test.go b/test/port_forwarding_test.go index 119d9f2cb..c38e4f6a0 100644 --- a/test/port_forwarding_test.go +++ b/test/port_forwarding_test.go @@ -15,12 +15,12 @@ import ( gvproxyclient "github.com/containers/gvisor-tap-vsock/pkg/client" "github.com/containers/gvisor-tap-vsock/pkg/transport" "github.com/containers/gvisor-tap-vsock/pkg/types" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" log "github.com/sirupsen/logrus" ) -var _ = Describe("port forwarding", func() { +var _ = ginkgo.Describe("port forwarding", func() { client := gvproxyclient.New(&http.Client{ Transport: &http.Transport{ DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { @@ -29,9 +29,9 @@ var _ = Describe("port forwarding", func() { }, }, "http://base") - It("should reach a http server on the host", func() { + ginkgo.It("should reach a http server on the host", func() { ln, err := net.Listen("tcp", "127.0.0.1:9090") - Expect(err).ShouldNot(HaveOccurred()) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) defer ln.Close() mux := http.NewServeMux() @@ -51,62 +51,62 @@ var _ = Describe("port forwarding", func() { }() out, err := sshExec("curl http://host.containers.internal:9090") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("Hello from the host")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("Hello from the host")) out, err = sshExec("curl http://host.docker.internal:9090") - Expect(err).ShouldNot(HaveOccurred()) - Expect(string(out)).To(ContainSubstring("Hello from the host")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + gomega.Expect(string(out)).To(gomega.ContainSubstring("Hello from the host")) }) - It("should reach a http server in the VM using dynamic port forwarding", func() { + ginkgo.It("should reach a http server in the VM using dynamic port forwarding", func() { _, err := net.Dial("tcp", "127.0.0.1:9090") - Expect(err).Should(HaveOccurred()) - Expect(err.Error()).To(HaveSuffix("connection refused")) + gomega.Expect(err).Should(gomega.HaveOccurred()) + gomega.Expect(err.Error()).To(gomega.HaveSuffix("connection refused")) - Expect(client.Expose(&types.ExposeRequest{ + gomega.Expect(client.Expose(&types.ExposeRequest{ Local: "127.0.0.1:9090", Remote: "192.168.127.2:8080", - })).Should(Succeed()) + })).Should(gomega.Succeed()) - Eventually(func(g Gomega) { + gomega.Eventually(func(g gomega.Gomega) { resp, err := http.Get("http://127.0.0.1:9090") - g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(resp.StatusCode).To(Equal(http.StatusOK)) - }).Should(Succeed()) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(resp.StatusCode).To(gomega.Equal(http.StatusOK)) + }).Should(gomega.Succeed()) - Expect(client.Unexpose(&types.UnexposeRequest{ + gomega.Expect(client.Unexpose(&types.UnexposeRequest{ Local: "127.0.0.1:9090", - })).Should(Succeed()) + })).Should(gomega.Succeed()) - Eventually(func(g Gomega) { + gomega.Eventually(func(g gomega.Gomega) { _, err = net.Dial("tcp", "127.0.0.1:9090") - g.Expect(err).Should(HaveOccurred()) - g.Expect(err.Error()).To(HaveSuffix("connection refused")) - }).Should(Succeed()) + g.Expect(err).Should(gomega.HaveOccurred()) + g.Expect(err.Error()).To(gomega.HaveSuffix("connection refused")) + }).Should(gomega.Succeed()) }) - It("should reach a dns server in the VM using dynamic port forwarding", func() { - Expect(client.Expose(&types.ExposeRequest{ + ginkgo.It("should reach a dns server in the VM using dynamic port forwarding", func() { + gomega.Expect(client.Expose(&types.ExposeRequest{ Local: ":1053", Remote: "192.168.127.2:53", Protocol: "udp", - })).Should(Succeed()) + })).Should(gomega.Succeed()) - Eventually(func(g Gomega) { + gomega.Eventually(func(g gomega.Gomega) { cmd := exec.Command("nslookup", "-timeout=1", "-port=1053", "foobar", "127.0.0.1") out, err := cmd.CombinedOutput() - g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(string(out)).To(ContainSubstring("Address: 1.2.3.4")) - }).Should(Succeed()) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(string(out)).To(gomega.ContainSubstring("Address: 1.2.3.4")) + }).Should(gomega.Succeed()) - Expect(client.Unexpose(&types.UnexposeRequest{ + gomega.Expect(client.Unexpose(&types.UnexposeRequest{ Local: ":1053", Protocol: "udp", - })).Should(Succeed()) + })).Should(gomega.Succeed()) }) - It("should reach a http server in the VM using the tunneling of the daemon", func() { + ginkgo.It("should reach a http server in the VM using the tunneling of the daemon", func() { httpClient := &http.Client{ Transport: &http.Transport{ DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { @@ -119,38 +119,38 @@ var _ = Describe("port forwarding", func() { }, } - Eventually(func(g Gomega) { + gomega.Eventually(func(g gomega.Gomega) { resp, err := httpClient.Get("http://placeholder/") - g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(resp.StatusCode).To(Equal(http.StatusOK)) - }).Should(Succeed()) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(resp.StatusCode).To(gomega.Equal(http.StatusOK)) + }).Should(gomega.Succeed()) }) - It("should reach a http server in the VM using dynamic port forwarding configured within the VM", func() { + ginkgo.It("should reach a http server in the VM using dynamic port forwarding configured within the VM", func() { _, err := net.Dial("tcp", "127.0.0.1:9090") - Expect(err).Should(HaveOccurred()) - Expect(err.Error()).To(HaveSuffix("connection refused")) + gomega.Expect(err).Should(gomega.HaveOccurred()) + gomega.Expect(err.Error()).To(gomega.HaveSuffix("connection refused")) _, err = sshExec(`curl http://gateway.containers.internal/services/forwarder/expose -X POST -d'{"local":":9090", "remote":":8080"}'`) - Expect(err).ShouldNot(HaveOccurred()) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) - Eventually(func(g Gomega) { + gomega.Eventually(func(g gomega.Gomega) { resp, err := http.Get("http://127.0.0.1:9090") - g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(resp.StatusCode).To(Equal(http.StatusOK)) - }).Should(Succeed()) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(resp.StatusCode).To(gomega.Equal(http.StatusOK)) + }).Should(gomega.Succeed()) _, err = sshExec(`curl http://gateway.containers.internal/services/forwarder/unexpose -X POST -d'{"local":":9090"}'`) - Expect(err).ShouldNot(HaveOccurred()) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) - Eventually(func(g Gomega) { + gomega.Eventually(func(g gomega.Gomega) { _, err = net.Dial("tcp", "127.0.0.1:9090") - g.Expect(err).Should(HaveOccurred()) - g.Expect(err.Error()).To(HaveSuffix("connection refused")) - }).Should(Succeed()) + g.Expect(err).Should(gomega.HaveOccurred()) + g.Expect(err.Error()).To(gomega.HaveSuffix("connection refused")) + }).Should(gomega.Succeed()) }) - It("should reach rootless podman API using unix socket forwarding over ssh", func() { + ginkgo.It("should reach rootless podman API using unix socket forwarding over ssh", func() { httpClient := &http.Client{ Transport: &http.Transport{ DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { @@ -159,21 +159,21 @@ var _ = Describe("port forwarding", func() { }, } - Eventually(func(g Gomega) { + gomega.Eventually(func(g gomega.Gomega) { resp, err := httpClient.Get("http://host/_ping") - g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(resp.StatusCode).To(Equal(http.StatusOK)) - g.Expect(resp.ContentLength).To(Equal(int64(2))) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(resp.StatusCode).To(gomega.Equal(http.StatusOK)) + g.Expect(resp.ContentLength).To(gomega.Equal(int64(2))) reply := make([]byte, resp.ContentLength) _, err = io.ReadAtLeast(resp.Body, reply, len(reply)) - g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(string(reply)).To(Equal("OK")) - }).Should(Succeed()) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(string(reply)).To(gomega.Equal("OK")) + }).Should(gomega.Succeed()) }) - It("should reach rootful podman API using unix socket forwarding over ssh", func() { + ginkgo.It("should reach rootful podman API using unix socket forwarding over ssh", func() { httpClient := &http.Client{ Transport: &http.Transport{ DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { @@ -182,36 +182,36 @@ var _ = Describe("port forwarding", func() { }, } - Eventually(func(g Gomega) { + gomega.Eventually(func(g gomega.Gomega) { resp, err := httpClient.Get("http://host/_ping") - g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(resp.StatusCode).To(Equal(http.StatusOK)) - g.Expect(resp.ContentLength).To(Equal(int64(2))) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(resp.StatusCode).To(gomega.Equal(http.StatusOK)) + g.Expect(resp.ContentLength).To(gomega.Equal(int64(2))) reply := make([]byte, resp.ContentLength) _, err = io.ReadAtLeast(resp.Body, reply, len(reply)) - g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(string(reply)).To(Equal("OK")) - }).Should(Succeed()) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(string(reply)).To(gomega.Equal("OK")) + }).Should(gomega.Succeed()) }) - It("should expose and reach an http service using unix to tcp forwarding", func() { + ginkgo.It("should expose and reach an http service using unix to tcp forwarding", func() { if runtime.GOOS == "windows" { - Skip("AF_UNIX not supported on Windows") + ginkgo.Skip("AF_UNIX not supported on Windows") } unix2tcpfwdsock, _ := filepath.Abs(filepath.Join(tmpDir, "podman-unix-to-unix-forwarding.sock")) out, err := sshExec(`curl http://gateway.containers.internal/services/forwarder/expose -X POST -d'{"protocol":"unix","local":"` + unix2tcpfwdsock + `","remote":"tcp://192.168.127.2:8080"}'`) - Expect(string(out)).Should(Equal("")) - Expect(err).ShouldNot(HaveOccurred()) + gomega.Expect(string(out)).Should(gomega.Equal("")) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) - Eventually(func(g Gomega) { + gomega.Eventually(func(g gomega.Gomega) { sockfile, err := os.Stat(unix2tcpfwdsock) - g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(sockfile.Mode().Type().String()).To(Equal(os.ModeSocket.String())) - }).Should(Succeed()) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(sockfile.Mode().Type().String()).To(gomega.Equal(os.ModeSocket.String())) + }).Should(gomega.Succeed()) httpClient := &http.Client{ Transport: &http.Transport{ @@ -221,29 +221,29 @@ var _ = Describe("port forwarding", func() { }, } - Eventually(func(g Gomega) { + gomega.Eventually(func(g gomega.Gomega) { resp, err := httpClient.Get("http://placeholder/") - g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(resp.StatusCode).To(Equal(http.StatusOK)) - }).Should(Succeed()) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(resp.StatusCode).To(gomega.Equal(http.StatusOK)) + }).Should(gomega.Succeed()) }) - It("should expose and reach rootless podman API using unix to unix forwarding over ssh", func() { + ginkgo.It("should expose and reach rootless podman API using unix to unix forwarding over ssh", func() { if runtime.GOOS == "windows" { - Skip("AF_UNIX not supported on Windows") + ginkgo.Skip("AF_UNIX not supported on Windows") } unix2unixfwdsock, _ := filepath.Abs(filepath.Join(tmpDir, "podman-unix-to-unix-forwarding.sock")) remoteuri := fmt.Sprintf(`ssh-tunnel://root@%s:%d%s?key=%s`, "192.168.127.2", 22, podmanSock, privateKeyFile) _, err := sshExec(`curl http://192.168.127.1/services/forwarder/expose -X POST -d'{"protocol":"unix","local":"` + unix2unixfwdsock + `","remote":"` + remoteuri + `"}'`) - Expect(err).ShouldNot(HaveOccurred()) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) - Eventually(func(g Gomega) { + gomega.Eventually(func(g gomega.Gomega) { sockfile, err := os.Stat(unix2unixfwdsock) - g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(sockfile.Mode().Type().String()).To(Equal(os.ModeSocket.String())) - }).Should(Succeed()) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(sockfile.Mode().Type().String()).To(gomega.Equal(os.ModeSocket.String())) + }).Should(gomega.Succeed()) httpClient := &http.Client{ Transport: &http.Transport{ @@ -253,17 +253,17 @@ var _ = Describe("port forwarding", func() { }, } - Eventually(func(g Gomega) { + gomega.Eventually(func(g gomega.Gomega) { resp, err := httpClient.Get("http://host/_ping") - g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(resp.StatusCode).To(Equal(http.StatusOK)) - g.Expect(resp.ContentLength).To(Equal(int64(2))) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(resp.StatusCode).To(gomega.Equal(http.StatusOK)) + g.Expect(resp.ContentLength).To(gomega.Equal(int64(2))) reply := make([]byte, resp.ContentLength) _, err = io.ReadAtLeast(resp.Body, reply, len(reply)) - g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(string(reply)).To(Equal("OK")) - }).Should(Succeed()) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(string(reply)).To(gomega.Equal("OK")) + }).Should(gomega.Succeed()) }) }) diff --git a/test/suite_test.go b/test/suite_test.go index 9aaddb62a..5c08d5f12 100644 --- a/test/suite_test.go +++ b/test/suite_test.go @@ -13,15 +13,15 @@ import ( "testing" "time" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) func TestSuite(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "gvisor-tap-vsock suite") + gomega.RegisterFailHandler(ginkgo.Fail) + ginkgo.RunSpecs(t, "gvisor-tap-vsock suite") } const ( @@ -60,19 +60,19 @@ func init() { } -var _ = BeforeSuite(func() { - Expect(os.MkdirAll(filepath.Join(tmpDir, "disks"), os.ModePerm)).Should(Succeed()) +var _ = ginkgo.BeforeSuite(func() { + gomega.Expect(os.MkdirAll(filepath.Join(tmpDir, "disks"), os.ModePerm)).Should(gomega.Succeed()) downloader, err := NewFcosDownloader(filepath.Join(tmpDir, "disks")) - Expect(err).ShouldNot(HaveOccurred()) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) qemuImage, err := downloader.DownloadImage() - Expect(err).ShouldNot(HaveOccurred()) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) publicKey, err := createSSHKeys() - Expect(err).ShouldNot(HaveOccurred()) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) err = CreateIgnition(ignFile, publicKey, ignitionUser, ignitionPasswordHash) - Expect(err).ShouldNot(HaveOccurred()) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) outer: for panics := 0; ; panics++ { @@ -87,7 +87,7 @@ outer: host.Stderr = os.Stderr host.Stdout = os.Stdout - Expect(host.Start()).Should(Succeed()) + gomega.Expect(host.Start()).Should(gomega.Succeed()) go func() { if err := host.Wait(); err != nil { log.Error(err) @@ -109,7 +109,7 @@ outer: client = exec.Command(qemuExecutable(), strings.Split(fmt.Sprintf(template, qemuArgs(), qconLog, qemuImage, ignFile, qemuPort), " ")...) client.Stderr = os.Stderr client.Stdout = os.Stdout - Expect(client.Start()).Should(Succeed()) + gomega.Expect(client.Start()).Should(gomega.Succeed()) go func() { if err := client.Wait(); err != nil { log.Error(err) @@ -124,10 +124,10 @@ outer: // Check for panic didPanic, err := panicCheck(qconLog) - Expect(err).ShouldNot(HaveOccurred()) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) if didPanic { - Expect(panics).ToNot(BeNumerically(">", 15), "No more than 15 panics allowed") + gomega.Expect(panics).ToNot(gomega.BeNumerically(">", 15), "No more than 15 panics allowed") log.Info("Detected Kernel panic, retrying...") _ = client.Process.Kill() _ = host.Process.Kill() @@ -141,11 +141,11 @@ outer: } err = scp(filepath.Join(binDir, "test-companion"), "/tmp/test-companion") - Expect(err).ShouldNot(HaveOccurred()) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) // start an embedded DNS and http server in the VM. Wait a bit for the server to start. cmd := sshCommand("sudo /tmp/test-companion") - Expect(cmd.Start()).ShouldNot(HaveOccurred()) + gomega.Expect(cmd.Start()).ShouldNot(gomega.HaveOccurred()) time.Sleep(5 * time.Second) }) @@ -228,7 +228,7 @@ func panicCheck(con string) (bool, error) { return strings.Contains(string(contents), "end Kernel panic"), nil } -var _ = AfterSuite(func() { +var _ = ginkgo.AfterSuite(func() { if host != nil { if err := host.Process.Kill(); err != nil { log.Error(err)