test: consolidate Go tests (#39962)

Consolidate all Go tests. Coverage is identical to before. Go tests are
around 5% faster while being 7% smaller. No non-test code is touched.
This commit is contained in:
silverwind authored and GitHub committed 2026-10-24 13:48:19 +00:00
1 parent ce7364e215
commit 8abda62312
388 files changed
+18410 -29561

No files matched your search

+33 -48
View File
@@ -47,31 +47,23 @@ func TestGPGKeys(t *testing.T) {
for _, tc := range tt {
// Basic test on result code
t.Run(tc.name, func(t *testing.T) {
t.Run("ViewOwnGPGKeys", func(t *testing.T) {
testViewOwnGPGKeys(t, tc.makeRequest, tc.token, tc.results[0])
})
t.Run("ViewGPGKeys", func(t *testing.T) {
testViewGPGKeys(t, tc.makeRequest, tc.token, tc.results[1])
})
t.Run("GetGPGKey", func(t *testing.T) {
testGetGPGKey(t, tc.makeRequest, tc.token, tc.results[2])
})
t.Run("DeleteGPGKey", func(t *testing.T) {
testDeleteGPGKey(t, tc.makeRequest, tc.token, tc.results[3])
})
t.Run("CreateInvalidGPGKey", func(t *testing.T) {
testCreateInvalidGPGKey(t, tc.makeRequest, tc.token, tc.results[4])
})
t.Run("CreateNoneRegisteredEmailGPGKey", func(t *testing.T) {
testCreateNoneRegisteredEmailGPGKey(t, tc.makeRequest, tc.token, tc.results[5])
})
t.Run("CreateValidGPGKey", func(t *testing.T) {
testCreateValidGPGKey(t, tc.makeRequest, tc.token, tc.results[6])
})
t.Run("CreateValidSecondaryEmailGPGKeyNotActivated", func(t *testing.T) {
testCreateValidSecondaryEmailGPGKey(t, tc.makeRequest, tc.token, tc.results[7])
})
for index, operation := range []struct {
name string
run func(*testing.T, makeRequestFunc, string, int)
}{
{"ViewOwnGPGKeys", testViewOwnGPGKeys},
{"ViewGPGKeys", testViewGPGKeys},
{"GetGPGKey", testGetGPGKey},
{"DeleteGPGKey", testDeleteGPGKey},
{"CreateInvalidGPGKey", testCreateInvalidGPGKey},
{"CreateNoneRegisteredEmailGPGKey", testCreateNoneRegisteredEmailGPGKey},
{"CreateValidGPGKey", testCreateValidGPGKey},
{"CreateValidSecondaryEmailGPGKeyNotActivated", testCreateValidSecondaryEmailGPGKey},
} {
t.Run(operation.name, func(t *testing.T) {
operation.run(t, tc.makeRequest, tc.token, tc.results[index])
})
}
})
}
@@ -112,29 +104,22 @@ func TestGPGKeys(t *testing.T) {
// Check state after basic add
t.Run("CheckCommits", func(t *testing.T) {
t.Run("NotSigned", func(t *testing.T) {
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo16/branches/not-signed").
AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
branch := DecodeJSON(t, resp, &api.Branch{})
assert.False(t, branch.Commit.Verification.Verified)
})
t.Run("SignedWithNotValidatedEmail", func(t *testing.T) {
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo16/branches/good-sign-not-yet-validated").
AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
branch := DecodeJSON(t, resp, &api.Branch{})
assert.False(t, branch.Commit.Verification.Verified)
})
t.Run("SignedWithValidEmail", func(t *testing.T) {
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo16/branches/good-sign").
AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
branch := DecodeJSON(t, resp, &api.Branch{})
assert.True(t, branch.Commit.Verification.Verified)
})
for _, tc := range []struct {
name, branch string
assert assert.BoolAssertionFunc
}{
{"NotSigned", "not-signed", assert.False},
{"SignedWithNotValidatedEmail", "good-sign-not-yet-validated", assert.False},
{"SignedWithValidEmail", "good-sign", assert.True},
} {
t.Run(tc.name, func(t *testing.T) {
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo16/branches/"+tc.branch).
AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
branch := DecodeJSON(t, resp, &api.Branch{})
tc.assert(t, branch.Commit.Verification.Verified)
})
}
})
}