Skip to content

Commit

Permalink
Rework Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dtomcej committed Feb 7, 2020
1 parent 4c9df07 commit ccc118f
Show file tree
Hide file tree
Showing 34 changed files with 1,537 additions and 648 deletions.
9 changes: 7 additions & 2 deletions .golangci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
[linters-settings.gocyclo]
min-complexity = 15.0

[linters-settings.gocognit]
min-complexity = 35.0 # FIXME should be 10-20

[linters-settings.maligned]
suggest-new = true

Expand All @@ -25,15 +28,17 @@
[linters]
enable-all = true
disable = [
"lll",
"gas",
"lll", # Long lines are ok.
"dupl",
"prealloc",
"maligned",
"gochecknoinits",
"gochecknoglobals",
"gomnd", # Currently not needed FIXME in future
"gosec", # Does not allow exec.Command with variable
"scopelint",
"funlen",
"bodyclose", # Too many false positives
]

[issues]
Expand Down
2 changes: 1 addition & 1 deletion .semaphoreci/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ sudo ln -s /usr/local/golang/"${GO_VERSION}"/go/bin/go /usr/local/bin/go
export GOROOT="/usr/local/golang/${GO_VERSION}/go"
export GOTOOLDIR="/usr/local/golang/${GO_VERSION}/go/pkg/tool/linux_amd64"

go version
go version
6 changes: 3 additions & 3 deletions .semaphoreci/setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# For personnal CI
# mv /home/runner/workspace/src/github.com/<username>/ /home/runner/workspace/src/github.com/containous/
# cd /home/runner/workspace/src/github.com/containous/maesh/
for s in apache2 cassandra elasticsearch memcached mysql mongod postgresql sphinxsearch rethinkdb rabbitmq-server redis-server; do sudo service $s stop; done
sudo swapoff -a
sudo dd if=/dev/zero of=/swapfile bs=1M count=3072
Expand All @@ -24,7 +22,9 @@ if [ -f "./.semaphoreci/golang.sh" ]; then ./.semaphoreci/golang.sh; fi
if [ -f "./.semaphoreci/golang.sh" ]; then export GOROOT="/usr/local/golang/${GO_VERSION}/go"; fi
if [ -f "./.semaphoreci/golang.sh" ]; then export GOTOOLDIR="/usr/local/golang/${GO_VERSION}/go/pkg/tool/linux_amd64"; fi
go version

mkdir -p /home/runner/src/github.com/containous
cp -r /home/runner/maesh /home/runner/src/github.com/containous
cd /home/runner/src/github.com/containous/maesh
if [ -f "./go.mod" ]; then export GO111MODULE=on; fi
if [ -f "./go.mod" ]; then export GOPROXY=https://proxy.golang.org; fi
if [ -f "./go.mod" ]; then go mod download; fi
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ WORKDIR /go/src/github.com/containous/maesh
RUN curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh

# Download golangci-lint binary to bin folder in $GOPATH
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.21.0
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.22.2

ENV GO111MODULE on
COPY go.mod go.sum ./
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DOCKER_IMAGE_NAME := containous/maesh

UNAME := $(shell uname)
SRCS = $(shell git ls-files '*.go' | grep -v '^vendor/')

BINARY_NAME = maesh
Expand Down Expand Up @@ -28,7 +28,7 @@ clean:
local-check: $(DIST_DIR) helm-lint
golangci-lint run --config .golangci.toml

# Build
# Local commands
local-build: $(DIST_DIR)
CGO_ENABLED=0 go build -o ${DIST_DIR_MAESH} -ldflags="-s -w \
-X github.com/containous/$(BINARY_NAME)/cmd/version.version=$(VERSION) \
Expand All @@ -39,8 +39,14 @@ local-build: $(DIST_DIR)
local-test: clean
go test -v -cover ./...

# Integration test
ifeq ($(UNAME), Linux)
test-integration: $(DIST_DIR) kubectl helm build k3d
else
test-integration: $(DIST_DIR) kubectl helm build local-build k3d
endif
CGO_ENABLED=0 go test ./integration -integration $(INTEGRATION_TEST_OPTS)

test-integration-nobuild: $(DIST_DIR) kubectl helm k3d
CGO_ENABLED=0 go test ./integration -integration $(INTEGRATION_TEST_OPTS)

kubectl:
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ go 1.13

