Skip to content

Commit

Permalink
Speed up and improve integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jspdown authored Aug 27, 2020
1 parent 15b57b3 commit 85cbd06
Show file tree
Hide file tree
Showing 59 changed files with 1,913 additions and 3,189 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ helm-lint: helm
helm lint helm/chart/maesh

k3d:
@command -v k3d >/dev/null 2>&1 || curl -s https://raw.githubusercontent.com/rancher/k3d/v1.5.1/install.sh | TAG=v1.5.1 bash
@command -v k3d >/dev/null 2>&1 || curl -s https://raw.githubusercontent.com/rancher/k3d/v3.0.1/install.sh | TAG=v3.0.1 bash

pages:
mkdir -p $(CURDIR)/pages
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ module github.com/containous/maesh
go 1.14

require (
github.com/abronan/valkeyrie v0.0.0-20200127174252-ef4277a138cd
github.com/cenkalti/backoff/v4 v4.0.2
github.com/containous/traefik/v2 v2.3.0-rc3
github.com/go-check/check v0.0.0-20180628173108-788fd7840127
github.com/google/uuid v1.1.1
github.com/gorilla/mux v1.7.3
github.com/hashicorp/go-version v1.2.1
github.com/pmezard/go-difflib v1.0.0
github.com/servicemeshinterface/smi-sdk-go v0.4.1
github.com/sirupsen/logrus v1.6.0
github.com/stretchr/testify v1.6.1
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@ k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c/go.mod h1:GRQhZsXIAJ1xR0C9bd8UpWHZ5plfAS9fzPjJuQ6JL3E=
k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6 h1:Oh3Mzx5pJ+yIumsAD0MOECPVeXsVot0UkiaCGVyfGQY=
k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6/go.mod h1:GRQhZsXIAJ1xR0C9bd8UpWHZ5plfAS9fzPjJuQ6JL3E=
k8s.io/kubernetes v1.13.0 h1:qTfB+u5M92k2fCCCVP2iuhgwwSOv1EkAkvQY1tQODD8=
k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89 h1:d4vVOjXm687F1iLSP2q3lyPPuyvTUt3aVoBpi2DqRsU=
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
Expand Down
175 changes: 90 additions & 85 deletions integration/acl_disabled_test.go
Original file line number Diff line number Diff line change
@@ -1,123 +1,128 @@
package integration

import (
"net/http"
"time"

"github.com/containous/maesh/integration/k3d"
"github.com/containous/maesh/integration/tool"
"github.com/containous/maesh/integration/try"
"github.com/go-check/check"
"github.com/sirupsen/logrus"
checker "github.com/vdemeester/shakers"
corev1 "k8s.io/api/core/v1"
)

// ACLDisabledSuite.
type ACLDisabledSuite struct{ BaseSuite }
type ACLDisabledSuite struct {
logger logrus.FieldLogger
cluster *k3d.Cluster
tool *tool.Tool
}

func (s *ACLDisabledSuite) SetUpSuite(c *check.C) {
requiredImages := []string{
"containous/maesh:latest",
"containous/whoami:v1.0.1",
"containous/whoamitcp:v0.0.2",
"containous/whoamiudp:v0.0.1",
"coredns/coredns:1.6.3",
var err error

requiredImages := []k3d.DockerImage{
{Name: "containous/maesh:latest", Local: true},
{Name: "traefik:v2.3"},
{Name: "containous/whoami:v1.0.1"},
{Name: "containous/whoamitcp:v0.0.2"},
{Name: "containous/whoamiudp:v0.0.1"},
{Name: "giantswarm/tiny-tools:3.9"},
}
s.startk3s(c, requiredImages)
s.startAndWaitForCoreDNS(c)
s.createResources(c, "testdata/smi/crds/")
}

func (s *ACLDisabledSuite) TearDownSuite(c *check.C) {
s.stopK3s()
}
s.logger = logrus.New()
s.cluster, err = k3d.NewCluster(s.logger, masterURL, k3dClusterName,
k3d.WithoutTraefik(),
k3d.WithImages(requiredImages...),
)
c.Assert(err, checker.IsNil)

func (s *ACLDisabledSuite) TestHTTPService(c *check.C) {
s.createResources(c, "testdata/acl/disabled/http")
defer s.deleteResources(c, "testdata/acl/disabled/http")
defer s.deleteShadowServices(c)
c.Assert(s.cluster.CreateNamespace(s.logger, maeshNamespace), checker.IsNil)
c.Assert(s.cluster.CreateNamespace(s.logger, testNamespace), checker.IsNil)

s.waitForPods(c, []string{"server"})
c.Assert(s.cluster.Apply(s.logger, smiCRDs), checker.IsNil)
c.Assert(s.cluster.Apply(s.logger, "testdata/tool/tool.yaml"), checker.IsNil)
c.Assert(s.cluster.Apply(s.logger, "testdata/maesh/controller-acl-disabled.yaml"), checker.IsNil)
c.Assert(s.cluster.Apply(s.logger, "testdata/maesh/proxy.yaml"), checker.IsNil)

cmd := s.startMaeshBinaryCmd(c, false, false)
err := cmd.Start()
c.Assert(s.cluster.WaitReadyPod("tool", testNamespace, 60*time.Second), checker.IsNil)
c.Assert(s.cluster.WaitReadyDeployment("maesh-controller", maeshNamespace, 60*time.Second), checker.IsNil)
c.Assert(s.cluster.WaitReadyDaemonSet("maesh-mesh", maeshNamespace, 60*time.Second), checker.IsNil)

c.Assert(err, checker.IsNil)
defer s.stopMaeshBinary(c, cmd.Process)
s.tool = tool.New(s.logger, "tool", testNamespace)
}

config := s.testConfigurationWithReturn(c, "testdata/acl/disabled/http.json")
func (s *ACLDisabledSuite) TearDownSuite(c *check.C) {
if s.cluster != nil {
c.Assert(s.cluster.Stop(s.logger), checker.IsNil)
}
}

serverSvc := s.getService(c, "server")
serverPod := s.getPod(c, "server")
// TestHTTPService deploys an HTTP service "server" with one Pod called "server" and asserts this service is
// reachable and responses are served by this Pod.
func (s *ACLDisabledSuite) TestHTTPService(c *check.C) {
c.Assert(s.cluster.Apply(s.logger, "testdata/acl_disabled/http"), checker.IsNil)
defer s.cluster.Delete(s.logger, "testdata/acl_disabled/http")

s.checkBlockAllMiddleware(c, config)
s.checkHTTPReadinessService(c, config)
s.checkHTTPServiceLoadBalancer(c, config, serverSvc, []*corev1.Pod{serverPod})
s.assertHTTPServiceReachable(c, "server-http.test.maesh:8080", "server-http", 60*time.Second)
}

// TestTCPService deploys a TCP service "server" with one Pod called "server" and asserts this service is
// reachable and that a connection has been established with this Pod.
func (s *ACLDisabledSuite) TestTCPService(c *check.C) {
s.createResources(c, "testdata/acl/disabled/tcp")
defer s.deleteResources(c, "testdata/acl/disabled/tcp")
defer s.deleteShadowServices(c)

s.waitForPods(c, []string{"server"})

cmd := s.startMaeshBinaryCmd(c, false, false)
err := cmd.Start()

c.Assert(err, checker.IsNil)
defer s.stopMaeshBinary(c, cmd.Process)

config := s.testConfigurationWithReturn(c, "testdata/acl/disabled/tcp.json")
c.Assert(s.cluster.Apply(s.logger, "testdata/acl_disabled/tcp"), checker.IsNil)
defer s.cluster.Delete(s.logger, "testdata/acl_disabled/tcp")

serverSvc := s.getService(c, "server")
serverPod := s.getPod(c, "server")

s.checkHTTPReadinessService(c, config)
s.checkTCPServiceLoadBalancer(c, config, serverSvc, []*corev1.Pod{serverPod})
s.assertTCPServiceReachable(c, "server-tcp.test.maesh", 8080, "server-tcp", 60*time.Second)
}

func (s *ACLDisabledSuite) TestUDPService(c *check.C) {
s.createResources(c, "testdata/acl/disabled/udp")
defer s.deleteResources(c, "testdata/acl/disabled/udp")
defer s.deleteShadowServices(c)

s.waitForPods(c, []string{"server"})

cmd := s.startMaeshBinaryCmd(c, false, false)
err := cmd.Start()

c.Assert(err, checker.IsNil)
defer s.stopMaeshBinary(c, cmd.Process)

config := s.testConfigurationWithReturn(c, "testdata/acl/disabled/udp.json")
// TestUDPService deploys a UDP service "server" with one Pod called "server" and asserts this service is
// reachable and that a connection has been established with this Pod.
func (s *ACLDisabledSuite) TestUDPervice(c *check.C) {
c.Assert(s.cluster.Apply(s.logger, "testdata/acl_disabled/udp"), checker.IsNil)
defer s.cluster.Delete(s.logger, "testdata/acl_disabled/udp")

serverSvc := s.getService(c, "server")
serverPod := s.getPod(c, "server")

s.checkHTTPReadinessService(c, config)
s.checkUDPServiceLoadBalancer(c, config, serverSvc, []*corev1.Pod{serverPod})
s.assertUDPServiceReachable(c, "server-udp.test.maesh", 8080, "server-udp", 60*time.Second)
}

// TestSplitTraffic deploys an HTTP service "server" and a TrafficSplit attached to it configured to distribute equally
// the load between two service "server-v1" and "server-v2", each one having a Pod with the same name. This test ensure
// both Pods are reachable through the service "server".
func (s *ACLDisabledSuite) TestSplitTraffic(c *check.C) {
s.createResources(c, "testdata/acl/disabled/traffic-split")
defer s.deleteResources(c, "testdata/acl/disabled/traffic-split")
defer s.deleteShadowServices(c)
c.Assert(s.cluster.Apply(s.logger, "testdata/acl_disabled/traffic-split"), checker.IsNil)
defer s.cluster.Delete(s.logger, "testdata/acl_disabled/traffic-split")

s.waitForPods(c, []string{"server-v1", "server-v2"})
s.assertHTTPServiceReachable(c, "server-split.test.maesh:8080", "server-v1", 60*time.Second)
s.assertHTTPServiceReachable(c, "server-split.test.maesh:8080", "server-v2", 30*time.Second)
}

cmd := s.startMaeshBinaryCmd(c, false, false)
err := cmd.Start()
func (s *ACLDisabledSuite) assertHTTPServiceReachable(c *check.C, url, expectedHostname string, timeout time.Duration) {
s.logger.Infof("Asserting HTTP service is reachable on %q and Pod %q has handled the request", url, expectedHostname)

err := try.Retry(func() error {
return s.tool.Curl(url, nil,
try.StatusCodeIs(http.StatusOK),
try.BodyContains("Hostname: "+expectedHostname),
)
}, timeout)
c.Assert(err, checker.IsNil)
defer s.stopMaeshBinary(c, cmd.Process)

config := s.testConfigurationWithReturn(c, "testdata/acl/disabled/traffic-split.json")

s.checkBlockAllMiddleware(c, config)
s.checkHTTPReadinessService(c, config)
}

serverV1Svc := s.getService(c, "server-v1")
serverV1Pod := s.getPod(c, "server-v1")
func (s *ACLDisabledSuite) assertTCPServiceReachable(c *check.C, url string, port int, expectedHostname string, timeout time.Duration) {
s.logger.Infof("Asserting TCP service is reachable on '%s:%d' and a connection with Pod %q is established", url, port, expectedHostname)

s.checkHTTPServiceLoadBalancer(c, config, serverV1Svc, []*corev1.Pod{serverV1Pod})
err := try.Retry(func() error {
return s.tool.Netcat(url, port, false, try.StringContains("Hostname: "+expectedHostname))
}, timeout)
c.Assert(err, checker.IsNil)
}

serverV2Svc := s.getService(c, "server-v2")
serverV2Pod := s.getPod(c, "server-v2")
func (s *ACLDisabledSuite) assertUDPServiceReachable(c *check.C, url string, port int, expectedHostname string, timeout time.Duration) {
s.logger.Infof("Asserting UDP service is reachable on '%s:%d' and a connection with Pod %q is established", url, port, expectedHostname)

s.checkHTTPServiceLoadBalancer(c, config, serverV2Svc, []*corev1.Pod{serverV2Pod})
err := try.Retry(func() error {
return s.tool.Netcat(url, port, true, try.StringContains("Hostname: "+expectedHostname))
}, timeout)
c.Assert(err, checker.IsNil)
}
Loading

0 comments on commit 85cbd06

Please sign in to comment.