-
Notifications
You must be signed in to change notification settings - Fork 0
test: DIGITALOCEAN_TOKEN-guarded integration test for trusted_sources app name→UUID #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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dc9f6e6
feat(test): DIGITALOCEAN_TOKEN-guarded integration test for trusted_s…
intel352 7e411af
fix(test): add 30s context timeout to live DO API calls in integratio…
intel352 9521112
ci(integration): add explicit permissions: contents: read to workflow
intel352 34f3f3b
fix(pr26): complete bool fix + workflow false-green guard
intel352 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| name: Integration Tests | ||
|
|
||
| # Manual-only: triggers paid DO API calls. Never runs on every PR. | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| app_name: | ||
| description: 'Name of a pre-existing App Platform app to use for trusted_sources resolution test' | ||
| required: true | ||
| type: string | ||
|
|
||
| # Restrict GITHUB_TOKEN to the minimum permissions needed. | ||
| # This workflow only checks out code and runs tests — it never writes back | ||
| # to the repository or publishes packages. | ||
| permissions: | ||
| contents: read | ||
|
|
||
| env: | ||
| GOPRIVATE: github.com/GoCodeAlone/* | ||
|
|
||
| jobs: | ||
| trusted-sources-app-resolution: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '1.26' | ||
| - name: Verify DIGITALOCEAN_TOKEN is configured | ||
| env: | ||
| DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }} | ||
| run: | | ||
| if [ -z "$DIGITALOCEAN_TOKEN" ]; then | ||
| echo "::error::DIGITALOCEAN_TOKEN secret is not set — configure it in repository Settings → Secrets before running this workflow" | ||
| exit 1 | ||
| fi | ||
| - name: Configure Git for private repos | ||
| run: git config --global url."https://x-access-token:${{ secrets.RELEASES_TOKEN }}@github.com/".insteadOf "https://github.com/" | ||
| - name: Run trusted_sources live integration test | ||
| env: | ||
| DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }} | ||
| DO_TEST_APP_NAME: ${{ inputs.app_name }} | ||
| run: | | ||
| GOWORK=off go test -v -tags integration ./internal/drivers/... \ | ||
| -run TestDatabaseDriver_TrustedSources_AppNameResolution_Live | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
103 changes: 103 additions & 0 deletions
103
internal/drivers/database_trusted_sources_integration_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| //go:build integration | ||
|
|
||
| package drivers | ||
|
|
||
| // Live integration test for trusted_sources app name→UUID resolution. | ||
| // | ||
| // Requirements: | ||
| // DIGITALOCEAN_TOKEN — personal access token with Apps read scope | ||
| // DO_TEST_APP_NAME — name of a pre-existing App Platform app in the account | ||
| // | ||
| // Both variables must be set or the test skips with t.Skip. | ||
| // The test is read-only: it never creates, modifies, or deletes any resource. | ||
| // | ||
| // Run manually: | ||
| // DIGITALOCEAN_TOKEN=<tok> DO_TEST_APP_NAME=<name> \ | ||
| // GOWORK=off go test -v -tags integration ./internal/drivers/... \ | ||
| // -run TestDatabaseDriver_TrustedSources_AppNameResolution_Live | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/digitalocean/godo" | ||
| "golang.org/x/oauth2" | ||
| ) | ||
|
|
||
| // TestDatabaseDriver_TrustedSources_AppNameResolution_Live calls | ||
| // resolveAppNamesMap against the live DO Apps API and verifies that: | ||
| // 1. The function resolves DO_TEST_APP_NAME to a UUID without error. | ||
| // 2. The returned UUID is UUID-shaped (passes isUUIDLike). | ||
| // 3. The UUID matches what an independent Apps.List call returns for the same | ||
| // app, confirming there is no off-by-one or pagination bug. | ||
| func TestDatabaseDriver_TrustedSources_AppNameResolution_Live(t *testing.T) { | ||
| token := os.Getenv("DIGITALOCEAN_TOKEN") | ||
| if token == "" { | ||
| t.Skip("DIGITALOCEAN_TOKEN not set — skipping live integration test") | ||
| } | ||
| appName := os.Getenv("DO_TEST_APP_NAME") | ||
| if appName == "" { | ||
| t.Skip("DO_TEST_APP_NAME not set — skipping live integration test") | ||
| } | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| defer cancel() | ||
|
|
||
| ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token}) | ||
| httpClient := oauth2.NewClient(ctx, ts) | ||
| godoClient := godo.NewClient(httpClient) | ||
|
|
||
| d := &DatabaseDriver{ | ||
| appsClient: godoClient.Apps, | ||
| region: "nyc3", | ||
| } | ||
|
|
||
| // ── 1. Resolve via the function under test ──────────────────────────────── | ||
| raw := []any{ | ||
| map[string]any{"type": "app", "value": appName}, | ||
| } | ||
| resolved, err := d.resolveAppNamesMap(ctx, raw) | ||
| if err != nil { | ||
| t.Fatalf("resolveAppNamesMap(%q): %v", appName, err) | ||
| } | ||
|
|
||
| gotUUID, ok := resolved[appName] | ||
| if !ok { | ||
| t.Fatalf("resolveAppNamesMap result missing key %q; map: %v", appName, resolved) | ||
| } | ||
| if !isUUIDLike(gotUUID) { | ||
| t.Errorf("resolved value %q for app %q does not look like a UUID", gotUUID, appName) | ||
| } | ||
|
|
||
| // ── 2. Independent cross-check via Apps.List ────────────────────────────── | ||
| wantUUID := "" | ||
| opts := &godo.ListOptions{Page: 1, PerPage: 200} | ||
| for { | ||
| apps, resp, listErr := godoClient.Apps.List(ctx, opts) | ||
| if listErr != nil { | ||
| t.Fatalf("Apps.List (cross-check): %v", listErr) | ||
| } | ||
| for _, app := range apps { | ||
| if app.Spec != nil && app.Spec.Name == appName { | ||
| wantUUID = app.ID | ||
| break | ||
| } | ||
| } | ||
| if wantUUID != "" || resp == nil || resp.Links == nil || resp.Links.IsLastPage() { | ||
| break | ||
| } | ||
| opts.Page++ | ||
| } | ||
| if wantUUID == "" { | ||
| t.Fatalf("app %q not found in Apps.List; verify DO_TEST_APP_NAME is correct", appName) | ||
| } | ||
|
|
||
| // ── 3. Assert resolved UUID == cross-checked UUID ───────────────────────── | ||
| if gotUUID != wantUUID { | ||
| t.Errorf("UUID mismatch for app %q:\n resolveAppNamesMap → %q\n Apps.List → %q", | ||
| appName, gotUUID, wantUUID) | ||
| } | ||
| t.Logf("✓ app %q resolved to UUID %q", appName, gotUUID) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 workflow can succeed without actually running the live test when
DIGITALOCEAN_TOKENis missing, because the test usest.Skipon empty token. Consider adding an explicit preflight check in the workflow step (or a separate step) that fails early ifsecrets.DIGITALOCEAN_TOKENis not set, to avoid a false-green manual run.