diff --git a/integration/integration_linux_test.go b/integration/integration_linux_test.go index 82c8d488..08b2bfaf 100644 --- a/integration/integration_linux_test.go +++ b/integration/integration_linux_test.go @@ -225,23 +225,22 @@ func (n Namespace) Del() { } func makeTcpClientInNS(netns string, address string, port int, numBytes int) { - message := bytes.Repeat([]byte{'a'}, numBytes) + payload := bytes.Repeat([]byte{'a'}, numBytes) + message := string(payload) - bin, err := exec.LookPath("nc") - Expect(err).NotTo(HaveOccurred()) var cmd *exec.Cmd if netns != "" { netns = filepath.Base(netns) - cmd = exec.Command("ip", "netns", "exec", netns, bin, "-v", address, strconv.Itoa(port)) + cmd = exec.Command("ip", "netns", "exec", netns, echoClientBinaryPath, "--target", fmt.Sprintf("%s:%d", address, port), "--message", message) } else { - cmd = exec.Command("nc", address, strconv.Itoa(port)) + cmd = exec.Command(echoClientBinaryPath, "--target", fmt.Sprintf("%s:%d", address, port), "--message", message) } cmd.Stdin = bytes.NewBuffer([]byte(message)) cmd.Stderr = GinkgoWriter out, err := cmd.Output() Expect(err).NotTo(HaveOccurred()) - Expect(string(out)).To(Equal(string(message))) + Expect(string(out)).To(Equal(message)) } func startEchoServerInNamespace(netNS Namespace) (int, *gexec.Session, error) { diff --git a/integration/integration_suite_test.go b/integration/integration_suite_test.go index 4cff6e28..de861c45 100644 --- a/integration/integration_suite_test.go +++ b/integration/integration_suite_test.go @@ -14,11 +14,10 @@ package integration_test import ( - "math/rand" + "strings" "testing" . "github.com/onsi/ginkgo" - "github.com/onsi/ginkgo/config" . "github.com/onsi/gomega" "github.com/onsi/gomega/gexec" ) @@ -28,15 +27,18 @@ func TestIntegration(t *testing.T) { RunSpecs(t, "integration") } -var echoServerBinaryPath string +var echoServerBinaryPath, echoClientBinaryPath string var _ = SynchronizedBeforeSuite(func() []byte { - binaryPath, err := gexec.Build("github.com/containernetworking/plugins/pkg/testutils/echosvr") + serverBinaryPath, err := gexec.Build("github.com/containernetworking/plugins/pkg/testutils/echo/server") Expect(err).NotTo(HaveOccurred()) - return []byte(binaryPath) + clientBinaryPath, err := gexec.Build("github.com/containernetworking/plugins/pkg/testutils/echo/client") + Expect(err).NotTo(HaveOccurred()) + return []byte(strings.Join([]string{serverBinaryPath, clientBinaryPath}, ",")) }, func(data []byte) { - echoServerBinaryPath = string(data) - rand.Seed(config.GinkgoConfig.RandomSeed + int64(GinkgoParallelNode())) + binaries := strings.Split(string(data), ",") + echoServerBinaryPath = binaries[0] + echoClientBinaryPath = binaries[1] }) var _ = SynchronizedAfterSuite(func() {}, func() { diff --git a/pkg/testutils/echo/client/client b/pkg/testutils/echo/client/client deleted file mode 100755 index 3a9353a7..00000000 Binary files a/pkg/testutils/echo/client/client and /dev/null differ diff --git a/pkg/testutils/echo/echo_test.go b/pkg/testutils/echo/echo_test.go index a0045fee..12523a59 100644 --- a/pkg/testutils/echo/echo_test.go +++ b/pkg/testutils/echo/echo_test.go @@ -20,7 +20,7 @@ var _ = SynchronizedBeforeSuite(func() []byte { Expect(err).NotTo(HaveOccurred()) clientBinaryPath, err := gexec.Build("github.com/containernetworking/plugins/pkg/testutils/echo/client") Expect(err).NotTo(HaveOccurred()) - return []byte(fmt.Sprintf("%s,%s", serverBinaryPath, clientBinaryPath)) + return []byte(strings.Join([]string{serverBinaryPath, clientBinaryPath}, ",")) }, func(data []byte) { binaries := strings.Split(string(data), ",") serverBinaryPath = binaries[0] diff --git a/plugins/meta/bandwidth/bandwidth_suite_test.go b/plugins/meta/bandwidth/bandwidth_suite_test.go index 594cd9f3..a0e34ac0 100644 --- a/plugins/meta/bandwidth/bandwidth_suite_test.go +++ b/plugins/meta/bandwidth/bandwidth_suite_test.go @@ -39,14 +39,18 @@ func TestTBF(t *testing.T) { RunSpecs(t, "plugins/meta/bandwidth") } -var echoServerBinaryPath string +var echoServerBinaryPath, echoClientBinaryPath string var _ = SynchronizedBeforeSuite(func() []byte { - binaryPath, err := gexec.Build("github.com/containernetworking/plugins/pkg/testutils/echosvr") + serverBinaryPath, err := gexec.Build("github.com/containernetworking/plugins/pkg/testutils/echo/server") Expect(err).NotTo(HaveOccurred()) - return []byte(binaryPath) + clientBinaryPath, err := gexec.Build("github.com/containernetworking/plugins/pkg/testutils/echo/client") + Expect(err).NotTo(HaveOccurred()) + return []byte(strings.Join([]string{serverBinaryPath, clientBinaryPath}, ",")) }, func(data []byte) { - echoServerBinaryPath = string(data) + binaries := strings.Split(string(data), ",") + echoServerBinaryPath = binaries[0] + echoClientBinaryPath = binaries[1] }) var _ = SynchronizedAfterSuite(func() {}, func() { @@ -84,23 +88,22 @@ func startEchoServerInNamespace(netNS ns.NetNS) (int, *gexec.Session, error) { } func makeTcpClientInNS(netns string, address string, port int, numBytes int) { - message := bytes.Repeat([]byte{'a'}, numBytes) + payload := bytes.Repeat([]byte{'a'}, numBytes) + message := string(payload) - bin, err := exec.LookPath("nc") - Expect(err).NotTo(HaveOccurred()) var cmd *exec.Cmd if netns != "" { netns = filepath.Base(netns) - cmd = exec.Command("ip", "netns", "exec", netns, bin, "-v", address, strconv.Itoa(port)) + cmd = exec.Command("ip", "netns", "exec", netns, echoClientBinaryPath, "--target", fmt.Sprintf("%s:%d", address, port), "--message", message) } else { - cmd = exec.Command("nc", address, strconv.Itoa(port)) + cmd = exec.Command(echoClientBinaryPath, "--target", fmt.Sprintf("%s:%d", address, port), "--message", message) } cmd.Stdin = bytes.NewBuffer([]byte(message)) cmd.Stderr = GinkgoWriter out, err := cmd.Output() Expect(err).NotTo(HaveOccurred()) - Expect(string(out)).To(Equal(string(message))) + Expect(string(out)).To(Equal(message)) } func createVeth(hostNamespace string, hostVethIfName string, containerNamespace string, containerVethIfName string, hostIP []byte, containerIP []byte, hostIfaceMTU int) { diff --git a/plugins/meta/portmap/portmap_integ_test.go b/plugins/meta/portmap/portmap_integ_test.go index 22a7f5bd..63d67b4e 100644 --- a/plugins/meta/portmap/portmap_integ_test.go +++ b/plugins/meta/portmap/portmap_integ_test.go @@ -23,7 +23,6 @@ import ( "os" "os/exec" "path/filepath" - "strconv" "github.com/containernetworking/cni/libcni" "github.com/containernetworking/cni/pkg/types/current" @@ -227,16 +226,14 @@ var _ = Describe("portmap integration tests", func() { // testEchoServer returns true if we found an echo server on the port func testEchoServer(address string, port int, netns string) bool { - message := "Aliquid melius quam pessimum optimum non est." + message := "'Aliquid melius quam pessimum optimum non est.'" - bin, err := exec.LookPath("nc") - Expect(err).NotTo(HaveOccurred()) var cmd *exec.Cmd if netns != "" { netns = filepath.Base(netns) - cmd = exec.Command("ip", "netns", "exec", netns, bin, "-v", address, strconv.Itoa(port)) + cmd = exec.Command("ip", "netns", "exec", netns, echoClientBinaryPath, "--target", fmt.Sprintf("%s:%d", address, port), "--message", message) } else { - cmd = exec.Command("nc", address, strconv.Itoa(port)) + cmd = exec.Command(echoClientBinaryPath, "--target", fmt.Sprintf("%s:%d", address, port), "--message", message) } cmd.Stdin = bytes.NewBufferString(message) cmd.Stderr = GinkgoWriter diff --git a/plugins/meta/portmap/portmap_suite_test.go b/plugins/meta/portmap/portmap_suite_test.go index 5826cfce..55aee924 100644 --- a/plugins/meta/portmap/portmap_suite_test.go +++ b/plugins/meta/portmap/portmap_suite_test.go @@ -40,14 +40,18 @@ func TestPortmap(t *testing.T) { RunSpecs(t, "plugins/meta/portmap") } -var echoServerBinaryPath string +var echoServerBinaryPath, echoClientBinaryPath string var _ = SynchronizedBeforeSuite(func() []byte { - binaryPath, err := gexec.Build("github.com/containernetworking/plugins/pkg/testutils/echosvr") + serverBinaryPath, err := gexec.Build("github.com/containernetworking/plugins/pkg/testutils/echo/server") Expect(err).NotTo(HaveOccurred()) - return []byte(binaryPath) + clientBinaryPath, err := gexec.Build("github.com/containernetworking/plugins/pkg/testutils/echo/client") + Expect(err).NotTo(HaveOccurred()) + return []byte(strings.Join([]string{serverBinaryPath, clientBinaryPath}, ",")) }, func(data []byte) { - echoServerBinaryPath = string(data) + binaries := strings.Split(string(data), ",") + echoServerBinaryPath = binaries[0] + echoClientBinaryPath = binaries[1] }) var _ = SynchronizedAfterSuite(func() {}, func() {