Skip to content

Commit

Permalink
test: add windows e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-hm19 committed Jul 3, 2024
1 parent 884ff58 commit f4b1cfb
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 28 deletions.
35 changes: 32 additions & 3 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
branches:
- main
jobs:
e2e:
name: e2e test
e2e-linux:
name: e2e test on linux
runs-on: ubuntu-20.04
steps:
- name: checkout code
Expand All @@ -22,4 +22,33 @@ jobs:
- name: Setup K3d
uses: nolar/[email protected]
- name: run e2e
run: make e2e-test
run: make e2e-test OSTYPE=linux

e2e-windows:
name: e2e test on windows
runs-on: windows-latest
steps:
- name: checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: install Go
uses: actions/setup-go@v2
with:
go-version: 1.22
- name: install K3d
shell: powershell
run: |
# Install scoop.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
# Install K3d.
scoop install k3d
- name: setup K3s
uses: knicknic/temp-kubernetes-ci@v1
- name: run e2e
run: |
# Add kusion binary path into the user executable path.
set path=%path%;D:\a\kusion\kusion\bin
make e2e-test OSTYPE=windows
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,6 @@ sh-in-docker: ## Run a shell in the docker container of kusion

e2e-test:
# Run e2e test
hack/run-e2e.sh
hack/run-e2e.sh $(OSTYPE)

.PHONY: test cover cover-html format lint lint-fix doc build-changelog upload clean build-all build-image build-local-linux build-local-windows build-local-linux-all build-local-windows-all e2e-test
2 changes: 1 addition & 1 deletion docs/design/kusion_module/kusion_modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Kusion module is a reusable building block of KusionStack designed by platform e
3. Modules should not have dependencies or be nested within each other.
4. AppConfig is not a Module.

