test(backup, scrobble, playevents, recsettings, apierror, auth, providers): merge repeated cases (#8299)
release / web (push) Successful in 1m41s
release / go (push) Successful in 2m4s
release / govulncheck (push) Successful in 23s
release / integration (push) Successful in 3m5s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Publish the release image to GHCR (dispatch only) (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 4m35s
release / Build signed APK (push) Canceled after 3m53s
release / web (push) Successful in 1m41s
release / go (push) Successful in 2m4s
release / govulncheck (push) Successful in 23s
release / integration (push) Successful in 3m5s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Publish the release image to GHCR (dispatch only) (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 4m35s
release / Build signed APK (push) Canceled after 3m53s
- backup: schema coverage's three tests and the three AWS signing examples, one table each. - scrobble: Qualifies' six boundary tests; the ListenBrainz client's refusal mapping, twelve tests of the same rule across three calls, one table over call x status; the two similarity lookups' success and URL tests, one table. - playevents: the skip rule's three plays share one fixture. Dropped TestRecordPlayEnded_SubThreshold_NoEnqueue: the writer only calls scrobble.MaybeEnqueue, whose own test and Qualifies' table hold that case; the qualifying-play test still proves the writer calls it. - recsettings: the three tag-scale tests share one database reset. - apierror: Error() and From, one test each; auth: RequireAdmin's three. - providers: GetJSON's not-found and transient answers, one table. Its two 401 tests expected the same answer with and without TreatAuthAsTransient, which changes only the error's text; the table says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+30
-30
@@ -22,37 +22,37 @@ const (
|
||||
|
||||
var awsTime = time.Date(2013, 5, 24, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
func TestSignMatchesAWSsGetObjectExample(t *testing.T) {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://examplebucket.s3.amazonaws.com/test.txt", nil)
|
||||
req.Header.Set("Range", "bytes=0-9")
|
||||
sign(req, emptySHA256, awsAccessKey, awsSecretKey, "us-east-1", awsTime)
|
||||
want := awsCred + ", SignedHeaders=host;range;x-amz-content-sha256;x-amz-date, Signature=f0e8bdb87c964420e857bd35b5d6ed310bd44f0170aba48dd91039c6036bdb41"
|
||||
if got := req.Header.Get("Authorization"); got != want {
|
||||
t.Errorf("Authorization =\n%s\nwant\n%s", got, want)
|
||||
func TestSignMatchesAWSsExamples(t *testing.T) {
|
||||
put := "Welcome to Amazon S3."
|
||||
if got := hexSHA256([]byte(put)); got != "44ce7dd67c959e0d3524ffac1771dfbba87d2b6b4b4e99e42034a8b803f8b072" {
|
||||
t.Fatalf("payload hash = %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSignMatchesAWSsPutObjectExample(t *testing.T) {
|
||||
req, _ := http.NewRequest(http.MethodPut, "http://examplebucket.s3.amazonaws.com/test$file.text", strings.NewReader("Welcome to Amazon S3."))
|
||||
req.Header.Set("Date", "Fri, 24 May 2013 00:00:00 GMT")
|
||||
req.Header.Set("X-Amz-Storage-Class", "REDUCED_REDUNDANCY")
|
||||
payload := hexSHA256([]byte("Welcome to Amazon S3."))
|
||||
if payload != "44ce7dd67c959e0d3524ffac1771dfbba87d2b6b4b4e99e42034a8b803f8b072" {
|
||||
t.Fatalf("payload hash = %s", payload)
|
||||
}
|
||||
sign(req, payload, awsAccessKey, awsSecretKey, "us-east-1", awsTime)
|
||||
want := awsCred + ", SignedHeaders=date;host;x-amz-content-sha256;x-amz-date;x-amz-storage-class, Signature=98ad721746da40c64f1a55b78f14c238d841ea1380cd77a1b5971af0ece108bd"
|
||||
if got := req.Header.Get("Authorization"); got != want {
|
||||
t.Errorf("Authorization =\n%s\nwant\n%s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSignMatchesAWSsListObjectsExample(t *testing.T) {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://examplebucket.s3.amazonaws.com/?max-keys=2&prefix=J", nil)
|
||||
sign(req, emptySHA256, awsAccessKey, awsSecretKey, "us-east-1", awsTime)
|
||||
want := awsCred + ", SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=34b48302e7b5fa45bde8084f4b7868a86f0a534bc59db6670ed5711ef69dc6f7"
|
||||
if got := req.Header.Get("Authorization"); got != want {
|
||||
t.Errorf("Authorization =\n%s\nwant\n%s", got, want)
|
||||
for _, tc := range []struct {
|
||||
name, method, url, body string
|
||||
headers map[string]string
|
||||
want string // after the credential
|
||||
}{
|
||||
{"GET object", http.MethodGet, "http://examplebucket.s3.amazonaws.com/test.txt", "",
|
||||
map[string]string{"Range": "bytes=0-9"},
|
||||
"SignedHeaders=host;range;x-amz-content-sha256;x-amz-date, Signature=f0e8bdb87c964420e857bd35b5d6ed310bd44f0170aba48dd91039c6036bdb41"},
|
||||
{"PUT object", http.MethodPut, "http://examplebucket.s3.amazonaws.com/test$file.text", put,
|
||||
map[string]string{"Date": "Fri, 24 May 2013 00:00:00 GMT", "X-Amz-Storage-Class": "REDUCED_REDUNDANCY"},
|
||||
"SignedHeaders=date;host;x-amz-content-sha256;x-amz-date;x-amz-storage-class, Signature=98ad721746da40c64f1a55b78f14c238d841ea1380cd77a1b5971af0ece108bd"},
|
||||
{"list objects", http.MethodGet, "http://examplebucket.s3.amazonaws.com/?max-keys=2&prefix=J", "", nil,
|
||||
"SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=34b48302e7b5fa45bde8084f4b7868a86f0a534bc59db6670ed5711ef69dc6f7"},
|
||||
} {
|
||||
req, _ := http.NewRequest(tc.method, tc.url, strings.NewReader(tc.body))
|
||||
for k, v := range tc.headers {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
payload := emptySHA256
|
||||
if tc.body != "" {
|
||||
payload = hexSHA256([]byte(tc.body))
|
||||
}
|
||||
sign(req, payload, awsAccessKey, awsSecretKey, "us-east-1", awsTime)
|
||||
if got, want := req.Header.Get("Authorization"), awsCred+", "+tc.want; got != want {
|
||||
t.Errorf("%s: Authorization =\n%s\nwant\n%s", tc.name, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,24 +17,31 @@ func everyListedTable() []string {
|
||||
return names
|
||||
}
|
||||
|
||||
func TestCoverageAcceptsASchemaThatMatchesTheLists(t *testing.T) {
|
||||
if problems := Coverage(everyListedTable()); len(problems) != 0 {
|
||||
t.Fatalf("problems = %v, want none", problems)
|
||||
// Coverage holds the schema against the two lists: every table is backed up
|
||||
// or excluded with a reason, and every listed table exists. A migration that
|
||||
// adds or drops a table without updating the lists fails here.
|
||||
func TestCoverage(t *testing.T) {
|
||||
without := func(drop ...string) []string {
|
||||
return slices.DeleteFunc(everyListedTable(), func(n string) bool { return slices.Contains(drop, n) })
|
||||
}
|
||||
}
|
||||
|
||||
func TestCoverageNamesATableInNeitherList(t *testing.T) {
|
||||
problems := Coverage(append(everyListedTable(), "new_table"))
|
||||
if len(problems) != 1 || !strings.HasPrefix(problems[0], "new_table: neither") {
|
||||
t.Fatalf("problems = %v, want one naming new_table", problems)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCoverageNamesAListedTableTheSchemaLacks(t *testing.T) {
|
||||
schema := slices.DeleteFunc(everyListedTable(), func(n string) bool { return n == "playlists" || n == "scan_runs" })
|
||||
problems := Coverage(schema)
|
||||
if len(problems) != 2 {
|
||||
t.Fatalf("problems = %v, want playlists and scan_runs named", problems)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
schema []string
|
||||
want []string // a prefix of each problem, in order
|
||||
}{
|
||||
{"the schema matches the lists", everyListedTable(), nil},
|
||||
{"a table in neither list", append(everyListedTable(), "new_table"), []string{"new_table: neither"}},
|
||||
{"listed tables the schema lacks", without("playlists", "scan_runs"), []string{"playlists", "scan_runs"}},
|
||||
} {
|
||||
problems := Coverage(tc.schema)
|
||||
slices.Sort(problems)
|
||||
ok := len(problems) == len(tc.want)
|
||||
for i := 0; ok && i < len(problems); i++ {
|
||||
ok = strings.HasPrefix(problems[i], tc.want[i])
|
||||
}
|
||||
if !ok {
|
||||
t.Errorf("%s: problems = %q, want ones starting %q", tc.name, problems, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user