7 "github.com/edwarnicke/exechelper"
10 func testProxyHttpTcp(s *NsSuite, proxySetup func() error) error {
11 const outputFile = "test.data"
13 stopServer := make(chan struct{}, 1)
14 serverRunning := make(chan struct{}, 1)
16 s.assertNil(proxySetup(), "failed to setup proxy")
19 err := exechelper.Run(fmt.Sprintf("ip netns exec server truncate -s %s %s", srcFile, srcFile))
20 s.assertNil(err, "failed to run truncate command")
21 defer func() { os.Remove(srcFile) }()
23 s.log("Test file created...")
25 go startHttpServer(serverRunning, stopServer, ":666", "server")
26 // TODO better error handling and recovery
29 defer func(chan struct{}) {
30 stopServer <- struct{}{}
33 s.log("http server started...")
35 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)
36 _, err = exechelper.CombinedOutput(c)
37 s.assertNil(err, "failed to run wget")
38 stopServer <- struct{}{}
40 defer func() { os.Remove(outputFile) }()
42 s.assertNil(assertFileSize(outputFile, srcFile))
46 func configureVppProxy(s *NsSuite) error {
47 container := s.getContainerByName("vpp")
48 testVppProxy := NewVppInstance(container)
49 testVppProxy.setVppProxy()
50 err := testVppProxy.start()
51 s.assertNil(err, "failed to start and configure VPP")
52 s.log("VPP running and configured...")
54 output, err := testVppProxy.vppctl("test proxy server server-uri tcp://10.0.0.2/555 client-uri tcp://10.0.1.1/666")
55 s.log("Proxy configured...", string(output))
59 func (s *NsSuite) TestVppProxyHttpTcp() {
60 err := testProxyHttpTcp(s, func() error {
61 return configureVppProxy(s)
66 func configureEnvoyProxy(s *NsSuite) error {
67 vppContainer := s.getContainerByName("vpp")
68 testVppForEnvoyProxy := NewVppInstance(vppContainer)
69 testVppForEnvoyProxy.setEnvoyProxy()
70 err := testVppForEnvoyProxy.start()
71 s.assertNil(err, "failed to start and configure VPP")
73 envoyContainer := s.getContainerByName("envoy")
76 s.log("VPP running and configured...")
80 func (s *NsSuite) TestEnvoyProxyHttpTcp() {
81 err := testProxyHttpTcp(s, func() error {
82 return configureEnvoyProxy(s)