Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: run integration tests against oldstable #310

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ jobs:
run: |
go build -v .

- name: Run integration test (devel)
timeout-minutes: 10
env:
CODER_IMAGE: "ghcr.io/coder/coder-preview"
CODER_VERSION: "latest"
run: |
go test -v ./integration

- name: Run integration test (mainline)
timeout-minutes: 10
env:
Expand All @@ -54,6 +62,14 @@ jobs:
source <(go run ./scripts/coderversion)
CODER_VERSION="${CODER_STABLE_VERSION}" go test -v ./integration

- name: Run integration test (oldstable)
timeout-minutes: 10
env:
CODER_IMAGE: "ghcr.io/coder/coder"
run: |
source <(go run ./scripts/coderversion)
CODER_VERSION="${CODER_OLDSTABLE_VERSION}" go test -v ./integration

# run acceptance tests in a matrix with Terraform core versions
test:
name: Matrix Test
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ To run these integration tests locally:
1. Pull the version of the Coder image you wish to test:

```console
docker pull ghcr.io/coder/coder:main-x.y.z-devel-abcd1234
docker pull ghcr.io/coder/coder-preview:main-x.y.z-devel-abcd1234
```

1. Run `CODER_VERSION=main-x.y.z-devel-abcd1234 make test-integration`.
1. Run `CODER_IMAGE=ghcr.io/coder/coder-preview CODER_VERSION=main-x.y.z-devel-abcd1234 make test-integration`.

> **Note:** you can specify `CODER_IMAGE` if the Coder image you wish to test is hosted somewhere other than `ghcr.io/coder/coder`.
> For example, `CODER_IMAGE=example.com/repo/coder CODER_VERSION=foobar make test-integration`.
28 changes: 28 additions & 0 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,34 @@ func TestIntegration(t *testing.T) {
"workspace_owner.login_type": ``,
},
},
{
name: "workspace-owner-filled",
minVersion: "v2.18.0",
expectedOutput: map[string]string{
"provisioner.arch": runtime.GOARCH,
"provisioner.id": `[a-zA-Z0-9-]+`,
"provisioner.os": runtime.GOOS,
"workspace.access_port": `\d+`,
"workspace.access_url": `https?://\D+:\d+`,
"workspace.id": `[a-zA-z0-9-]+`,
"workspace.name": ``,
"workspace.start_count": `1`,
"workspace.template_id": `[a-zA-Z0-9-]+`,
"workspace.template_name": `workspace-owner`,
"workspace.template_version": `.+`,
"workspace.transition": `start`,
"workspace_owner.email": `testing@coder\.com`,
"workspace_owner.full_name": `default`,
"workspace_owner.groups": `\[(\"Everyone\")?\]`,
"workspace_owner.id": `[a-zA-Z0-9-]+`,
"workspace_owner.name": `testing`,
"workspace_owner.oidc_access_token": `^$`, // TODO: test OIDC integration
"workspace_owner.session_token": `.+`,
"workspace_owner.ssh_private_key": `(?s)^.+?BEGIN OPENSSH PRIVATE KEY.+?END OPENSSH PRIVATE KEY.+?$`,
"workspace_owner.ssh_public_key": `(?s)^ssh-ed25519.+$`,
"workspace_owner.login_type": `password`,
},
},
{
name: "coder-app-hidden",
minVersion: "v0.0.0",
Expand Down
58 changes: 58 additions & 0 deletions integration/workspace-owner-filled/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
terraform {
required_providers {
coder = {
source = "coder/coder"
}
local = {
source = "hashicorp/local"
}
}
}

// TODO: test coder_external_auth
// data coder_external_auth "me" {}
data "coder_provisioner" "me" {}
data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}

locals {
# NOTE: these must all be strings in the output
output = {
"provisioner.arch" : data.coder_provisioner.me.arch,
"provisioner.id" : data.coder_provisioner.me.id,
"provisioner.os" : data.coder_provisioner.me.os,
"workspace.access_port" : tostring(data.coder_workspace.me.access_port),
"workspace.access_url" : data.coder_workspace.me.access_url,
"workspace.id" : data.coder_workspace.me.id,
"workspace.name" : data.coder_workspace.me.name,
"workspace.start_count" : tostring(data.coder_workspace.me.start_count),
"workspace.template_id" : data.coder_workspace.me.template_id,
"workspace.template_name" : data.coder_workspace.me.template_name,
"workspace.template_version" : data.coder_workspace.me.template_version,
"workspace.transition" : data.coder_workspace.me.transition,
"workspace_owner.email" : data.coder_workspace_owner.me.email,
"workspace_owner.full_name" : data.coder_workspace_owner.me.full_name,
"workspace_owner.groups" : jsonencode(data.coder_workspace_owner.me.groups),
"workspace_owner.id" : data.coder_workspace_owner.me.id,
"workspace_owner.name" : data.coder_workspace_owner.me.name,
"workspace_owner.oidc_access_token" : data.coder_workspace_owner.me.oidc_access_token,
"workspace_owner.session_token" : data.coder_workspace_owner.me.session_token,
"workspace_owner.ssh_private_key" : data.coder_workspace_owner.me.ssh_private_key,
"workspace_owner.ssh_public_key" : data.coder_workspace_owner.me.ssh_public_key,
"workspace_owner.login_type" : data.coder_workspace_owner.me.login_type,
}
}

variable "output_path" {
type = string
}

resource "local_file" "output" {
filename = var.output_path
content = jsonencode(local.output)
}

output "output" {
value = local.output
sensitive = true
}
32 changes: 32 additions & 0 deletions scripts/coderversion/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,38 @@ func main() {

stable := fmt.Sprintf("v%d.%d.%d", stableVer.Major(), stableVer.Minor(), stableVer.Patch())
_, _ = fmt.Fprintf(os.Stdout, "CODER_STABLE_VERSION=%q\n", stable)

expectedOldStableMinor := mainlineVer.Minor() - 2
if expectedOldStableMinor < 0 {
expectedOldStableMinor = 0
}
debug("expected old stable minor: %d\n", expectedStableMinor)
oldStableVer := semver.MustParse("v0.0.0")
for _, rel := range releases {
debug("check version %s\n", rel)
if rel == "" {
debug("ignoring untagged version %s\n", rel)
continue
}

ver, err := semver.NewVersion(rel)
if err != nil {
debug("skipping invalid version %s\n", rel)
}

if ver.Minor() != expectedOldStableMinor {
debug("skipping version %s\n", rel)
continue
}

if ver.Compare(oldStableVer) > 0 {
oldStableVer = ver
continue
}
}

oldStable := fmt.Sprintf("v%d.%d.%d", oldStableVer.Major(), oldStableVer.Minor(), oldStableVer.Patch())
_, _ = fmt.Fprintf(os.Stdout, "CODER_OLDSTABLE_VERSION=%q\n", oldStable)
}

type release struct {
Expand Down
Loading