-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speed up and improve integration tests
- Loading branch information
Showing
59 changed files
with
1,913 additions
and
3,189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.