Skip to content

Commit 2703fa7

Browse files
authored
Add e2e test (#658)
This is the initial version of our E2E test suite which is currently a subset of the acceptance test suite reimplemented in Go. To run it, pass `-run ^TestE2E$` to `go test`, without `-short`, like `go test -timeout 600s -run ^TestE2E$ github.com/actions-runner-controller/actions-runner-controller/test/e2e -v`. `make test` is modified to pass `-short` to `go test` by default to skip E2E tests. The biggest benefit of rewriting the acceptance test in Go turned out to be the fact that you can easily rerun each step- a go-test "subtest"- individually from your IDE, for faster turnaround. Both VS Code and IntelliJ IDEA/GoLand are known to work. In the near future, we will add more steps to the suite, like actually git-comminting some Actions workflow and pushing some commit to trigger a workflow run, and verify the workflow and job run results, and finally run it on our `test` workflow to fully automated E2E testing. But that s another story.
1 parent 605ec15 commit 2703fa7

File tree

4 files changed

+562
-2
lines changed

4 files changed

+562
-2
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ bin
2626

2727
.envrc
2828
.env
29+
.test.env
2930
*.pem
3031

3132
# OS
32-
.DS_STORE
33+
.DS_STORE

Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ endif
5454

5555
all: manager
5656

57+
GO_TEST_ARGS ?= -short
58+
5759
# Run tests
5860
test: generate fmt vet manifests
59-
go test ./... -coverprofile cover.out
61+
go test $(GO_TEST_ARGS) ./... -coverprofile cover.out
6062

6163
test-with-deps: kube-apiserver etcd kubectl
6264
# See https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/envtest#pkg-constants

test/e2e/e2e_test.go

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package e2e
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"time"
8+
9+
"github.com/actions-runner-controller/actions-runner-controller/testing"
10+
)
11+
12+
// If you're willing to run this test via VS Code "run test" or "debug test",
13+
// almost certainly you'd want to make the default go test timeout from 30s to longer and enough value.
14+
// Press Cmd + Shift + P, type "Workspace Settings" and open it, and type "go test timeout" and set e.g. 600s there.
15+
// See https://github.com/golang/vscode-go/blob/master/docs/settings.md#gotesttimeout for more information.
16+
//
17+
// This tests ues testing.Logf extensively for debugging purpose.
18+
// But messages logged via Logf shows up only when the test failed by default.
19+
// To always enable logging, do not forget to pass `-test.v` to `go test`.
20+
// If you're using VS Code, open `Workspace Settings` and search for `go test flags`, edit the `settings.json` and put the below:
21+
// "go.testFlags": ["-v"]
22+
func TestE2E(t *testing.T) {
23+
if testing.Short() {
24+
t.Skip("Skipped as -short is set")
25+
}
26+
27+
Img := func(repo, tag string) testing.ContainerImage {
28+
return testing.ContainerImage{
29+
Repo: repo,
30+
Tag: tag,
31+
}
32+
}
33+
34+
controllerImageRepo := "actionsrunnercontrollere2e/actions-runner-controller"
35+
controllerImageTag := "e2e"
36+
controllerImage := Img(controllerImageRepo, controllerImageTag)
37+
runnerImageRepo := "actionsrunnercontrollere2e/actions-runner"
38+
runnerImageTag := "e2e"
39+
runnerImage := Img(runnerImageRepo, runnerImageTag)
40+
41+
prebuildImages := []testing.ContainerImage{
42+
controllerImage,
43+
runnerImage,
44+
}
45+
46+
builds := []testing.DockerBuild{
47+
{
48+
Dockerfile: "../../Dockerfile",
49+
Args: []testing.BuildArg{},
50+
Image: controllerImage,
51+
},
52+
{
53+
Dockerfile: "../../runner/Dockerfile",
54+
Args: []testing.BuildArg{},
55+
Image: runnerImage,
56+
},
57+
}
58+
59+
certManagerVersion := "v1.1.1"
60+
61+
images := []testing.ContainerImage{
62+
Img("docker", "dind"),
63+
Img("quay.io/brancz/kube-rbac-proxy", "v0.10.0"),
64+
Img("quay.io/jetstack/cert-manager-controller", certManagerVersion),
65+
Img("quay.io/jetstack/cert-manager-cainjector", certManagerVersion),
66+
Img("quay.io/jetstack/cert-manager-webhook", certManagerVersion),
67+
}
68+
69+
k := testing.Start(t, testing.Cluster{}, testing.Preload(images...))
70+
71+
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second)
72+
defer cancel()
73+
74+
t.Run("build images", func(t *testing.T) {
75+
if err := k.BuildImages(ctx, builds); err != nil {
76+
t.Fatal(err)
77+
}
78+
})
79+
80+
t.Run("load images", func(t *testing.T) {
81+
if err := k.LoadImages(ctx, prebuildImages); err != nil {
82+
t.Fatal(err)
83+
}
84+
})
85+
86+
kubectlEnv := []string{
87+
"KUBECONFIG=" + k.Kubeconfig(),
88+
}
89+
90+
t.Run("install cert-manager", func(t *testing.T) {
91+
certmanagerVersion := "v1.1.1"
92+
93+
if err := k.Apply(ctx, fmt.Sprintf("https://github.com/jetstack/cert-manager/releases/download/%s/cert-manager.yaml", certmanagerVersion), testing.KubectlConfig{NoValidate: true}); err != nil {
94+
t.Fatal(err)
95+
}
96+
97+
certmanagerKubectlCfg := testing.KubectlConfig{
98+
Env: kubectlEnv,
99+
Namespace: "cert-manager",
100+
Timeout: 90 * time.Second,
101+
}
102+
103+
if err := k.WaitUntilDeployAvailable(ctx, "cert-manager-cainjector", certmanagerKubectlCfg); err != nil {
104+
t.Fatal(err)
105+
}
106+
107+
if err := k.WaitUntilDeployAvailable(ctx, "cert-manager-webhook", certmanagerKubectlCfg.WithTimeout(60*time.Second)); err != nil {
108+
t.Fatal(err)
109+
}
110+
111+
if err := k.WaitUntilDeployAvailable(ctx, "cert-manager", certmanagerKubectlCfg.WithTimeout(60*time.Second)); err != nil {
112+
t.Fatal(err)
113+
}
114+
115+
if err := k.RunKubectlEnsureNS(ctx, "actions-runner-system", testing.KubectlConfig{Env: kubectlEnv}); err != nil {
116+
t.Fatal(err)
117+
}
118+
})
119+
120+
// If you're using VS Code and wanting to run this test locally,
121+
// Browse "Workspace Settings" and search for "go test env file" and put e.g. "${workspaceFolder}/.test.env" there
122+
githubToken := os.Getenv("GITHUB_TOKEN")
123+
if githubToken == "" {
124+
t.Fatal("GITHUB_TOKEN must be set")
125+
}
126+
127+
scriptEnv := []string{
128+
"KUBECONFIG=" + k.Kubeconfig(),
129+
"NAME=" + controllerImageRepo,
130+
"VERSION=" + controllerImageTag,
131+
"RUNNER_NAME=" + runnerImageRepo,
132+
"RUNNER_TAG=" + runnerImageTag,
133+
"TEST_REPO=" + "actions-runner-controller/mumoshu-actions-test",
134+
"TEST_ORG=" + "actions-runner-controller",
135+
"TEST_ORG_REPO=" + "actions-runner-controller/mumoshu-actions-test-org-runners",
136+
"SYNC_PERIOD=" + "10s",
137+
"USE_RUNNERSET=" + "1",
138+
"ACCEPTANCE_TEST_DEPLOYMENT_TOOL=" + "helm",
139+
"ACCEPTANCE_TEST_SECRET_TYPE=token",
140+
"GITHUB_TOKEN=" + githubToken,
141+
}
142+
143+
t.Run("install actions-runner-controller", func(t *testing.T) {
144+
if err := k.RunScript(ctx, "../../acceptance/deploy.sh", testing.ScriptConfig{Dir: "../..", Env: scriptEnv}); err != nil {
145+
t.Fatal(err)
146+
}
147+
})
148+
}

0 commit comments

Comments
 (0)