Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap wego acceptancesuite #56

Merged
merged 7 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ jobs:
run: mkdir -p pkg/flux/bin && touch pkg/flux/bin/flux
- name: build
run: make all BINARY_NAME=wego-${{matrix.os}}
- name: User Acceptance Tests (Ubuntu)
run: |
export WEGO_BIN_PATH=$(pwd)/bin/wego-${{matrix.os}}
go test -v -tags=acceptance ./test/acceptance/test/...
if: matrix.os == 'ubuntu-latest'
- name: Smoke Tests (macOS)
run: |
export WEGO_BIN_PATH=$(pwd)/bin/wego-${{matrix.os}}
go test -v -tags=smoke ./test/acceptance/test/...
if: matrix.os == 'macos-latest'

- name: publish
uses: aws-actions/configure-aws-credentials@v1
with:
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ jobs:
- name: Run tests
run: make unit-tests

smoke-tests:
runs-on: ubuntu-latest
steps:
- name: Install Go
if: success()
uses: actions/setup-go@v2
with:
go-version: 1.16.x
- name: Checkout code
uses: actions/checkout@v2
- name: build
run: |
make
- name: Run smoke tests from acceptance suite
run: |
export PATH=${PATH}:`go env GOPATH`/bin
export WEGO_BIN_PATH=$(pwd)/bin/wego
go test -v -tags=smoke ./test/acceptance/test/...

coverage:
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ go 1.16
require (
github.com/BurntSushi/toml v0.3.1
github.com/kr/pretty v0.2.0 // indirect
github.com/onsi/ginkgo v1.16.1 // indirect
github.com/onsi/gomega v1.11.0 // indirect
github.com/sirupsen/logrus v1.2.0
github.com/spf13/cobra v1.1.3
github.com/stretchr/testify v1.7.0
github.com/weaveworks/go-checkpoint v0.0.0-20170503165305-ebbb8b0518ab
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/sys v0.0.0-20201112073958-5cba982894dd // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)
61 changes: 61 additions & 0 deletions go.sum

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions test/acceptance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# WEGO User Acceptance Tests

This suite contains the user acceptance tests for the Weave GitOps. To run these tests you can either use gingko runner or standard go test command .

By default test harness assumes that WEGO binary is available on `$PATH` but this can be overriden by exporting the following variable


```
export WEGO_BIN_PATH=<path/to/wego-binary>
```

# Smoke Tests

To run the **smoke tests** from the suite, run the following the command from the repo root directory.

```
ginkgo -v -tags=smoke ./test/acceptance/test/...
```
Or

```
go test -v -tags=smoke ./test/acceptance/test/...
```
# Acceptance Tests
To run the full **acceptance suite**, run the command


```
ginkgo -v -tags=acceptance ./test/acceptance/test/...
```
Or
```
go test -v -tags=acceptance ./test/acceptance/test/...
```

# How to add new test

Smoke test can be added to `smoke_tests.go` or create a new go file with smoke as build tag.

For non smoke tests, feel free to create appropriately named go file.

This suite follows the **BDD** gherkin style specs, when adding a new test, make every effort to adhere to `Given-When-Then` semantics.
30 changes: 30 additions & 0 deletions test/acceptance/test/acceptance_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package acceptance

import (
"fmt"
"os"
"testing"

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

var WEGO_BIN_PATH string

func TestAcceptance(t *testing.T) {

if testing.Short() {
t.Skip("Skip User Acceptance Tests")
}

RegisterFailHandler(Fail)
RunSpecs(t, "Test Suite")
}

var _ = BeforeSuite(func() {
WEGO_BIN_PATH = os.Getenv("WEGO_BIN_PATH")
if WEGO_BIN_PATH == "" {
WEGO_BIN_PATH = "/usr/local/bin/wego"
}
fmt.Printf("WEGO Binary Path: %s\n", WEGO_BIN_PATH)
})
70 changes: 70 additions & 0 deletions test/acceptance/test/smoke_tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// +build smoke acceptance

/**
* All smoke tests go to this file, keep them light weight and fast.
* However these should still be end to end user facing scenarios.
* Smoke tests would run as part of full suite too hence the acceptance_tests flag.
*/
package acceptance

import (
"os"
"os/exec"

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

func FileExists(name string) bool {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}

var _ = Describe("WEGO Acceptance Tests ", func() {

BeforeEach(func() {

})

AfterEach(func() {

})

It("Verify that command wego version prints the version information", func() {

var session *gexec.Session
var err error

By("Given I have a wego binary installed on my local machine", func() {
Expect(FileExists(WEGO_BIN_PATH)).To(BeTrue())
})

By("When I run the command 'wego version' ", func() {
command := exec.Command(WEGO_BIN_PATH, "version")
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
})

By("Then I should see the wego version printed in format vm.n.n with newline character", func() {
Eventually(session).Should(gbytes.Say("Version v[0-3].[0-9].[0-9]\n"))
})

By("And git commit with commit id", func() {
Eventually(session).Should(gbytes.Say("GitCommit: [a-f0-9]{7}\n"))
})

By("And build timestamp", func() {
Eventually(session).Should(gbytes.Say("BuildTime: [0-9-_:]+\n"))
})

By("And branch name", func() {
Eventually(session).Should(gbytes.Say("Branch: main|HEAD\n"))
})
})
})
4 changes: 4 additions & 0 deletions test/acceptance/test/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* All common util functions and golbal constants will go here.
**/
package acceptance