mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-26 06:16:56 +09:00
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:
1 parent
ce7364e215
commit
8abda62312
388 files changed
+18410
-29561
No files matched your search
@@ -17,66 +17,29 @@ import (
|
||||
func TestTestHookValidation(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
t.Run("Test Validation", func(t *testing.T) {
|
||||
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/hooks")
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
cases := []struct {
|
||||
name string
|
||||
hookType string
|
||||
config map[string]string
|
||||
status int
|
||||
}{
|
||||
{"Test Validation", "gitea", map[string]string{"content_type": "json", "url": "https://example.com/webhook"}, 0}, // not written yet
|
||||
{"Test Validation with invalid URL", "gitea", map[string]string{"content_type": "json", "url": "example.com/webhook"}, http.StatusUnprocessableEntity},
|
||||
{"Test Validation with invalid webhook type", "unknown", map[string]string{"content_type": "json", "url": "example.com/webhook"}, http.StatusUnprocessableEntity},
|
||||
{"Test Validation with empty content type", "unknown", map[string]string{"url": "https://example.com/webhook"}, http.StatusUnprocessableEntity},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/hooks")
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
|
||||
checkCreateHookOption(ctx, &structs.CreateHookOption{
|
||||
Type: "gitea",
|
||||
Config: map[string]string{
|
||||
"content_type": "json",
|
||||
"url": "https://example.com/webhook",
|
||||
},
|
||||
checkCreateHookOption(ctx, &structs.CreateHookOption{
|
||||
Type: tc.hookType,
|
||||
Config: tc.config,
|
||||
})
|
||||
assert.Equal(t, tc.status, ctx.Resp.WrittenStatus())
|
||||
})
|
||||
assert.Equal(t, 0, ctx.Resp.WrittenStatus()) // not written yet
|
||||
})
|
||||
|
||||
t.Run("Test Validation with invalid URL", func(t *testing.T) {
|
||||
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/hooks")
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
|
||||
checkCreateHookOption(ctx, &structs.CreateHookOption{
|
||||
Type: "gitea",
|
||||
Config: map[string]string{
|
||||
"content_type": "json",
|
||||
"url": "example.com/webhook",
|
||||
},
|
||||
})
|
||||
assert.Equal(t, http.StatusUnprocessableEntity, ctx.Resp.WrittenStatus())
|
||||
})
|
||||
|
||||
t.Run("Test Validation with invalid webhook type", func(t *testing.T) {
|
||||
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/hooks")
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
|
||||
checkCreateHookOption(ctx, &structs.CreateHookOption{
|
||||
Type: "unknown",
|
||||
Config: map[string]string{
|
||||
"content_type": "json",
|
||||
"url": "example.com/webhook",
|
||||
},
|
||||
})
|
||||
assert.Equal(t, http.StatusUnprocessableEntity, ctx.Resp.WrittenStatus())
|
||||
})
|
||||
|
||||
t.Run("Test Validation with empty content type", func(t *testing.T) {
|
||||
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/hooks")
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
|
||||
checkCreateHookOption(ctx, &structs.CreateHookOption{
|
||||
Type: "unknown",
|
||||
Config: map[string]string{
|
||||
"url": "https://example.com/webhook",
|
||||
},
|
||||
})
|
||||
assert.Equal(t, http.StatusUnprocessableEntity, ctx.Resp.WrittenStatus())
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user