Skip to content

Commit

Permalink
test(integration): Add scaffold for running integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>
  • Loading branch information
danielpacak committed Jul 24, 2020
1 parent a0ad1ad commit dc33fab
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 5 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,23 @@ jobs:
- name: Verify generated code
run: GOPATH="$(go env GOPATH)" ./hack/verify-codegen.sh
- name: Run unit tests
run: make test
run: make unit-tests
- name: Upload code coverage
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.txt
- name: Setup Kubernetes cluster (KIND)
uses: engineerd/setup-kind@v0.4.0
- name: Test connection to Kubernetes cluster
run: |
kubectl cluster-info
- name: Run integration tests
run: |
make integration-tests
kubectl get crd
env:
KUBECONFIG: /home/runner/.kube/config
- name: Release snapshot
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
fetch-depth: 0
- name: Run unit tests
run: make test
run: make unit-tests
- name: Release
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ build: starboard
$(BINARY): $(SOURCES)
CGO_ENABLED=0 go build -o ./bin/$(BINARY) ./cmd/starboard/main.go

test: $(SOURCES)
unit-tests: $(SOURCES)
go test -v -short -race -timeout 30s -coverprofile=coverage.txt -covermode=atomic ./...

integration-tests: build
go test -v ./integration-tests
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ go 1.14
require (
github.com/google/go-containerregistry v0.1.1
github.com/google/uuid v1.1.1
github.com/onsi/ginkgo v1.12.0
github.com/onsi/gomega v1.9.0
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.5.1
Expand Down
5 changes: 4 additions & 1 deletion hack/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
// This package imports things required by build scripts, to force `go mod` to see them as dependencies.
package tools

import _ "k8s.io/code-generator"
import (
_ "k8s.io/code-generator"
_ "github.com/onsi/ginkgo/ginkgo"
)
16 changes: 16 additions & 0 deletions integration-tests/starboard_integration_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package integration_tests

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestIntegration(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test")
}
RegisterFailHandler(Fail)
RunSpecs(t, "Starboard CLI")
}
63 changes: 63 additions & 0 deletions integration-tests/starboard_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package integration_tests

import (
"context"
extensionsapi "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"os"
"os/exec"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

const (
starboardCmd = "./../bin/starboard"
)

var _ = Describe("Starboard CLI", func() {

BeforeEach(func() {
// setup
})

Describe("Version command", func() {
It("Should print the current version of the Starboard CLI", func() {
cmd := exec.Command(starboardCmd, []string{"version"}...)
output, err := cmd.Output()
Expect(err).ShouldNot(HaveOccurred())
Expect(string(output)).To(Equal("Starboard Version: {Version:dev Commit:none Date:unknown}\n"))
})

})

Describe("Init command", func() {
It("Should initialize Starboard", func() {
cmd := exec.Command(starboardCmd, []string{"init", "-v", "3"}...)
_, err := cmd.Output()
Expect(err).ShouldNot(HaveOccurred())

// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", os.Getenv("KUBECONFIG"))
Expect(err).ShouldNot(HaveOccurred())

// create the clientset
clientset, err := kubernetes.NewForConfig(config)
Expect(err).ShouldNot(HaveOccurred())
Expect(clientset).ShouldNot(Equal(nil))

clientsetext, err := extensionsapi.NewForConfig(config)
Expect(err).ShouldNot(HaveOccurred())
crdsList, err := clientsetext.CustomResourceDefinitions().List(context.Background(), v1.ListOptions{})
Expect(err).ShouldNot(HaveOccurred())
Expect(len(crdsList.Items)).To(Equal(4))
})
})

AfterEach(func() {
// tear down
})

})
2 changes: 1 addition & 1 deletion pkg/polaris/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

const (
polarisContainerName = "polaris"
polarisContainerName = "polaris"
polarisContainerImage = "quay.io/fairwinds/polaris:1.1.0"
polarisConfigVolume = "config-volume"
polarisConfigMap = "polaris"
Expand Down

0 comments on commit dc33fab

Please sign in to comment.