9 "github.com/edwarnicke/exechelper"
12 func testProxyHttpTcp(t *testing.T, dockerInstance string, proxySetup func() error) error {
13 const outputFile = "test.data"
15 stopServer := make(chan struct{}, 1)
16 serverRunning := make(chan struct{}, 1)
18 volumeArgs := fmt.Sprintf("-v shared-vol:/tmp/%s", dockerInstance)
19 err := dockerRun(dockerInstance, volumeArgs)
21 return fmt.Errorf("failed to start container: %v", err)
23 defer func() { exechelper.Run("docker stop " + dockerInstance) }()
25 // start & configure vpp in the container
26 _, err = hstExec(dockerInstance, dockerInstance)
28 return fmt.Errorf("error starting vpp in container: %v", err)
31 fmt.Println("VPP running and configured...")
33 if err := proxySetup(); err != nil {
34 return fmt.Errorf("failed to setup proxy: %v", err)
36 fmt.Println("Proxy configured...")
39 err = exechelper.Run(fmt.Sprintf("ip netns exec server truncate -s %s %s", srcFile, srcFile))
41 return fmt.Errorf("failed to run truncate command")
43 defer func() { os.Remove(srcFile) }()
45 fmt.Println("Test file created...")
47 go startHttpServer(serverRunning, stopServer, ":666", "server")
48 // TODO better error handling and recovery
51 defer func(chan struct{}) {
52 stopServer <- struct{}{}
55 fmt.Println("http server started...")
57 c := fmt.Sprintf("ip netns exec client wget --retry-connrefused --retry-on-http-error=503 --tries=10 -O %s 10.0.0.2:555/%s", outputFile, srcFile)
58 _, err = exechelper.CombinedOutput(c)
60 return fmt.Errorf("failed to run wget: %v", err)
62 stopServer <- struct{}{}
64 defer func() { os.Remove(outputFile) }()
66 if err = assertFileSize(outputFile, srcFile); err != nil {
72 func (s *NsSuite) TestVppProxyHttpTcp() {
74 dockerInstance := "vpp-proxy"
75 err := testProxyHttpTcp(t, dockerInstance, configureVppProxy)
81 func (s *NsSuite) TestEnvoyProxyHttpTcp() {
83 exechelper.Run("docker volume create --name=shared-vol")
85 exechelper.Run("docker stop envoy")
88 ctx, cancel := context.WithCancel(context.Background())
90 dockerInstance := "vpp-envoy"
91 err := testProxyHttpTcp(t, dockerInstance, func() error {
92 return setupEnvoy(t, ctx, dockerInstance)