aboutsummaryrefslogtreecommitdiffstats
path: root/extras/hs-test/proxy_test.go
diff options
context:
space:
mode:
authorMaros Ondrejicka <maros.ondrejicka@pantheon.tech>2022-12-14 16:30:04 +0100
committerFlorin Coras <florin.coras@gmail.com>2022-12-19 17:11:52 +0000
commitdb823ed6e9543741f6969ff160314093002e037e (patch)
treebf046f85d1052058da38192687874e361c684e4c /extras/hs-test/proxy_test.go
parentaff4d320f0fe9ce68fcb83ee9ab0abc2d8612644 (diff)
hs-test: abstract away topology from test cases
Definition of shared volumes and containers has been moved to yaml files to be together with network topology. Containers are automatically run at the beginning of each test case and stopped afterward. Type: test Signed-off-by: Maros Ondrejicka <maros.ondrejicka@pantheon.tech> Change-Id: I264cbb4f1355f8bd7aade221e9609fb5b9bd693e
Diffstat (limited to 'extras/hs-test/proxy_test.go')
-rwxr-xr-xextras/hs-test/proxy_test.go79
1 files changed, 30 insertions, 49 deletions
diff --git a/extras/hs-test/proxy_test.go b/extras/hs-test/proxy_test.go
index 0ada6fad0f7..952bcc5aa76 100755
--- a/extras/hs-test/proxy_test.go
+++ b/extras/hs-test/proxy_test.go
@@ -1,34 +1,22 @@
package main
import (
- "context"
"fmt"
"os"
"github.com/edwarnicke/exechelper"
)
-func testProxyHttpTcp(s *NsSuite, dockerInstance, action string, proxySetup func() error) error {
+func testProxyHttpTcp(s *NsSuite, proxySetup func() error) error {
const outputFile = "test.data"
const srcFile = "10M"
stopServer := make(chan struct{}, 1)
serverRunning := make(chan struct{}, 1)
- volumeArgs := fmt.Sprintf("-v shared-vol:/tmp/%s", dockerInstance)
- s.assertNil(dockerRun(dockerInstance, volumeArgs), "failed to start container")
- defer func() { exechelper.Run("docker stop " + dockerInstance) }()
-
- // start & configure vpp in the container
- _, err := hstExec(action, dockerInstance)
- s.assertNil(err)
-
- fmt.Println("VPP running and configured...")
-
s.assertNil(proxySetup(), "failed to setup proxy")
- fmt.Println("Proxy configured...")
// create test file
- err = exechelper.Run(fmt.Sprintf("ip netns exec server truncate -s %s %s", srcFile, srcFile))
+ err := exechelper.Run(fmt.Sprintf("ip netns exec server truncate -s %s %s", srcFile, srcFile))
s.assertNil(err, "failed to run truncate command")
defer func() { os.Remove(srcFile) }()
@@ -55,50 +43,43 @@ func testProxyHttpTcp(s *NsSuite, dockerInstance, action string, proxySetup func
return nil
}
-func setupEnvoy(ctx context.Context, dockerInstance string) error {
- errCh := startEnvoy(ctx, dockerInstance)
- select {
- case err := <-errCh:
- return err
- default:
- }
-
- go func(ctx context.Context, errCh <-chan error) {
- for {
- select {
- // handle cancel() call from outside to gracefully stop the routine
- case <-ctx.Done():
- return
- default:
- select {
- case err := <-errCh:
- fmt.Printf("error while running envoy: %v", err)
- default:
- }
- }
- }
- }(ctx, errCh)
+func configureVppProxy(s *NsSuite) error {
+ container := s.getContainerByName("vpp")
+ testVppProxy := NewVppInstance(container)
+ testVppProxy.setVppProxy()
+ err := testVppProxy.start()
+ s.assertNil(err, "failed to start and configure VPP")
+ fmt.Println("VPP running and configured...")
+
+ output, err := testVppProxy.vppctl("test proxy server server-uri tcp://10.0.0.2/555 client-uri tcp://10.0.1.1/666")
+ fmt.Println("Proxy configured...", string(output))
return nil
}
func (s *NsSuite) TestVppProxyHttpTcp() {
- dockerInstance := "vpp-proxy"
- err := testProxyHttpTcp(s, dockerInstance, "ConfigureVppProxy", configureVppProxy)
+ err := testProxyHttpTcp(s, func() error {
+ return configureVppProxy(s)
+ })
s.assertNil(err)
}
-func (s *NsSuite) TestEnvoyProxyHttpTcp() {
- exechelper.Run("docker volume create --name=shared-vol")
- defer func() {
- exechelper.Run("docker stop envoy")
- }()
+func configureEnvoyProxy(s *NsSuite) error {
+ vppContainer := s.getContainerByName("vpp")
+ testVppForEnvoyProxy := NewVppInstance(vppContainer)
+ testVppForEnvoyProxy.setEnvoyProxy()
+ err := testVppForEnvoyProxy.start()
+ s.assertNil(err, "failed to start and configure VPP")
- ctx, cancel := context.WithCancel(context.Background())
+ envoyContainer := s.getContainerByName("envoy")
+ envoyContainer.run()
- dockerInstance := "vpp-envoy"
- err := testProxyHttpTcp(s, dockerInstance, "ConfigureEnvoyProxy", func() error {
- return setupEnvoy(ctx, dockerInstance)
+ fmt.Println("VPP running and configured...")
+ return nil
+}
+
+func (s *NsSuite) TestEnvoyProxyHttpTcp() {
+ err := testProxyHttpTcp(s, func() error {
+ return configureEnvoyProxy(s)
})
s.assertNil(err)
- cancel()
}