Skip to content

Commit

Permalink
test: e2e test on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-hm19 committed Jul 1, 2024
1 parent 884ff58 commit f5f61a1
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 27 deletions.
50 changes: 42 additions & 8 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,58 @@ name: e2e test
on:
push:
branches:
- main
- ks-main
pull_request:
branches:
- main
- ks-main
jobs:
e2e:
name: e2e test
runs-on: ubuntu-20.04
# e2e:
# name: e2e test
# runs-on: ubuntu-20.04
# 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: Setup K3d
# uses: nolar/[email protected]
# - name: run e2e
# run: make e2e-test
e2e-windows:
name: e2e test on windows
runs-on: windows-2019
steps:
- name: checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: install Go
uses: actions/setup-go@v2
with:
with:
go-version: 1.22
- name: Setup K3d
uses: nolar/[email protected]
- name: run e2e
shell: powershell
# uses: nolar/[email protected]
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 with temp-kubernetes-ci
uses: knicknic/temp-kubernetes-ci@v1

- name: Check K3s cluster
shell: powershell
run: |
kubectl config get-contexts
kubectl get nodes
- name: Run e2e
run: make e2e-test
16 changes: 12 additions & 4 deletions hack/run-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ set -o pipefail
# Install ginkgo
GO111MODULE=on go install github.com/onsi/ginkgo/v2/[email protected]

# Build kusion binary
go generate ./pkg/version
go build -o bin/kusion .

# Check OS type.
os=${OSTYPE//[0-9.]/}

if [[ $os == "windows" ]]; then
# Build kusion binary on Windows
go generate ./pkg/version
go build -o bin/kusion.exe .
else
# Build kusion binary on Linux
go generate ./pkg/version
go build -o bin/kusion .
fi

# Run e2e
set +e
Expand Down
40 changes: 26 additions & 14 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2e
import (
"fmt"
"path/filepath"
"runtime"
"testing"

"github.com/onsi/ginkgo/v2"
Expand All @@ -16,34 +17,45 @@ 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())
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("Cloning"))
})

var kusionInitCmd string
if runtime.GOOS == "windows" {
kusionInitCmd = "kusion.exe init"
} else {
kusionInitCmd = "kusion init"
}

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")
_, err := ExecKusionWithStdin(kusionInitCmd, 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
2 changes: 1 addition & 1 deletion test/e2e/kusionctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var _ = ginkgo.Describe("kusion Runtime Commands", func() {
ginkgo.It("kusion apply", 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())
})

Expand Down

0 comments on commit f5f61a1

Please sign in to comment.