Skip to content

Commit

Permalink
tests: add Windows E2E testing
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Di Maio <[email protected]>
  • Loading branch information
89luca89 committed Nov 22, 2023
1 parent d61d366 commit aefe64b
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 93 deletions.
103 changes: 76 additions & 27 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,56 @@ env:
GOFLAGS: -mod=vendor

jobs:
test-e2e:
runs-on: ubuntu-latest
strategy:
fail-fast: true
max-parallel: 16
matrix:
label: ["build", "ide", "integration", "machine", "machineprovider", "provider", "proxyprovider", "ssh", "up", "up-docker", "up-podman", "up-docker-compose"]
#test-e2e:
# runs-on: ubuntu-latest
# strategy:
# fail-fast: true
# max-parallel: 16
# matrix:
# label: ["build", "ide", "integration", "machine", "machineprovider", "provider", "proxyprovider", "ssh", "up", "up-docker", "up-podman", "up-docker-compose"]

# steps:
# - name: Checkout repo
# uses: actions/checkout@v2

# - name: Set up Go
# uses: actions/setup-go@v2
# with:
# go-version: 1.20.5

# - name: Set up kind k8s cluster
# uses: engineerd/[email protected]
# with:
# version: "v0.20.0"
# image: kindest/node:v1.27.3

# - name: Testing kind cluster set-up
# run: |
# set -x
# kubectl cluster-info
# kubectl get pods -n kube-system -v 10
# echo "kubectl config current-context:" $(kubectl config current-context)
# echo "KUBECONFIG env var:" ${KUBECONFIG}

# - name: Build binary and copy to the E2E directory
# working-directory: ./e2e
# run: |
# chmod +x ../hack/build-e2e.sh
# BUILDDIR=bin SRCDIR=".." ../hack/build-e2e.sh

# - name: E2E test
# working-directory: ./e2e
# run: |
# sudo KUBECONFIG=/home/runner/.kube/config go test -v -ginkgo.v -timeout 3600s --ginkgo.label-filter=${{ matrix.label }}

test-e2e-windows:
runs-on: windows-latest
# strategy:
# fail-fast: true
# max-parallel: 16
# matrix:
# # "up-podman", "integration", "machineprovider", "up"
# label: ["build", "ide", "machine", "machineprovider", "provider", "proxyprovider", "ssh", "up-docker", "up-docker-compose"]

steps:
- name: Checkout repo
Expand All @@ -38,27 +81,33 @@ jobs:
with:
go-version: 1.20.5

- name: Set up kind k8s cluster
uses: engineerd/[email protected]
with:
version: "v0.20.0"
image: kindest/node:v1.27.3

- name: Testing kind cluster set-up
- name: Download Docker
run: |
set -x
kubectl cluster-info
kubectl get pods -n kube-system -v 10
echo "kubectl config current-context:" $(kubectl config current-context)
echo "KUBECONFIG env var:" ${KUBECONFIG}
- name: Build binary and copy to the E2E directory
working-directory: ./e2e
Invoke-WebRequest -URI 'https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe' -OutFile Docker.exe
- name: Set up Docker
run: |
chmod +x ../hack/build-e2e.sh
BUILDDIR=bin SRCDIR=".." ../hack/build-e2e.sh
Start-Process 'Docker.exe' -Wait install
# choco install -y docker-desktop
- name: E2E test
working-directory: ./e2e
- name: Run docker linux
run: |
sudo KUBECONFIG=/home/runner/.kube/config go test -v -ginkgo.v -timeout 3600s --ginkgo.label-filter=${{ matrix.label }}
$PATH = [Environment]::GetEnvironmentVariable("PATH")
$docker_path = "C:\Program Files\Docker\Docker\resources\bin"
[Environment]::SetEnvironmentVariable("PATH", "$docker_path;$PATH")
[Environment]::SetEnvironmentVariable("PATH", "$docker_path;$PATH", "Machine")
C:\"Program Files"\Docker\Docker\resources\bin\docker.exe run --rm docker.io/library/alpine:latest sh -c "cat /etc/os-release"
C:\"Program Files"\Docker\Docker\resources\bin\docker run --rm docker.io/library/alpine:latest sh -c "cat /etc/os-release"
docker run --rm docker.io/library/alpine:latest sh -c "cat /etc/os-release"
# - name: Build binary and copy to the E2E directory
# run: |
# go build -ldflags "-s -w" -o devpod-windows-amd64.exe
# mkdir e2e\bin
# cp devpod-windows-amd64.exe e2e\bin\
#
# - name: E2E test
# working-directory: .\e2e
# run: |
# go run github.com/onsi/ginkgo/v2/ginkgo -r --timeout=3600s --label-filter=${{ matrix.label }}
9 changes: 5 additions & 4 deletions e2e/framework/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"io"
"os"
"os/exec"
"path/filepath"
"strings"
)

