-
Notifications
You must be signed in to change notification settings - Fork 1
Replace shell smoke test with Go integration tests #26
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| name: canary | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "0 6 * * *" # daily at 6am UTC | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| live: | ||
| name: Live wp.org Canary | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: actions/setup-go@v6 | ||
| with: | ||
| go-version-file: go.mod | ||
| - uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: "8.2" | ||
| tools: composer:v2 | ||
| - name: Create stub CSS for embed | ||
| run: touch internal/http/static/assets/styles/app.css | ||
| - name: Live Canary Test | ||
| run: go test -tags=wporg_live -count=1 -timeout=5m -v ./internal/integration/... | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| //go:build integration || wporg_live | ||
|
|
||
| package integration | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "io" | ||
| "log/slog" | ||
| "net/http" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func testLogger(t *testing.T) *slog.Logger { | ||
| t.Helper() | ||
| return slog.Default() | ||
| } | ||
|
|
||
| func httpGet(t *testing.T, url string) string { | ||
| t.Helper() | ||
| resp, err := http.Get(url) | ||
| if err != nil { | ||
| t.Fatalf("GET %s: %v", url, err) | ||
| } | ||
| defer resp.Body.Close() | ||
| if resp.StatusCode != 200 { | ||
| t.Fatalf("GET %s: status %d", url, resp.StatusCode) | ||
| } | ||
| body, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| t.Fatalf("reading response from %s: %v", url, err) | ||
| } | ||
| return string(body) | ||
| } | ||
|
|
||
| func writeComposerJSON(t *testing.T, dir, repoURL string, require map[string]string) { | ||
| t.Helper() | ||
| data := map[string]any{ | ||
| "repositories": []map[string]any{ | ||
| { | ||
| "type": "composer", | ||
| "url": repoURL, | ||
| }, | ||
| }, | ||
| "require": require, | ||
| "config": map[string]any{ | ||
| "allow-plugins": map[string]any{ | ||
| "composer/installers": true, | ||
| }, | ||
| "secure-http": false, | ||
| }, | ||
| } | ||
| jsonData, err := json.MarshalIndent(data, "", " ") | ||
| if err != nil { | ||
| t.Fatalf("marshaling composer.json: %v", err) | ||
| } | ||
| if err := os.WriteFile(filepath.Join(dir, "composer.json"), jsonData, 0644); err != nil { | ||
| t.Fatalf("writing composer.json: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func runComposer(t *testing.T, composerPath, dir string, args ...string) string { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript ? We can test it against multiple composer versions via docker images. Examples:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using docker for multiple versions is definitely better 👍 think I'll defer as a follow-up though |
||
| t.Helper() | ||
| cmd := exec.Command(composerPath, args...) | ||
| cmd.Dir = dir | ||
| out, err := cmd.CombinedOutput() | ||
| if err != nil { | ||
| t.Fatalf("composer %s failed: %v\noutput: %s", strings.Join(args, " "), err, out) | ||
| } | ||
| return string(out) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scheduled canary now only runs
go test -tags=wporg_live, butTestWpOrgLiveserves Composer metadata from an in-processhttptest.Serverand installs fromrepoServer.URLrather thanhttps://repo.wp-composer.com. Because this commit also deletes.github/workflows/smoke-test.yml, a broken production deploy of the public repository, CDN, or/downloadsendpoint would no longer trip any scheduled check; the canary will stay green as long as the local build still works.Useful? React with 👍 / 👎.