e871b05b38
CI / Test (linux/amd64) (pull_request) Successful in 34s
CI / Lint (pull_request) Failing after 16s
CI / Build (windows/amd64) (pull_request) Successful in 22s
CI / Build (linux/amd64) (pull_request) Successful in 20s
CI / Build (linux/arm64) (pull_request) Successful in 21s
Cleanup pass over the repo so CI can enforce lint going forward
without the only-new-issues escape hatch:
* gofumpt -w across the tree (31 hits, all formatting)
* misspell --fix (25 hits, US-locale spelling) — but reverted on
api.JobCancelled = "cancelled" since that literal is the wire +
DB CHECK constraint value, plus matched the case in store/fleet.go
back to "cancelled" and added //nolint:misspell on both for the
next time someone reaches for the auto-fix
* Wrap every `defer rows.Close()` / `defer stmt.Close()` /
`defer res.Body.Close()` in `defer func() { _ = .Close() }()`
to satisfy errcheck without losing the close itself
* websocket.Dial callers (1 prod, 4 tests) now capture + close the
upgrade response Body — coder/websocket can return res with a nil
Body on success, so the test deferred-closes guard against that
* Annotate the two genuine-by-design nilerr cases with //nolint
comments explaining why nil-on-error is the contract (cookie
missing = no session; ctx cancelled mid-backoff = clean shutdown)
* Add brief godoc on the 10 exported const groups + types that
revive flagged (api.HostOS/HostArch/JobKind/JobStatus/LogStream/
ErrorCode, restic.EventKind, store.Role, web.FS)
* Drop the unused (*Server).userByID method
* Inline the unparam baseView(active) — every UI page is under
the dashboard primary nav today
Result: `golangci-lint run ./...` reports 0 issues. CI lint job
no longer needs only-new-issues: true; X-06 follow-up entry in
tasks.md removed.
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package restic
|
|
|
|
import "testing"
|
|
|
|
func TestMergeRestCreds(t *testing.T) {
|
|
cases := []struct {
|
|
name, url, user, pass, want string
|
|
}{
|
|
{"rest with creds", "rest:http://h:8000/p/", "u", "p", "rest:http://u:p@h:8000/p/"},
|
|
{"rest no user — no-op", "rest:http://h:8000/p/", "", "p", "rest:http://h:8000/p/"},
|
|
{
|
|
"rest creds already inline — no-op",
|
|
"rest:http://existing:secret@h:8000/p/", "u", "p",
|
|
"rest:http://existing:secret@h:8000/p/",
|
|
},
|
|
{"non-rest s3 — no-op", "s3:s3.amazonaws.com/bucket", "u", "p", "s3:s3.amazonaws.com/bucket"},
|
|
{"unparseable — pass through", "rest:not a url", "u", "p", "rest:not a url"},
|
|
{"https URL kept intact", "rest:https://h/p/", "u", "p", "rest:https://u:p@h/p/"},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
got := mergeRestCreds(c.url, c.user, c.pass)
|
|
if got != c.want {
|
|
t.Fatalf("mergeRestCreds(%q,%q,***) = %q; want %q", c.url, c.user, got, c.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRedactURL(t *testing.T) {
|
|
cases := []struct{ in, want string }{
|
|
{"rest:http://u:p@h:8000/p/", "rest:http://u:***@h:8000/p/"},
|
|
{"rest:http://h:8000/p/", "rest:http://h:8000/p/"},
|
|
{"https://u:p@example/", "https://u:***@example/"},
|
|
{"s3:s3.amazonaws.com/bucket", "s3:s3.amazonaws.com/bucket"},
|
|
}
|
|
for _, c := range cases {
|
|
got := RedactURL(c.in)
|
|
if got != c.want {
|
|
t.Fatalf("RedactURL(%q) = %q; want %q", c.in, got, c.want)
|
|
}
|
|
}
|
|
}
|