8 "github.com/edwarnicke/exechelper"
11 func testProxyHttpTcp(s *NsSuite, dockerInstance, action string, proxySetup func() error) error {
12 const outputFile = "test.data"
14 stopServer := make(chan struct{}, 1)
15 serverRunning := make(chan struct{}, 1)
17 volumeArgs := fmt.Sprintf("-v shared-vol:/tmp/%s", dockerInstance)
18 s.assertNil(dockerRun(dockerInstance, volumeArgs), "failed to start container")
19 defer func() { exechelper.Run("docker stop " + dockerInstance) }()
21 // start & configure vpp in the container
22 _, err := hstExec(action, dockerInstance)
25 fmt.Println("VPP running and configured...")
27 s.assertNil(proxySetup(), "failed to setup proxy")
28 fmt.Println("Proxy configured...")
31 err = exechelper.Run(fmt.Sprintf("ip netns exec server truncate -s %s %s", srcFile, srcFile))
32 s.assertNil(err, "failed to run truncate command")
33 defer func() { os.Remove(srcFile) }()
35 fmt.Println("Test file created...")
37 go startHttpServer(serverRunning, stopServer, ":666", "server")
38 // TODO better error handling and recovery
41 defer func(chan struct{}) {
42 stopServer <- struct{}{}
45 fmt.Println("http server started...")
47 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)
48 _, err = exechelper.CombinedOutput(c)
49 s.assertNil(err, "failed to run wget")
50 stopServer <- struct{}{}
52 defer func() { os.Remove(outputFile) }()
54 s.assertNil(assertFileSize(outputFile, srcFile))
58 func setupEnvoy(ctx context.Context, dockerInstance string) error {
59 errCh := startEnvoy(ctx, dockerInstance)
66 go func(ctx context.Context, errCh <-chan error) {
69 // handle cancel() call from outside to gracefully stop the routine
75 fmt.Printf("error while running envoy: %v", err)
84 func (s *NsSuite) TestVppProxyHttpTcp() {
85 dockerInstance := "vpp-proxy"
86 err := testProxyHttpTcp(s, dockerInstance, "ConfigureVppProxy", configureVppProxy)
90 func (s *NsSuite) TestEnvoyProxyHttpTcp() {
91 exechelper.Run("docker volume create --name=shared-vol")
93 exechelper.Run("docker stop envoy")
96 ctx, cancel := context.WithCancel(context.Background())
98 dockerInstance := "vpp-envoy"
99 err := testProxyHttpTcp(s, dockerInstance, "ConfigureEnvoyProxy", func() error {
100 return setupEnvoy(ctx, dockerInstance)