Skip to content

Commit

Permalink
test(docker, kubernetes): execute integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob LeGrone <git@jacob.work>
  • Loading branch information
jlegrone committed Dec 7, 2019
1 parent 92e1ee6 commit 5eb07d4
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ vendor/
__pycache__/
/duffle
.vscode/settings.json

# Test Output
kind-kubeconfig.yaml
coverage.*
report.xml
go_test.log
19 changes: 10 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ build:
test:
go test ./...

.PHONY: integration-test
integration-test:
go test -tags integration ./...

.PHONY: lint
lint:
golangci-lint run --config ./golangci.yml

HAS_GOLANGCI := $(shell $(CHECK) golangci-lint)
HAS_GOLANGCI := $(shell $(CHECK) golangci-lint)
GOLANGCI_VERSION := v1.21.0

HAS_KIND := $(shell $(CHECK) kind)
HAS_KUBECTL := $(shell $(CHECK) kubectl)
HAS_GOCOV_XML := $(shell command -v gocov-xml;)
HAS_GOCOV := $(shell command -v gocov;)
HAS_GO_JUNIT_REPORT := $(shell command -v go-junit-report;)
Expand All @@ -38,6 +35,12 @@ bootstrap:
ifndef HAS_GOLANGCI
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin $(GOLANGCI_VERSION)
endif
ifndef HAS_KIND
go get sigs.k8s.io/kind@v0.6.0
endif
ifndef HAS_KUBECTL
echo "Follow instructions at https://kubernetes.io/docs/tasks/tools/install-kubectl/ to install kubectl."
endif
ifndef HAS_GOCOV_XML
go get github.com/AlekSi/gocov-xml
endif
Expand All @@ -50,6 +53,4 @@ endif

.PHONY: coverage
coverage:
go test -v -coverprofile=coverage.txt -covermode count ./... 2>&1 | go-junit-report > report.xml
gocov convert coverage.txt > coverage.json
gocov-xml < coverage.json > coverage.xml
./e2e-kind.sh
6 changes: 4 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ steps:

- script: |
go version
make bootstrap build test lint coverage
go get sigs.k8s.io/kind@v0.6.0
make bootstrap build lint coverage
workingDirectory: '$(modulePath)'
displayName: 'Get dependencies, build, test'

- task: PublishTestResults@2
inputs:
testRunner: JUnit
testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml
failTaskOnFailedTests: true

- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml
summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml
5 changes: 3 additions & 2 deletions driver/kubernetes/kubernetes_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package kubernetes

import (
"bytes"
"os"
"testing"

"github.com/cnabio/cnab-go/bundle"
Expand All @@ -12,10 +13,10 @@ import (
)

func TestDriver_Run_Integration(t *testing.T) {
namespace := "default"
k := &Driver{}
k.SetConfig(map[string]string{
"KUBE_NAMESPACE": namespace,
"KUBE_NAMESPACE": "default",
"KUBECONFIG": os.Getenv("KUBECONFIG"),
})
k.ActiveDeadlineSeconds = 60

Expand Down
73 changes: 73 additions & 0 deletions e2e-kind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env bash

# Adapted from https://github.com/helm/chart-testing/blob/b8572749f073372c64323618ca13255677376e0d/e2e-kind.sh

set -o errexit
set -o nounset
set -o pipefail

CLUSTER_NAME=cnab-go-testing
readonly CLUSTER_NAME

K8S_VERSION=v1.15.3
readonly K8S_VERSION

KIND_KUBECONFIG="$PWD/kind-kubeconfig.yaml"
readonly KIND_KUBECONFIG

GO_TEST_COMMAND="go test -tags=integration -v -coverprofile=coverage.txt -covermode count ./..."
readonly GO_TEST_COMMAND

GO_TEST_LOG="go_test.log"
readonly GO_TEST_LOG

create_kind_cluster() {
kind create cluster \
--name "$CLUSTER_NAME" \
--image "kindest/node:$K8S_VERSION" \
--kubeconfig "$KIND_KUBECONFIG" \
--wait 300s

kubectl cluster-info --kubeconfig $KIND_KUBECONFIG
echo

kubectl get nodes --kubeconfig $KIND_KUBECONFIG
echo

echo 'Cluster ready!'
echo
}

test_e2e() {
echo "Running $GO_TEST_COMMAND"

KUBECONFIG="$KIND_KUBECONFIG" $GO_TEST_COMMAND >"$GO_TEST_LOG" 2>&1
echo
}

print_versions() {
echo "kind version: $(kind version)"
echo "kubectl version: $(kubectl version)"
}

cleanup() {
cat "$GO_TEST_LOG"
echo

cat "$GO_TEST_LOG" | go-junit-report > report.xml
gocov convert coverage.txt > coverage.json
gocov-xml < coverage.json > coverage.xml

kind delete cluster --name "$CLUSTER_NAME"
echo 'Done!'
}

main() {
trap cleanup EXIT

print_versions
create_kind_cluster
test_e2e
}

main

0 comments on commit 5eb07d4

Please sign in to comment.