|
| 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