// Kubernetes version kubernetes-1.15.3
require (
github.com/abronan/valkeyrie v0.0.0-20190802193736-ed4c4a229894
github.com/cenkalti/backoff/v3 v3.0.0
github.com/containous/traefik/v2 v2.0.2
github.com/deislabs/smi-sdk-go v0.2.1-0.20191211172751-4e51d4dc331e
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/pmezard/go-difflib v1.0.0
github.com/sirupsen/logrus v1.4.2
github.com/stretchr/testify v1.4.0
github.com/vdemeester/shakers v0.1.0
Expand Down
94 changes: 94 additions & 0 deletions go.sum

Large diffs are not rendered by default.

50 changes: 36 additions & 14 deletions integration/coredns_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package integration

import (
"os"

"github.com/go-check/check"
checker "github.com/vdemeester/shakers"
)
Expand All @@ -9,7 +11,16 @@ import (
type CoreDNSSuite struct{ BaseSuite }

func (s *CoreDNSSuite) SetUpSuite(c *check.C) {
s.startk3s(c)
requiredImages := []string{
"containous/whoami:v1.0.1",
"coredns/coredns:1.2.6",
"coredns/coredns:1.3.1",
"coredns/coredns:1.4.0",
"coredns/coredns:1.5.2",
"coredns/coredns:1.6.3",
"giantswarm/tiny-tools:3.9",
}
s.startk3s(c, requiredImages)
s.startAndWaitForCoreDNS(c)
s.startWhoami(c)
s.installTinyToolsMaesh(c)
Expand Down Expand Up @@ -48,26 +59,37 @@ func (s *CoreDNSSuite) TestCoreDNSVersion(c *check.C) {
}

for _, test := range testCases {
pod := s.getToolsPodMaesh(c)
c.Assert(pod, checker.NotNil)
s.WaitForCoreDNS(c)
c.Log("Testing compatibility with " + test.desc)
s.setCoreDNSVersion(c, test.version)

argSlice := []string{
"exec", "-it", pod.Name, "-n", pod.Namespace, "-c", pod.Spec.Containers[0].Name, "--", "curl", "whoami.whoami.maesh", "--max-time", "5",
}
args := []string{}
cmd := s.maeshPrepareWithArgs(args...)
cmd.Env = os.Environ()
output, err := cmd.CombinedOutput()

c.Log(test.desc)
s.setCoreDNSVersion(c, test.version)
err := s.installHelmMaesh(c, false, false)
c.Log(string(output))

if test.expectedError {
err = s.waitForMaeshControllerStartedWithReturn()
c.Assert(err, checker.NotNil)
} else {
c.Assert(err, checker.IsNil)
s.waitForMaeshControllerStarted(c)
s.waitKubectlExecCommand(c, argSlice, "whoami")
}

s.unInstallHelmMaesh(c)
}
}

func (s *CoreDNSSuite) TestCoreDNS(c *check.C) {
s.WaitForCoreDNS(c)
s.setCoreDNSVersion(c, "1.3.1")

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

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

pod := s.getToolsPodMaesh(c)
c.Assert(pod, checker.NotNil)

s.digHost(c, pod.Name, pod.Namespace, "whoami.whoami.maesh")
}
45 changes: 45 additions & 0 deletions integration/helm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package integration

import (
"github.com/go-check/check"
checker "github.com/vdemeester/shakers"
)

// HelmSuite
type HelmSuite struct{ BaseSuite }

func (s *HelmSuite) SetUpSuite(c *check.C) {
requiredImages := []string{
"containous/maesh:latest",
"coredns/coredns:1.3.1",
"traefik:v2.1.1",
}
s.startk3s(c, requiredImages)
s.startAndWaitForCoreDNS(c)
s.startWhoami(c)
}

func (s *HelmSuite) TearDownSuite(c *check.C) {
s.stopK3s()
}

func (s *HelmSuite) TestKubernetesInstall(c *check.C) {
err := s.installHelmMaesh(c, false, false)
c.Assert(err, checker.IsNil)

defer s.unInstallHelmMaesh(c)

s.waitForMaeshControllerStarted(c)
}

func (s *HelmSuite) TestSMIInstall(c *check.C) {
s.createResources(c, "resources/smi/crds/")
defer s.deleteResources(c, "resources/smi/crds/", true)

err := s.installHelmMaesh(c, true, false)
c.Assert(err, checker.IsNil)

defer s.unInstallHelmMaesh(c)

s.waitForMaeshControllerStarted(c)
}

0 comments on commit ccc118f

Please sign in to comment.