For more details, please visit our [official website](https://www.kusionstack.io/docs/concepts/kusion-module/overview).
For more details, please visit our [official website](https://www.kusionstack.io/docs/concepts/module/overview).

![module](../collaboration/kusion-module.png)

Expand Down
11 changes: 9 additions & 2 deletions hack/run-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
# Usage: hack/run-e2e.sh
# Example 1: hack/run-e2e.sh (run e2e test)

# Get the OS type.
OSTYPE=$1

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

# Install ginkgo
GO111MODULE=on go install github.com/onsi/ginkgo/v2/[email protected]

# Build kusion binary
# Build kusion binary according to the OS type.
go generate ./pkg/version
go build -o bin/kusion .
if [ $OSTYPE == "windows" ]; then
go build -o bin/kusion.exe .
else
go build -o bin/kusion .
fi


# Run e2e
Expand Down
35 changes: 21 additions & 14 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package e2e

import (
"fmt"
"os"
"path/filepath"
"runtime"
"testing"

"github.com/onsi/ginkgo/v2"
Expand All @@ -16,12 +18,14 @@ func TestE2e(t *testing.T) {

// BeforeSuite Create kubernetes
var _ = ginkgo.BeforeSuite(func() {
ginkgo.By("create k3s cluster", func() {
cli := "k3d cluster create kusion-e2e"
output, err := Exec(cli)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("successfully"))
})
if runtime.GOOS != "windows" {
ginkgo.By("create k3s cluster", func() {
cli := "k3d cluster create kusion-e2e"
output, err := Exec(cli)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("successfully"))
})
}

ginkgo.By("git clone konfig", func() {
output, err := ExecWithWorkDir("git clone https://github.com/KusionStack/konfig.git", GetWorkDir())
Expand All @@ -30,20 +34,23 @@ var _ = ginkgo.BeforeSuite(func() {
})

ginkgo.By("kusion init", func() {
path := filepath.Join(GetWorkDir(), "konfig")
_, err := ExecKusionWithStdin("kusion init --online=true --yes=true", path, "\n")
path := filepath.Join(GetWorkDir(), "konfig", "quickstart-e2e")
_ = os.MkdirAll(path, 0o755)
_, err := ExecKusionWithStdin("kusion init", path, "\n")
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})
})

// AfterSuite clean kubernetes
var _ = ginkgo.AfterSuite(func() {
ginkgo.By("clean up k3s cluster", func() {
cli := "k3d cluster delete kusion-e2e"
output, err := Exec(cli)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("Successfully"))
})
if runtime.GOOS != "windows" {
ginkgo.By("clean up k3s cluster", func() {
cli := "k3d cluster delete kusion-e2e"
output, err := Exec(cli)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("Successfully"))
})
}

ginkgo.By("clean up konfig", func() {
path := filepath.Join(GetWorkDir(), "konfig")
Expand Down
49 changes: 42 additions & 7 deletions test/e2e/kusionctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package e2e

import (
"context"
"fmt"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -34,23 +33,41 @@ var _ = ginkgo.Describe("kusion Runtime Commands", func() {
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})

ginkgo.It("kusion apply", func() {
ginkgo.It("apply and destroy", func() {
ginkgo.By("kusion apply", func() {
path := filepath.Join(GetWorkDir(), "konfig", "example", "service-multi-stack", "dev")
_, err := ExecKusionWithWorkDir("kusion apply -y=true", path)
_, err := ExecKusionWithWorkDir("kusion apply --watch=false -y=true", path)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})

ginkgo.By("kusion apply", func() {
path := filepath.Join(GetWorkDir(), "konfig", "example", "quickstart", "default")
_, err := ExecKusionWithWorkDir("kusion apply --watch=false -y=true", path)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})

ginkgo.By("wait service-multi-stack deploy", func() {
homedir := os.Getenv("HOME")
configPath := fmt.Sprintf("%s/.kube/config", homedir)
configPath := filepath.Join(homedir, ".kube", "config")
clusterConfig, err := clientcmd.BuildConfigFromFlags("", configPath)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
clusterClient := kubernetes.NewForConfigOrDie(clusterConfig)
gomega.Eventually(func() bool {
_, err := clusterClient.AppsV1().Deployments("service-multi-stack").Get(context.TODO(), "service-multi-stack-dev-echoserver", metav1.GetOptions{})
return err == nil
}, 300*time.Second, 5*time.Second).Should(gomega.Equal(true))
}, 900*time.Second, 5*time.Second).Should(gomega.Equal(true))
})

ginkgo.By("wait quickstart deploy", func() {
homedir := os.Getenv("HOME")
configPath := filepath.Join(homedir, ".kube", "config")
clusterConfig, err := clientcmd.BuildConfigFromFlags("", configPath)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
clusterClient := kubernetes.NewForConfigOrDie(clusterConfig)
gomega.Eventually(func() bool {
_, err := clusterClient.AppsV1().Deployments("quickstart").Get(context.TODO(), "quickstart-default-quickstart", metav1.GetOptions{})
return err == nil
}, 900*time.Second, 5*time.Second).Should(gomega.Equal(true))
})

ginkgo.By("kusion destroy", func() {
Expand All @@ -59,16 +76,34 @@ var _ = ginkgo.Describe("kusion Runtime Commands", func() {
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})

ginkgo.By("kusion destroy", func() {
path := filepath.Join(GetWorkDir(), "konfig", "example", "quickstart", "default")
_, err := ExecKusionWithWorkDir("kusion destroy -y=true", path)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})

ginkgo.By("wait service-multi-stack destroy", func() {
homedir := os.Getenv("HOME")
configPath := fmt.Sprintf("%s/.kube/config", homedir)
configPath := filepath.Join(homedir, ".kube", "config")
clusterConfig, err := clientcmd.BuildConfigFromFlags("", configPath)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
clusterClient := kubernetes.NewForConfigOrDie(clusterConfig)
gomega.Eventually(func() bool {
_, err := clusterClient.CoreV1().Namespaces().Get(context.TODO(), "service-multi-stack", metav1.GetOptions{})
return errors.IsNotFound(err)
}, 300*time.Second, 5*time.Second).Should(gomega.Equal(true))
}, 900*time.Second, 5*time.Second).Should(gomega.Equal(true))
})

ginkgo.By("wait service-multi-stack destroy", func() {
homedir := os.Getenv("HOME")
configPath := filepath.Join(homedir, ".kube", "config")
clusterConfig, err := clientcmd.BuildConfigFromFlags("", configPath)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
clusterClient := kubernetes.NewForConfigOrDie(clusterConfig)
gomega.Eventually(func() bool {
_, err := clusterClient.CoreV1().Namespaces().Get(context.TODO(), "quickstart", metav1.GetOptions{})
return errors.IsNotFound(err)
}, 900*time.Second, 5*time.Second).Should(gomega.Equal(true))
})
})
})
Expand Down

0 comments on commit f4b1cfb

Please sign in to comment.