// ExecCommand executes the command string with the devpod test binary
func (f *Framework) ExecCommandOutput(ctx context.Context, args []string) (string, error) {
var execOut bytes.Buffer

cmd := exec.CommandContext(ctx, f.DevpodBinDir+"/"+f.DevpodBinName, args...)
cmd := exec.CommandContext(ctx, filepath.Join(f.DevpodBinDir, f.DevpodBinName), args...)
cmd.Stdout = io.MultiWriter(os.Stdout, &execOut)
cmd.Stderr = os.Stderr

Expand All @@ -27,7 +28,7 @@ func (f *Framework) ExecCommandOutput(ctx context.Context, args []string) (strin

// ExecCommandStdout executes the command string with the devpod test binary
func (f *Framework) ExecCommandStdout(ctx context.Context, args []string) error {
cmd := exec.CommandContext(ctx, f.DevpodBinDir+"/"+f.DevpodBinName, args...)
cmd := exec.CommandContext(ctx, filepath.Join(f.DevpodBinDir, f.DevpodBinName), args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
Expand All @@ -41,7 +42,7 @@ func (f *Framework) ExecCommandStdout(ctx context.Context, args []string) error
func (f *Framework) ExecCommand(ctx context.Context, captureStdOut, searchForString bool, searchString string, args []string) error {
var execOut bytes.Buffer

cmd := exec.CommandContext(ctx, f.DevpodBinDir+"/"+f.DevpodBinName, args...)
cmd := exec.CommandContext(ctx, filepath.Join(f.DevpodBinDir, f.DevpodBinName), args...)
cmd.Stdout = io.MultiWriter(os.Stdout, &execOut)
cmd.Stderr = os.Stderr

Expand All @@ -65,7 +66,7 @@ func (f *Framework) ExecCommandCapture(ctx context.Context, args []string) (stri
var execOut bytes.Buffer
var execErr bytes.Buffer

cmd := exec.CommandContext(ctx, f.DevpodBinDir+"/"+f.DevpodBinName, args...)
cmd := exec.CommandContext(ctx, filepath.Join(f.DevpodBinDir, f.DevpodBinName), args...)
cmd.Stdout = io.MultiWriter(os.Stdout, &execOut)
cmd.Stderr = io.MultiWriter(os.Stderr, &execErr)

Expand Down
9 changes: 8 additions & 1 deletion e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ type Framework struct {
}

func NewDefaultFramework(path string) *Framework {
var binName = "devpod-"
binName := "devpod-"
switch runtime.GOOS {
case "darwin":
binName = binName + "darwin-"
case "linux":
binName = binName + "linux-"
case "windows":
binName = binName + "windows-"
}

switch runtime.GOARCH {
Expand All @@ -24,5 +26,10 @@ func NewDefaultFramework(path string) *Framework {
case "arm64":
binName = binName + "arm64"
}

if runtime.GOOS == "windows" {
binName = binName + ".exe"
}

return &Framework{DevpodBinDir: path, DevpodBinName: binName}
}
21 changes: 20 additions & 1 deletion e2e/framework/util.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
package framework

import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"time"

"github.com/otiai10/copy"
)

func GetTiemout() time.Duration {
if runtime.GOOS == "windows" {
return 300 * time.Second
}

return 60 * time.Second
}

func CreateTempDir() (string, error) {
// Create temporary directory
dir, err := os.MkdirTemp("", "temp-*")
Expand Down Expand Up @@ -78,8 +90,15 @@ func CopyToTempDir(relativePath string) (string, error) {

func CleanupTempDir(initialDir, tempDir string) {
err := os.RemoveAll(tempDir)
ExpectNoError(err)
if err != nil {
fmt.Println("WARN:", err)
}

err = os.Chdir(initialDir)
ExpectNoError(err)
}

func CleanString(input string) string {
input = strings.ReplaceAll(input, "\\", "")
return strings.ReplaceAll(input, "/", "")
}
6 changes: 6 additions & 0 deletions e2e/tests/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"os"
"path/filepath"
"runtime"

"github.com/loft-sh/devpod/e2e/framework"
"github.com/loft-sh/devpod/pkg/devcontainer/config"
Expand Down Expand Up @@ -157,6 +158,11 @@ var _ = DevPodDescribe("devpod build test suite", func() {
})

ginkgo.It("build kubernetes dockerless", func() {
// skip windows for now
if runtime.GOOS == "windows" {
return
}

ctx := context.Background()

f := framework.NewDefaultFramework(initialDir + "/bin")
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/machineprovider/machineprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var _ = DevPodDescribe("devpod machine provider test suite", func() {
// delete workspace
err = f.DevPodWorkspaceDelete(ctx, tempDir)
framework.ExpectNoError(err)
}, ginkgo.SpecTimeout(60*time.Second))
}, ginkgo.SpecTimeout(framework.GetTiemout()))

ginkgo.It("test devpod inactivity timeout", func(ctx context.Context) {
f := framework.NewDefaultFramework(initialDir + "/bin")
Expand Down Expand Up @@ -155,6 +155,6 @@ var _ = DevPodDescribe("devpod machine provider test suite", func() {

time.Sleep(time.Second * 2)
}
}, ginkgo.SpecTimeout(300*time.Second))
}, ginkgo.SpecTimeout(framework.GetTiemout()*5))
})
})
9 changes: 4 additions & 5 deletions e2e/tests/proxyprovider/proxyprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/loft-sh/devpod/e2e/framework"
"github.com/loft-sh/devpod/pkg/client"
Expand Down Expand Up @@ -81,7 +80,7 @@ var _ = DevPodDescribe("devpod proxy provider test suite", func() {
// delete workspace
err = f.DevPodWorkspaceDelete(ctx, tempDir)
framework.ExpectNoError(err)
}, ginkgo.SpecTimeout(120*time.Second))
}, ginkgo.SpecTimeout(framework.GetTiemout()*2))

ginkgo.It("create & stop workspace via proxy provider", func(ctx context.Context) {
f := framework.NewDefaultFramework(initialDir + "/bin")
Expand Down Expand Up @@ -128,7 +127,7 @@ var _ = DevPodDescribe("devpod proxy provider test suite", func() {
// delete workspace
err = f.DevPodWorkspaceDelete(ctx, tempDir)
framework.ExpectNoError(err)
}, ginkgo.SpecTimeout(120*time.Second))
}, ginkgo.SpecTimeout(framework.GetTiemout()*2))

ginkgo.It("recreate workspace", func(ctx context.Context) {
f := framework.NewDefaultFramework(initialDir + "/bin")
Expand Down Expand Up @@ -176,7 +175,7 @@ var _ = DevPodDescribe("devpod proxy provider test suite", func() {
// delete workspace
err = f.DevPodWorkspaceDelete(ctx, tempDir)
framework.ExpectNoError(err)
}, ginkgo.SpecTimeout(120*time.Second))
}, ginkgo.SpecTimeout(framework.GetTiemout()*2))

ginkgo.It("devcontainer path workspace", func(ctx context.Context) {
f := framework.NewDefaultFramework(initialDir + "/bin")
Expand Down Expand Up @@ -210,6 +209,6 @@ var _ = DevPodDescribe("devpod proxy provider test suite", func() {
// delete workspace
err = f.DevPodWorkspaceDelete(ctx, tempDir)
framework.ExpectNoError(err)
}, ginkgo.SpecTimeout(120*time.Second))
}, ginkgo.SpecTimeout(framework.GetTiemout()*2))
})
})
6 changes: 6 additions & 0 deletions e2e/tests/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"os"
"os/exec"
"runtime"
"strconv"
"time"

Expand Down Expand Up @@ -82,6 +83,11 @@ var _ = DevPodDescribe("devpod ssh test suite", func() {
})

ginkgo.It("should start a new workspace with a docker provider (default) and forward a port into it", func() {
// skip windows for now
if runtime.GOOS == "windows" {
return
}

tempDir, err := framework.CopyToTempDir("tests/ssh/testdata/forward-test")
framework.ExpectNoError(err)
defer framework.CleanupTempDir(initialDir, tempDir)
Expand Down
Loading

0 comments on commit aefe64b

Please sign in to comment.