aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnthony Wang2022-12-22 21:12:50 +0000
committerAnthony Wang2022-12-22 21:12:50 +0000
commite8c3886995e96c0f368ad15588579a04b1253dec (patch)
tree55b081d8ba099f6af142a585aa26cf587e3e1a2b /tests
parenta8be3ece4bc6a963d32c8a26ff4cdcddfaa7d064 (diff)
parent84001467bd893c0ccaa7e4c4d0de5d69b7461496 (diff)
Merge remote-tracking branch 'origin/main' into forgejo-federation
Diffstat (limited to 'tests')
-rw-r--r--tests/e2e/e2e_test.go3
-rw-r--r--tests/e2e/utils_e2e_test.go3
-rw-r--r--tests/gitea-repositories-meta/user30/renderer.git/HEAD1
-rw-r--r--tests/gitea-repositories-meta/user30/renderer.git/config6
-rw-r--r--tests/gitea-repositories-meta/user30/renderer.git/description1
-rw-r--r--tests/gitea-repositories-meta/user30/renderer.git/hooks/post-receive15
-rw-r--r--tests/gitea-repositories-meta/user30/renderer.git/hooks/post-receive.d/gitea2
-rw-r--r--tests/gitea-repositories-meta/user30/renderer.git/hooks/pre-receive15
-rw-r--r--tests/gitea-repositories-meta/user30/renderer.git/hooks/pre-receive.d/gitea2
-rw-r--r--tests/gitea-repositories-meta/user30/renderer.git/hooks/update14
-rw-r--r--tests/gitea-repositories-meta/user30/renderer.git/hooks/update.d/gitea2
-rw-r--r--tests/gitea-repositories-meta/user30/renderer.git/info/exclude6
-rw-r--r--tests/gitea-repositories-meta/user30/renderer.git/objects/06/0d5c2acd8bf4b6f14010acd1a73d73392ec46ebin0 -> 56 bytes
-rw-r--r--tests/gitea-repositories-meta/user30/renderer.git/objects/45/14a93050edb2c3165bdd0a3c03be063e879e68bin0 -> 50 bytes
-rw-r--r--tests/gitea-repositories-meta/user30/renderer.git/objects/c9/61cc4d1ba6b7ee1ba228a9a02b00b7746d8033bin0 -> 789 bytes
-rw-r--r--tests/gitea-repositories-meta/user30/renderer.git/packed-refs2
-rw-r--r--tests/integration/admin_user_test.go3
-rw-r--r--tests/integration/api_activitypub_person_test.go3
-rw-r--r--tests/integration/api_admin_org_test.go9
-rw-r--r--tests/integration/api_admin_test.go65
-rw-r--r--tests/integration/api_branch_test.go35
-rw-r--r--tests/integration/api_comment_attachment_test.go154
-rw-r--r--tests/integration/api_comment_test.go43
-rw-r--r--tests/integration/api_feed_user_test.go3
-rw-r--r--tests/integration/api_fork_test.go3
-rw-r--r--tests/integration/api_gpg_keys_test.go15
-rw-r--r--tests/integration/api_helper_for_declarative_test.go3
-rw-r--r--tests/integration/api_httpsig_test.go5
-rw-r--r--tests/integration/api_issue_attachment_test.go143
-rw-r--r--tests/integration/api_issue_label_test.go39
-rw-r--r--tests/integration/api_issue_milestone_test.go17
-rw-r--r--tests/integration/api_issue_reaction_test.go25
-rw-r--r--tests/integration/api_issue_stopwatch_test.go17
-rw-r--r--tests/integration/api_issue_subscription_test.go13
-rw-r--r--tests/integration/api_issue_test.go17
-rw-r--r--tests/integration/api_issue_tracked_time_test.go21
-rw-r--r--tests/integration/api_keys_test.go23
-rw-r--r--tests/integration/api_nodeinfo_test.go3
-rw-r--r--tests/integration/api_notification_test.go38
-rw-r--r--tests/integration/api_oauth2_apps_test.go11
-rw-r--r--tests/integration/api_org_test.go7
-rw-r--r--tests/integration/api_packages_composer_test.go3
-rw-r--r--tests/integration/api_packages_conan_test.go3
-rw-r--r--tests/integration/api_packages_container_test.go31
-rw-r--r--tests/integration/api_packages_generic_test.go3
-rw-r--r--tests/integration/api_packages_helm_test.go5
-rw-r--r--tests/integration/api_packages_maven_test.go33
-rw-r--r--tests/integration/api_packages_npm_test.go3
-rw-r--r--tests/integration/api_packages_nuget_test.go6
-rw-r--r--tests/integration/api_packages_pub_test.go3
-rw-r--r--tests/integration/api_packages_pypi_test.go9
-rw-r--r--tests/integration/api_packages_rubygems_test.go3
-rw-r--r--tests/integration/api_packages_test.go212
-rw-r--r--tests/integration/api_packages_vagrant_test.go5
-rw-r--r--tests/integration/api_private_serv_test.go3
-rw-r--r--tests/integration/api_pull_commits_test.go15
-rw-r--r--tests/integration/api_pull_review_test.go55
-rw-r--r--tests/integration/api_pull_test.go34
-rw-r--r--tests/integration/api_releases_test.go20
-rw-r--r--tests/integration/api_repo_archive_test.go3
-rw-r--r--tests/integration/api_repo_collaborator_test.go14
-rw-r--r--tests/integration/api_repo_edit_test.go59
-rw-r--r--tests/integration/api_repo_file_create_test.go26
-rw-r--r--tests/integration/api_repo_file_delete_test.go24
-rw-r--r--tests/integration/api_repo_file_get_test.go3
-rw-r--r--tests/integration/api_repo_file_helpers.go3
-rw-r--r--tests/integration/api_repo_file_update_test.go26
-rw-r--r--tests/integration/api_repo_get_contents_list_test.go22
-rw-r--r--tests/integration/api_repo_get_contents_test.go22
-rw-r--r--tests/integration/api_repo_git_blobs_test.go21
-rw-r--r--tests/integration/api_repo_git_commits_test.go23
-rw-r--r--tests/integration/api_repo_git_hook_test.go3
-rw-r--r--tests/integration/api_repo_git_notes_test.go9
-rw-r--r--tests/integration/api_repo_git_ref_test.go9
-rw-r--r--tests/integration/api_repo_git_tags_test.go11
-rw-r--r--tests/integration/api_repo_git_trees_test.go19
-rw-r--r--tests/integration/api_repo_hook_test.go3
-rw-r--r--tests/integration/api_repo_languages_test.go5
-rw-r--r--tests/integration/api_repo_lfs_locks_test.go3
-rw-r--r--tests/integration/api_repo_lfs_migrate_test.go3
-rw-r--r--tests/integration/api_repo_lfs_test.go6
-rw-r--r--tests/integration/api_repo_raw_test.go7
-rw-r--r--tests/integration/api_repo_tags_test.go15
-rw-r--r--tests/integration/api_repo_teams_test.go19
-rw-r--r--tests/integration/api_repo_test.go47
-rw-r--r--tests/integration/api_repo_topic_test.go3
-rw-r--r--tests/integration/api_settings_test.go3
-rw-r--r--tests/integration/api_team_test.go29
-rw-r--r--tests/integration/api_team_user_test.go7
-rw-r--r--tests/integration/api_token_test.go3
-rw-r--r--tests/integration/api_user_email_test.go17
-rw-r--r--tests/integration/api_user_follow_test.go3
-rw-r--r--tests/integration/api_user_heatmap_test.go3
-rw-r--r--tests/integration/api_user_info_test.go3
-rw-r--r--tests/integration/api_user_org_perm_test.go12
-rw-r--r--tests/integration/api_user_orgs_test.go17
-rw-r--r--tests/integration/api_user_search_test.go7
-rw-r--r--tests/integration/api_user_star_test.go3
-rw-r--r--tests/integration/api_user_watch_test.go3
-rw-r--r--tests/integration/api_wiki_test.go16
-rw-r--r--tests/integration/attachment_test.go3
-rw-r--r--tests/integration/auth_ldap_test.go3
-rw-r--r--tests/integration/benchmarks_test.go3
-rw-r--r--tests/integration/branches_test.go3
-rw-r--r--tests/integration/change_default_branch_test.go3
-rw-r--r--tests/integration/cmd_keys_test.go3
-rw-r--r--tests/integration/compare_test.go3
-rw-r--r--tests/integration/cors_test.go3
-rw-r--r--tests/integration/create_no_session_test.go3
-rw-r--r--tests/integration/csrf_test.go3
-rw-r--r--tests/integration/delete_user_test.go3
-rw-r--r--tests/integration/download_test.go19
-rw-r--r--tests/integration/dump_restore_test.go5
-rw-r--r--tests/integration/editor_test.go3
-rw-r--r--tests/integration/empty_repo_test.go3
-rw-r--r--tests/integration/eventsource_test.go6
-rw-r--r--tests/integration/explore_repos_test.go3
-rw-r--r--tests/integration/git_clone_wiki_test.go3
-rw-r--r--tests/integration/git_helper_for_declarative_test.go3
-rw-r--r--tests/integration/git_smart_http_test.go3
-rw-r--r--tests/integration/git_test.go7
-rw-r--r--tests/integration/goget_test.go3
-rw-r--r--tests/integration/gpg_git_test.go3
-rw-r--r--tests/integration/html_helper.go3
-rw-r--r--tests/integration/integration_test.go3
-rw-r--r--tests/integration/issue_test.go3
-rw-r--r--tests/integration/lfs_getobject_test.go6
-rw-r--r--tests/integration/lfs_local_endpoint_test.go3
-rw-r--r--tests/integration/links_test.go3
-rw-r--r--tests/integration/markup_external_test.go40
-rw-r--r--tests/integration/migrate_test.go3
-rw-r--r--tests/integration/migration-test/migration_test.go3
-rw-r--r--tests/integration/mirror_pull_test.go10
-rw-r--r--tests/integration/mirror_push_test.go3
-rw-r--r--tests/integration/nonascii_branches_test.go5
-rw-r--r--tests/integration/oauth_test.go3
-rw-r--r--tests/integration/org_count_test.go3
-rw-r--r--tests/integration/org_team_invite_test.go3
-rw-r--r--tests/integration/org_test.go3
-rw-r--r--tests/integration/privateactivity_test.go3
-rw-r--r--tests/integration/pull_compare_test.go3
-rw-r--r--tests/integration/pull_create_test.go3
-rw-r--r--tests/integration/pull_merge_test.go3
-rw-r--r--tests/integration/pull_review_test.go4
-rw-r--r--tests/integration/pull_status_test.go4
-rw-r--r--tests/integration/pull_update_test.go11
-rw-r--r--tests/integration/release_test.go5
-rw-r--r--tests/integration/rename_branch_test.go5
-rw-r--r--tests/integration/repo_activity_test.go3
-rw-r--r--tests/integration/repo_branch_test.go3
-rw-r--r--tests/integration/repo_commits_search_test.go3
-rw-r--r--tests/integration/repo_commits_test.go34
-rw-r--r--tests/integration/repo_fork_test.go3
-rw-r--r--tests/integration/repo_generate_test.go3
-rw-r--r--tests/integration/repo_migrate_test.go3
-rw-r--r--tests/integration/repo_search_test.go8
-rw-r--r--tests/integration/repo_tag_test.go12
-rw-r--r--tests/integration/repo_test.go3
-rw-r--r--tests/integration/repo_topic_test.go3
-rw-r--r--tests/integration/repo_watch_test.go3
-rw-r--r--tests/integration/repofiles_delete_test.go3
-rw-r--r--tests/integration/repofiles_update_test.go3
-rw-r--r--tests/integration/setting_test.go3
-rw-r--r--tests/integration/signin_test.go3
-rw-r--r--tests/integration/signout_test.go3
-rw-r--r--tests/integration/signup_test.go3
-rw-r--r--tests/integration/ssh_key_test.go3
-rw-r--r--tests/integration/timetracking_test.go3
-rw-r--r--tests/integration/user_avatar_test.go3
-rw-r--r--tests/integration/user_test.go3
-rw-r--r--tests/integration/version_test.go3
-rw-r--r--tests/integration/view_test.go3
-rw-r--r--tests/integration/webfinger_test.go3
-rw-r--r--tests/integration/xss_test.go3
-rw-r--r--tests/sqlite.ini.tmpl7
-rw-r--r--tests/test_utils.go3
-rw-r--r--tests/testlogger.go3
177 files changed, 1310 insertions, 825 deletions
diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go
index 6028ff74f..697a828e0 100644
--- a/tests/e2e/e2e_test.go
+++ b/tests/e2e/e2e_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
// This is primarily coped from /tests/integration/integration_test.go
// TODO: Move common functions to shared file
diff --git a/tests/e2e/utils_e2e_test.go b/tests/e2e/utils_e2e_test.go
index f8f3e94cd..e6e35c474 100644
--- a/tests/e2e/utils_e2e_test.go
+++ b/tests/e2e/utils_e2e_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package e2e
diff --git a/tests/gitea-repositories-meta/user30/renderer.git/HEAD b/tests/gitea-repositories-meta/user30/renderer.git/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests/gitea-repositories-meta/user30/renderer.git/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests/gitea-repositories-meta/user30/renderer.git/config b/tests/gitea-repositories-meta/user30/renderer.git/config
new file mode 100644
index 000000000..e6da23157
--- /dev/null
+++ b/tests/gitea-repositories-meta/user30/renderer.git/config
@@ -0,0 +1,6 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
+ ignorecase = true
+ precomposeunicode = true
diff --git a/tests/gitea-repositories-meta/user30/renderer.git/description b/tests/gitea-repositories-meta/user30/renderer.git/description
new file mode 100644
index 000000000..04c23973b
--- /dev/null
+++ b/tests/gitea-repositories-meta/user30/renderer.git/description
@@ -0,0 +1 @@
+The repository will be used to test third-party renderer in TestExternalMarkupRenderer
diff --git a/tests/gitea-repositories-meta/user30/renderer.git/hooks/post-receive b/tests/gitea-repositories-meta/user30/renderer.git/hooks/post-receive
new file mode 100644
index 000000000..f1f2709dd
--- /dev/null
+++ b/tests/gitea-repositories-meta/user30/renderer.git/hooks/post-receive
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+data=$(cat)
+exitcodes=""
+hookname=$(basename $0)
+GIT_DIR=${GIT_DIR:-$(dirname $0)}
+
+for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do
+test -x "${hook}" && test -f "${hook}" || continue
+echo "${data}" | "${hook}"
+exitcodes="${exitcodes} $?"
+done
+
+for i in ${exitcodes}; do
+[ ${i} -eq 0 ] || exit ${i}
+done
diff --git a/tests/gitea-repositories-meta/user30/renderer.git/hooks/post-receive.d/gitea b/tests/gitea-repositories-meta/user30/renderer.git/hooks/post-receive.d/gitea
new file mode 100644
index 000000000..43a948da3
--- /dev/null
+++ b/tests/gitea-repositories-meta/user30/renderer.git/hooks/post-receive.d/gitea
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" post-receive
diff --git a/tests/gitea-repositories-meta/user30/renderer.git/hooks/pre-receive b/tests/gitea-repositories-meta/user30/renderer.git/hooks/pre-receive
new file mode 100644
index 000000000..f1f2709dd
--- /dev/null
+++ b/tests/gitea-repositories-meta/user30/renderer.git/hooks/pre-receive
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+data=$(cat)
+exitcodes=""
+hookname=$(basename $0)
+GIT_DIR=${GIT_DIR:-$(dirname $0)}
+
+for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do
+test -x "${hook}" && test -f "${hook}" || continue
+echo "${data}" | "${hook}"
+exitcodes="${exitcodes} $?"
+done
+
+for i in ${exitcodes}; do
+[ ${i} -eq 0 ] || exit ${i}
+done
diff --git a/tests/gitea-repositories-meta/user30/renderer.git/hooks/pre-receive.d/gitea b/tests/gitea-repositories-meta/user30/renderer.git/hooks/pre-receive.d/gitea
new file mode 100644
index 000000000..49d094063
--- /dev/null
+++ b/tests/gitea-repositories-meta/user30/renderer.git/hooks/pre-receive.d/gitea
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" pre-receive
diff --git a/tests/gitea-repositories-meta/user30/renderer.git/hooks/update b/tests/gitea-repositories-meta/user30/renderer.git/hooks/update
new file mode 100644
index 000000000..df5bd27f1
--- /dev/null
+++ b/tests/gitea-repositories-meta/user30/renderer.git/hooks/update
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+exitcodes=""
+hookname=$(basename $0)
+GIT_DIR=${GIT_DIR:-$(dirname $0)}
+
+for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do
+test -x "${hook}" && test -f "${hook}" || continue
+"${hook}" $1 $2 $3
+exitcodes="${exitcodes} $?"
+done
+
+for i in ${exitcodes}; do
+[ ${i} -eq 0 ] || exit ${i}
+done
diff --git a/tests/gitea-repositories-meta/user30/renderer.git/hooks/update.d/gitea b/tests/gitea-repositories-meta/user30/renderer.git/hooks/update.d/gitea
new file mode 100644
index 000000000..38101c242
--- /dev/null
+++ b/tests/gitea-repositories-meta/user30/renderer.git/hooks/update.d/gitea
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" update $1 $2 $3
diff --git a/tests/gitea-repositories-meta/user30/renderer.git/info/exclude b/tests/gitea-repositories-meta/user30/renderer.git/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests/gitea-repositories-meta/user30/renderer.git/info/exclude
@@ -0,0 +1,6 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
diff --git a/tests/gitea-repositories-meta/user30/renderer.git/objects/06/0d5c2acd8bf4b6f14010acd1a73d73392ec46e b/tests/gitea-repositories-meta/user30/renderer.git/objects/06/0d5c2acd8bf4b6f14010acd1a73d73392ec46e
new file mode 100644
index 000000000..994f25602
--- /dev/null
+++ b/tests/gitea-repositories-meta/user30/renderer.git/objects/06/0d5c2acd8bf4b6f14010acd1a73d73392ec46e
Binary files differ
diff --git a/tests/gitea-repositories-meta/user30/renderer.git/objects/45/14a93050edb2c3165bdd0a3c03be063e879e68 b/tests/gitea-repositories-meta/user30/renderer.git/objects/45/14a93050edb2c3165bdd0a3c03be063e879e68
new file mode 100644
index 000000000..b1fff2775
--- /dev/null
+++ b/tests/gitea-repositories-meta/user30/renderer.git/objects/45/14a93050edb2c3165bdd0a3c03be063e879e68
Binary files differ
diff --git a/tests/gitea-repositories-meta/user30/renderer.git/objects/c9/61cc4d1ba6b7ee1ba228a9a02b00b7746d8033 b/tests/gitea-repositories-meta/user30/renderer.git/objects/c9/61cc4d1ba6b7ee1ba228a9a02b00b7746d8033
new file mode 100644
index 000000000..66488767a
--- /dev/null
+++ b/tests/gitea-repositories-meta/user30/renderer.git/objects/c9/61cc4d1ba6b7ee1ba228a9a02b00b7746d8033
Binary files differ
diff --git a/tests/gitea-repositories-meta/user30/renderer.git/packed-refs b/tests/gitea-repositories-meta/user30/renderer.git/packed-refs
new file mode 100644
index 000000000..63f8af0f1
--- /dev/null
+++ b/tests/gitea-repositories-meta/user30/renderer.git/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled fully-peeled sorted
+c961cc4d1ba6b7ee1ba228a9a02b00b7746d8033 refs/heads/master
diff --git a/tests/integration/admin_user_test.go b/tests/integration/admin_user_test.go
index ffe3f670f..dd6b9ccbb 100644
--- a/tests/integration/admin_user_test.go
+++ b/tests/integration/admin_user_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_activitypub_person_test.go b/tests/integration/api_activitypub_person_test.go
index 0765a4645..434143194 100644
--- a/tests/integration/api_activitypub_person_test.go
+++ b/tests/integration/api_activitypub_person_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_admin_org_test.go b/tests/integration/api_admin_org_test.go
index a8770db4c..05825eff3 100644
--- a/tests/integration/api_admin_org_test.go
+++ b/tests/integration/api_admin_org_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -32,7 +31,7 @@ func TestAPIAdminOrgCreate(t *testing.T) {
Visibility: "private",
}
req := NewRequestWithJSON(t, "POST", "/api/v1/admin/users/user2/orgs?token="+token, &org)
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var apiOrg api.Organization
DecodeJSON(t, resp, &apiOrg)
@@ -66,7 +65,7 @@ func TestAPIAdminOrgCreateBadVisibility(t *testing.T) {
Visibility: "notvalid",
}
req := NewRequestWithJSON(t, "POST", "/api/v1/admin/users/user2/orgs?token="+token, &org)
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
})
}
@@ -84,5 +83,5 @@ func TestAPIAdminOrgCreateNotAdmin(t *testing.T) {
Visibility: "public",
}
req := NewRequestWithJSON(t, "POST", "/api/v1/admin/users/user2/orgs?token="+token, &org)
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
}
diff --git a/tests/integration/api_admin_test.go b/tests/integration/api_admin_test.go
index d6bc6016f..53952210f 100644
--- a/tests/integration/api_admin_test.go
+++ b/tests/integration/api_admin_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -31,7 +30,7 @@ func TestAPIAdminCreateAndDeleteSSHKey(t *testing.T) {
"key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4cn+iXnA4KvcQYSV88vGn0Yi91vG47t1P7okprVmhNTkipNRIHWr6WdCO4VDr/cvsRkuVJAsLO2enwjGWWueOO6BodiBgyAOZ/5t5nJNMCNuLGT5UIo/RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1PDeDL0JuTjL+tr1SZi/EyxCngpYszKdXllJEHyI79KQgeD0Vt3pTrkbNVTOEcCNqZePSVmUH8X8Vhugz3bnE0/iE9Pb5fkWO9c4AnM1FgI/8Bvp27Fw2ShryIXuR6kKvUqhVMTuOSDHwu6A8jLE5Owt3GAYugDpDYuwTVNGrHLXKpPzrGGPE/jPmaLCMZcsdkec95dYeU3zKODEm8UQZFhmJmDeWVJ36nGrGZHL4J5aTTaeFUJmmXDaJYiJ+K2/ioKgXqnXvltu0A9R8/LGy4nrTJRr4JMLuJFoUXvGm1gXQ70w2LSpk6yl71RNC0hCtsBe8BP8IhYCM0EP5jh7eCMQZNvM= nocomment\n",
"title": "test-key",
})
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var newPublicKey api.PublicKey
DecodeJSON(t, resp, &newPublicKey)
@@ -44,53 +43,49 @@ func TestAPIAdminCreateAndDeleteSSHKey(t *testing.T) {
req = NewRequestf(t, "DELETE", "/api/v1/admin/users/%s/keys/%d?token=%s",
keyOwner.Name, newPublicKey.ID, token)
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
unittest.AssertNotExistsBean(t, &asymkey_model.PublicKey{ID: newPublicKey.ID})
}
func TestAPIAdminDeleteMissingSSHKey(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- // user1 is an admin user
- session := loginUser(t, "user1")
- token := getTokenForLoggedInUser(t, session)
+ // user1 is an admin user
+ token := getUserToken(t, "user1")
req := NewRequestf(t, "DELETE", "/api/v1/admin/users/user1/keys/%d?token=%s", unittest.NonexistentID, token)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
}
func TestAPIAdminDeleteUnauthorizedKey(t *testing.T) {
defer tests.PrepareTestEnv(t)()
adminUsername := "user1"
normalUsername := "user2"
- session := loginUser(t, adminUsername)
+ token := getUserToken(t, adminUsername)
- token := getTokenForLoggedInUser(t, session)
urlStr := fmt.Sprintf("/api/v1/admin/users/%s/keys?token=%s", adminUsername, token)
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
"key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4cn+iXnA4KvcQYSV88vGn0Yi91vG47t1P7okprVmhNTkipNRIHWr6WdCO4VDr/cvsRkuVJAsLO2enwjGWWueOO6BodiBgyAOZ/5t5nJNMCNuLGT5UIo/RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1PDeDL0JuTjL+tr1SZi/EyxCngpYszKdXllJEHyI79KQgeD0Vt3pTrkbNVTOEcCNqZePSVmUH8X8Vhugz3bnE0/iE9Pb5fkWO9c4AnM1FgI/8Bvp27Fw2ShryIXuR6kKvUqhVMTuOSDHwu6A8jLE5Owt3GAYugDpDYuwTVNGrHLXKpPzrGGPE/jPmaLCMZcsdkec95dYeU3zKODEm8UQZFhmJmDeWVJ36nGrGZHL4J5aTTaeFUJmmXDaJYiJ+K2/ioKgXqnXvltu0A9R8/LGy4nrTJRr4JMLuJFoUXvGm1gXQ70w2LSpk6yl71RNC0hCtsBe8BP8IhYCM0EP5jh7eCMQZNvM= nocomment\n",
"title": "test-key",
})
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var newPublicKey api.PublicKey
DecodeJSON(t, resp, &newPublicKey)
- session = loginUser(t, normalUsername)
- token = getTokenForLoggedInUser(t, session)
+ token = getUserToken(t, normalUsername)
req = NewRequestf(t, "DELETE", "/api/v1/admin/users/%s/keys/%d?token=%s",
adminUsername, newPublicKey.ID, token)
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
}
func TestAPISudoUser(t *testing.T) {
defer tests.PrepareTestEnv(t)()
adminUsername := "user1"
normalUsername := "user2"
- session := loginUser(t, adminUsername)
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, adminUsername)
urlStr := fmt.Sprintf("/api/v1/user?sudo=%s&token=%s", normalUsername, token)
req := NewRequest(t, "GET", urlStr)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var user api.User
DecodeJSON(t, resp, &user)
@@ -102,23 +97,20 @@ func TestAPISudoUserForbidden(t *testing.T) {
adminUsername := "user1"
normalUsername := "user2"
- session := loginUser(t, normalUsername)
- token := getTokenForLoggedInUser(t, session)
-
+ token := getUserToken(t, normalUsername)
urlStr := fmt.Sprintf("/api/v1/user?sudo=%s&token=%s", adminUsername, token)
req := NewRequest(t, "GET", urlStr)
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
}
func TestAPIListUsers(t *testing.T) {
defer tests.PrepareTestEnv(t)()
adminUsername := "user1"
- session := loginUser(t, adminUsername)
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, adminUsername)
urlStr := fmt.Sprintf("/api/v1/admin/users?token=%s", token)
req := NewRequest(t, "GET", urlStr)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var users []api.User
DecodeJSON(t, resp, &users)
@@ -142,17 +134,15 @@ func TestAPIListUsersNotLoggedIn(t *testing.T) {
func TestAPIListUsersNonAdmin(t *testing.T) {
defer tests.PrepareTestEnv(t)()
nonAdminUsername := "user2"
- session := loginUser(t, nonAdminUsername)
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, nonAdminUsername)
req := NewRequestf(t, "GET", "/api/v1/admin/users?token=%s", token)
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
}
func TestAPICreateUserInvalidEmail(t *testing.T) {
defer tests.PrepareTestEnv(t)()
adminUsername := "user1"
- session := loginUser(t, adminUsername)
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, adminUsername)
urlStr := fmt.Sprintf("/api/v1/admin/users?token=%s", token)
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
"email": "invalid_email@domain.com\r\n",
@@ -164,14 +154,13 @@ func TestAPICreateUserInvalidEmail(t *testing.T) {
"source_id": "0",
"username": "invalidUser",
})
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
}
func TestAPICreateAndDeleteUser(t *testing.T) {
defer tests.PrepareTestEnv(t)()
adminUsername := "user1"
- session := loginUser(t, adminUsername)
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, adminUsername)
req := NewRequestWithValues(
t,
@@ -197,8 +186,7 @@ func TestAPICreateAndDeleteUser(t *testing.T) {
func TestAPIEditUser(t *testing.T) {
defer tests.PrepareTestEnv(t)()
adminUsername := "user1"
- session := loginUser(t, adminUsername)
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, adminUsername)
urlStr := fmt.Sprintf("/api/v1/admin/users/%s?token=%s", "user2", token)
req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{
@@ -208,7 +196,7 @@ func TestAPIEditUser(t *testing.T) {
// to change
"full_name": "Full Name User 2",
})
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
empty := ""
req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{
@@ -216,7 +204,7 @@ func TestAPIEditUser(t *testing.T) {
SourceID: 0,
Email: &empty,
})
- resp := session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ resp := MakeRequest(t, req, http.StatusUnprocessableEntity)
errMap := make(map[string]interface{})
json.Unmarshal(resp.Body.Bytes(), &errMap)
@@ -232,7 +220,7 @@ func TestAPIEditUser(t *testing.T) {
// to change
Restricted: &bTrue,
})
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
user2 = unittest.AssertExistsAndLoadBean(t, &user_model.User{LoginName: "user2"})
assert.True(t, user2.IsRestricted)
}
@@ -240,8 +228,7 @@ func TestAPIEditUser(t *testing.T) {
func TestAPICreateRepoForUser(t *testing.T) {
defer tests.PrepareTestEnv(t)()
adminUsername := "user1"
- session := loginUser(t, adminUsername)
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, adminUsername)
req := NewRequestWithJSON(
t,
diff --git a/tests/integration/api_branch_test.go b/tests/integration/api_branch_test.go
index bdfdd3c75..c176a144c 100644
--- a/tests/integration/api_branch_test.go
+++ b/tests/integration/api_branch_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -16,10 +15,9 @@ import (
)
func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
- session := loginUser(t, "user2")
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, "user2")
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branches/%s?token=%s", branchName, token)
- resp := session.MakeRequest(t, req, NoExpectedStatus)
+ resp := MakeRequest(t, req, NoExpectedStatus)
if !exists {
assert.EqualValues(t, http.StatusNotFound, resp.Code)
return
@@ -33,10 +31,9 @@ func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
}
func testAPIGetBranchProtection(t *testing.T, branchName string, expectedHTTPStatus int) {
- session := loginUser(t, "user2")
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, "user2")
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branch_protections/%s?token=%s", branchName, token)
- resp := session.MakeRequest(t, req, expectedHTTPStatus)
+ resp := MakeRequest(t, req, expectedHTTPStatus)
if resp.Code == http.StatusOK {
var branchProtection api.BranchProtection
@@ -46,12 +43,11 @@ func testAPIGetBranchProtection(t *testing.T, branchName string, expectedHTTPSta
}
func testAPICreateBranchProtection(t *testing.T, branchName string, expectedHTTPStatus int) {
- session := loginUser(t, "user2")
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, "user2")
req := NewRequestWithJSON(t, "POST", "/api/v1/repos/user2/repo1/branch_protections?token="+token, &api.BranchProtection{
BranchName: branchName,
})
- resp := session.MakeRequest(t, req, expectedHTTPStatus)
+ resp := MakeRequest(t, req, expectedHTTPStatus)
if resp.Code == http.StatusCreated {
var branchProtection api.BranchProtection
@@ -61,10 +57,9 @@ func testAPICreateBranchProtection(t *testing.T, branchName string, expectedHTTP
}
func testAPIEditBranchProtection(t *testing.T, branchName string, body *api.BranchProtection, expectedHTTPStatus int) {
- session := loginUser(t, "user2")
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, "user2")
req := NewRequestWithJSON(t, "PATCH", "/api/v1/repos/user2/repo1/branch_protections/"+branchName+"?token="+token, body)
- resp := session.MakeRequest(t, req, expectedHTTPStatus)
+ resp := MakeRequest(t, req, expectedHTTPStatus)
if resp.Code == http.StatusOK {
var branchProtection api.BranchProtection
@@ -74,17 +69,15 @@ func testAPIEditBranchProtection(t *testing.T, branchName string, body *api.Bran
}
func testAPIDeleteBranchProtection(t *testing.T, branchName string, expectedHTTPStatus int) {
- session := loginUser(t, "user2")
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, "user2")
req := NewRequestf(t, "DELETE", "/api/v1/repos/user2/repo1/branch_protections/%s?token=%s", branchName, token)
- session.MakeRequest(t, req, expectedHTTPStatus)
+ MakeRequest(t, req, expectedHTTPStatus)
}
func testAPIDeleteBranch(t *testing.T, branchName string, expectedHTTPStatus int) {
- session := loginUser(t, "user2")
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, "user2")
req := NewRequestf(t, "DELETE", "/api/v1/repos/user2/repo1/branches/%s?token=%s", branchName, token)
- session.MakeRequest(t, req, expectedHTTPStatus)
+ MakeRequest(t, req, expectedHTTPStatus)
}
func TestAPIGetBranch(t *testing.T) {
@@ -161,7 +154,7 @@ func testAPICreateBranch(t testing.TB, session *TestSession, user, repo, oldBran
BranchName: newBranch,
OldBranchName: oldBranch,
})
- resp := session.MakeRequest(t, req, status)
+ resp := MakeRequest(t, req, status)
var branch api.Branch
DecodeJSON(t, resp, &branch)
diff --git a/tests/integration/api_comment_attachment_test.go b/tests/integration/api_comment_attachment_test.go
new file mode 100644
index 000000000..22bf502ef
--- /dev/null
+++ b/tests/integration/api_comment_attachment_test.go
@@ -0,0 +1,154 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package integration
+
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "mime/multipart"
+ "net/http"
+ "testing"
+
+ "code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
+ repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
+ "code.gitea.io/gitea/modules/convert"
+ api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/tests"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestAPIGetCommentAttachment(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 2})
+ assert.NoError(t, comment.LoadIssue(db.DefaultContext))
+ assert.NoError(t, comment.LoadAttachments(db.DefaultContext))
+ attachment := unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: comment.Attachments[0].ID})
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: comment.Issue.RepoID})
+ repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
+
+ session := loginUser(t, repoOwner.Name)
+ token := getTokenForLoggedInUser(t, session)
+ req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d/assets/%d", repoOwner.Name, repo.Name, comment.ID, attachment.ID)
+ session.MakeRequest(t, req, http.StatusOK)
+ req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d/assets/%d?token=%s", repoOwner.Name, repo.Name, comment.ID, attachment.ID, token)
+ resp := session.MakeRequest(t, req, http.StatusOK)
+
+ var apiAttachment api.Attachment
+ DecodeJSON(t, resp, &apiAttachment)
+
+ expect := convert.ToAttachment(attachment)
+ assert.Equal(t, expect.ID, apiAttachment.ID)
+ assert.Equal(t, expect.Name, apiAttachment.Name)
+ assert.Equal(t, expect.UUID, apiAttachment.UUID)
+ assert.Equal(t, expect.Created.Unix(), apiAttachment.Created.Unix())
+}
+
+func TestAPIListCommentAttachments(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 2})
+ issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: comment.IssueID})
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
+ repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
+
+ session := loginUser(t, repoOwner.Name)
+ req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d/assets",
+ repoOwner.Name, repo.Name, comment.ID)
+ resp := session.MakeRequest(t, req, http.StatusOK)
+
+ var apiAttachments []*api.Attachment
+ DecodeJSON(t, resp, &apiAttachments)
+ expectedCount := unittest.GetCount(t, &repo_model.Attachment{CommentID: comment.ID})
+ assert.EqualValues(t, expectedCount, len(apiAttachments))
+
+ unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: apiAttachments[0].ID, CommentID: comment.ID})
+}
+
+func TestAPICreateCommentAttachment(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 2})
+ issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: comment.IssueID})
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
+ repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
+
+ session := loginUser(t, repoOwner.Name)
+ token := getTokenForLoggedInUser(t, session)
+ urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d/assets?token=%s",
+ repoOwner.Name, repo.Name, comment.ID, token)
+
+ filename := "image.png"
+ buff := generateImg()
+ body := &bytes.Buffer{}
+
+ // Setup multi-part
+ writer := multipart.NewWriter(body)
+ part, err := writer.CreateFormFile("attachment", filename)
+ assert.NoError(t, err)
+ _, err = io.Copy(part, &buff)
+ assert.NoError(t, err)
+ err = writer.Close()
+ assert.NoError(t, err)
+
+ req := NewRequestWithBody(t, "POST", urlStr, body)
+ req.Header.Add("Content-Type", writer.FormDataContentType())
+ resp := session.MakeRequest(t, req, http.StatusCreated)
+
+ apiAttachment := new(api.Attachment)
+ DecodeJSON(t, resp, &apiAttachment)
+
+ unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: apiAttachment.ID, CommentID: comment.ID})
+}
+
+func TestAPIEditCommentAttachment(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ const newAttachmentName = "newAttachmentName"
+
+ attachment := unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: 6})
+ comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: attachment.CommentID})
+ issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: comment.IssueID})
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
+ repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
+
+ session := loginUser(t, repoOwner.Name)
+ token := getTokenForLoggedInUser(t, session)
+ urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d/assets/%d?token=%s",
+ repoOwner.Name, repo.Name, comment.ID, attachment.ID, token)
+ req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{
+ "name": newAttachmentName,
+ })
+ resp := session.MakeRequest(t, req, http.StatusCreated)
+ apiAttachment := new(api.Attachment)
+ DecodeJSON(t, resp, &apiAttachment)
+
+ unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: apiAttachment.ID, CommentID: comment.ID, Name: apiAttachment.Name})
+}
+
+func TestAPIDeleteCommentAttachment(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ attachment := unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: 6})
+ comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: attachment.CommentID})
+ issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: comment.IssueID})
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
+ repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
+
+ session := loginUser(t, repoOwner.Name)
+ token := getTokenForLoggedInUser(t, session)
+ urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d/assets/%d?token=%s",
+ repoOwner.Name, repo.Name, comment.ID, attachment.ID, token)
+
+ req := NewRequestf(t, "DELETE", urlStr)
+ session.MakeRequest(t, req, http.StatusNoContent)
+
+ unittest.AssertNotExistsBean(t, &repo_model.Attachment{ID: attachment.ID, CommentID: comment.ID})
+}
diff --git a/tests/integration/api_comment_test.go b/tests/integration/api_comment_test.go
index 126d88684..edd4da88c 100644
--- a/tests/integration/api_comment_test.go
+++ b/tests/integration/api_comment_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -10,6 +9,7 @@ import (
"net/url"
"testing"
+ "code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
@@ -30,10 +30,9 @@ func TestAPIListRepoComments(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
- session := loginUser(t, repoOwner.Name)
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments", repoOwner.Name, repo.Name))
req := NewRequest(t, "GET", link.String())
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiComments []*api.Comment
DecodeJSON(t, resp, &apiComments)
@@ -52,7 +51,7 @@ func TestAPIListRepoComments(t *testing.T) {
query.Add("before", before)
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiComments)
assert.Len(t, apiComments, 1)
assert.EqualValues(t, 2, apiComments[0].ID)
@@ -61,7 +60,7 @@ func TestAPIListRepoComments(t *testing.T) {
query.Add("since", since)
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiComments)
assert.Len(t, apiComments, 1)
assert.EqualValues(t, 3, apiComments[0].ID)
@@ -76,10 +75,9 @@ func TestAPIListIssueComments(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
- session := loginUser(t, repoOwner.Name)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/comments",
repoOwner.Name, repo.Name, issue.Index)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var comments []*api.Comment
DecodeJSON(t, resp, &comments)
@@ -96,14 +94,13 @@ func TestAPICreateComment(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
- session := loginUser(t, repoOwner.Name)
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, repoOwner.Name)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments?token=%s",
repoOwner.Name, repo.Name, issue.Index, token)
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
"body": commentBody,
})
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var updatedComment api.Comment
DecodeJSON(t, resp, &updatedComment)
@@ -115,21 +112,20 @@ func TestAPIGetComment(t *testing.T) {
defer tests.PrepareTestEnv(t)()
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 2})
- assert.NoError(t, comment.LoadIssue())
+ assert.NoError(t, comment.LoadIssue(db.DefaultContext))
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: comment.Issue.RepoID})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
- session := loginUser(t, repoOwner.Name)
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, repoOwner.Name)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d?token=%s", repoOwner.Name, repo.Name, comment.ID, token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiComment api.Comment
DecodeJSON(t, resp, &apiComment)
- assert.NoError(t, comment.LoadPoster())
+ assert.NoError(t, comment.LoadPoster(db.DefaultContext))
expect := convert.ToComment(comment)
assert.Equal(t, expect.ID, apiComment.ID)
@@ -148,14 +144,13 @@ func TestAPIEditComment(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
- session := loginUser(t, repoOwner.Name)
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, repoOwner.Name)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d?token=%s",
repoOwner.Name, repo.Name, comment.ID, token)
req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{
"body": newCommentBody,
})
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var updatedComment api.Comment
DecodeJSON(t, resp, &updatedComment)
@@ -173,11 +168,10 @@ func TestAPIDeleteComment(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
- session := loginUser(t, repoOwner.Name)
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, repoOwner.Name)
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/comments/%d?token=%s",
repoOwner.Name, repo.Name, comment.ID, token)
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
unittest.AssertNotExistsBean(t, &issues_model.Comment{ID: comment.ID})
}
@@ -191,10 +185,9 @@ func TestAPIListIssueTimeline(t *testing.T) {
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
// make request
- session := loginUser(t, repoOwner.Name)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/timeline",
repoOwner.Name, repo.Name, issue.Index)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
// check if lens of list returned by API and
// lists extracted directly from DB are the same
diff --git a/tests/integration/api_feed_user_test.go b/tests/integration/api_feed_user_test.go
index c137dd120..c44f9a195 100644
--- a/tests/integration/api_feed_user_test.go
+++ b/tests/integration/api_feed_user_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_fork_test.go b/tests/integration/api_fork_test.go
index 131dcf70b..7c231415a 100644
--- a/tests/integration/api_fork_test.go
+++ b/tests/integration/api_fork_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gogs Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_gpg_keys_test.go b/tests/integration/api_gpg_keys_test.go
index 0ad876c9b..162a5a4fd 100644
--- a/tests/integration/api_gpg_keys_test.go
+++ b/tests/integration/api_gpg_keys_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gogs Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -75,7 +74,7 @@ func TestGPGKeys(t *testing.T) {
var keys []*api.GPGKey
req := NewRequest(t, "GET", "/api/v1/user/gpg_keys?token="+token) // GET all keys
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &keys)
assert.Len(t, keys, 1)
@@ -91,7 +90,7 @@ func TestGPGKeys(t *testing.T) {
var key api.GPGKey
req = NewRequest(t, "GET", "/api/v1/user/gpg_keys/"+strconv.FormatInt(primaryKey1.ID, 10)+"?token="+token) // Primary key 1
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &key)
assert.EqualValues(t, "38EA3BCED732982C", key.KeyID)
assert.Len(t, key.Emails, 1)
@@ -99,7 +98,7 @@ func TestGPGKeys(t *testing.T) {
assert.True(t, key.Emails[0].Verified)
req = NewRequest(t, "GET", "/api/v1/user/gpg_keys/"+strconv.FormatInt(subKey.ID, 10)+"?token="+token) // Subkey of 38EA3BCED732982C
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &key)
assert.EqualValues(t, "70D7C694D17D03AD", key.KeyID)
assert.Empty(t, key.Emails)
@@ -110,7 +109,7 @@ func TestGPGKeys(t *testing.T) {
t.Run("NotSigned", func(t *testing.T) {
var branch api.Branch
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo16/branches/not-signed?token="+token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &branch)
assert.False(t, branch.Commit.Verification.Verified)
})
@@ -118,7 +117,7 @@ func TestGPGKeys(t *testing.T) {
t.Run("SignedWithNotValidatedEmail", func(t *testing.T) {
var branch api.Branch
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo16/branches/good-sign-not-yet-validated?token="+token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &branch)
assert.False(t, branch.Commit.Verification.Verified)
})
@@ -126,7 +125,7 @@ func TestGPGKeys(t *testing.T) {
t.Run("SignedWithValidEmail", func(t *testing.T) {
var branch api.Branch
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo16/branches/good-sign?token="+token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &branch)
assert.True(t, branch.Commit.Verification.Verified)
})
diff --git a/tests/integration/api_helper_for_declarative_test.go b/tests/integration/api_helper_for_declarative_test.go
index 5a798f79f..dbfe502ec 100644
--- a/tests/integration/api_helper_for_declarative_test.go
+++ b/tests/integration/api_helper_for_declarative_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_httpsig_test.go b/tests/integration/api_httpsig_test.go
index 80b3c586b..881bb45ca 100644
--- a/tests/integration/api_httpsig_test.go
+++ b/tests/integration/api_httpsig_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -62,7 +61,7 @@ func TestHTTPSigPubKey(t *testing.T) {
Key: keyType + " " + keyContent,
}
req := NewRequestWithJSON(t, "POST", keysURL, rawKeyBody)
- session.MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusCreated)
// parse our private key and create the httpsig request
sshSigner, _ := ssh.ParsePrivateKey([]byte(httpsigPrivateKey))
diff --git a/tests/integration/api_issue_attachment_test.go b/tests/integration/api_issue_attachment_test.go
new file mode 100644
index 000000000..0558dda56
--- /dev/null
+++ b/tests/integration/api_issue_attachment_test.go
@@ -0,0 +1,143 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package integration
+
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "mime/multipart"
+ "net/http"
+ "testing"
+
+ issues_model "code.gitea.io/gitea/models/issues"
+ repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
+ api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/tests"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestAPIGetIssueAttachment(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ attachment := unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: 1})
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: attachment.RepoID})
+ issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: attachment.IssueID})
+ repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
+
+ session := loginUser(t, repoOwner.Name)
+ token := getTokenForLoggedInUser(t, session)
+ urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets/%d?token=%s",
+ repoOwner.Name, repo.Name, issue.Index, attachment.ID, token)
+
+ req := NewRequest(t, "GET", urlStr)
+ resp := session.MakeRequest(t, req, http.StatusOK)
+ apiAttachment := new(api.Attachment)
+ DecodeJSON(t, resp, &apiAttachment)
+
+ unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: apiAttachment.ID, IssueID: issue.ID})
+}
+
+func TestAPIListIssueAttachments(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ attachment := unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: 1})
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: attachment.RepoID})
+ issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: attachment.IssueID})
+ repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
+
+ session := loginUser(t, repoOwner.Name)
+ token := getTokenForLoggedInUser(t, session)
+ urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets?token=%s",
+ repoOwner.Name, repo.Name, issue.Index, token)
+
+ req := NewRequest(t, "GET", urlStr)
+ resp := session.MakeRequest(t, req, http.StatusOK)
+ apiAttachment := new([]api.Attachment)
+ DecodeJSON(t, resp, &apiAttachment)
+
+ unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: (*apiAttachment)[0].ID, IssueID: issue.ID})
+}
+
+func TestAPICreateIssueAttachment(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
+ issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: repo.ID})
+ repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
+
+ session := loginUser(t, repoOwner.Name)
+ token := getTokenForLoggedInUser(t, session)
+ urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets?token=%s",
+ repoOwner.Name, repo.Name, issue.Index, token)
+
+ filename := "image.png"
+ buff := generateImg()
+ body := &bytes.Buffer{}
+
+ // Setup multi-part
+ writer := multipart.NewWriter(body)
+ part, err := writer.CreateFormFile("attachment", filename)
+ assert.NoError(t, err)
+ _, err = io.Copy(part, &buff)
+ assert.NoError(t, err)
+ err = writer.Close()
+ assert.NoError(t, err)
+
+ req := NewRequestWithBody(t, "POST", urlStr, body)
+ req.Header.Add("Content-Type", writer.FormDataContentType())
+ resp := session.MakeRequest(t, req, http.StatusCreated)
+
+ apiAttachment := new(api.Attachment)
+ DecodeJSON(t, resp, &apiAttachment)
+
+ unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: apiAttachment.ID, IssueID: issue.ID})
+}
+
+func TestAPIEditIssueAttachment(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ const newAttachmentName = "newAttachmentName"
+
+ attachment := unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: 1})
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: attachment.RepoID})
+ issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: attachment.IssueID})
+ repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
+
+ session := loginUser(t, repoOwner.Name)
+ token := getTokenForLoggedInUser(t, session)
+ urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets/%d?token=%s",
+ repoOwner.Name, repo.Name, issue.Index, attachment.ID, token)
+ req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{
+ "name": newAttachmentName,
+ })
+ resp := session.MakeRequest(t, req, http.StatusCreated)
+ apiAttachment := new(api.Attachment)
+ DecodeJSON(t, resp, &apiAttachment)
+
+ unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: apiAttachment.ID, IssueID: issue.ID, Name: apiAttachment.Name})
+}
+
+func TestAPIDeleteIssueAttachment(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ attachment := unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: 1})
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: attachment.RepoID})
+ issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: attachment.IssueID})
+ repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
+
+ session := loginUser(t, repoOwner.Name)
+ token := getTokenForLoggedInUser(t, session)
+ urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets/%d?token=%s",
+ repoOwner.Name, repo.Name, issue.Index, attachment.ID, token)
+
+ req := NewRequest(t, "DELETE", urlStr)
+ session.MakeRequest(t, req, http.StatusNoContent)
+
+ unittest.AssertNotExistsBean(t, &repo_model.Attachment{ID: attachment.ID, IssueID: issue.ID})
+}
diff --git a/tests/integration/api_issue_label_test.go b/tests/integration/api_issue_label_test.go
index 586c50a55..6f0fd8791 100644
--- a/tests/integration/api_issue_label_test.go
+++ b/tests/integration/api_issue_label_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -34,7 +33,7 @@ func TestAPIModifyLabels(t *testing.T) {
Color: "abcdef",
Description: "test label",
})
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
apiLabel := new(api.Label)
DecodeJSON(t, resp, &apiLabel)
dbLabel := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: apiLabel.ID, RepoID: repo.ID})
@@ -46,16 +45,16 @@ func TestAPIModifyLabels(t *testing.T) {
Color: "#123456",
Description: "jet another test label",
})
- session.MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusCreated)
req = NewRequestWithJSON(t, "POST", urlStr, &api.CreateLabelOption{
Name: "WrongTestL",
Color: "#12345g",
})
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
// ListLabels
req = NewRequest(t, "GET", urlStr)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
var apiLabels []*api.Label
DecodeJSON(t, resp, &apiLabels)
assert.Len(t, apiLabels, 2)
@@ -63,7 +62,7 @@ func TestAPIModifyLabels(t *testing.T) {
// GetLabel
singleURLStr := fmt.Sprintf("/api/v1/repos/%s/%s/labels/%d?token=%s", owner.Name, repo.Name, dbLabel.ID, token)
req = NewRequest(t, "GET", singleURLStr)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiLabel)
assert.EqualValues(t, strings.TrimLeft(dbLabel.Color, "#"), apiLabel.Color)
@@ -75,17 +74,17 @@ func TestAPIModifyLabels(t *testing.T) {
Name: &newName,
Color: &newColor,
})
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiLabel)
assert.EqualValues(t, newColor, apiLabel.Color)
req = NewRequestWithJSON(t, "PATCH", singleURLStr, &api.EditLabelOption{
Color: &newColorWrong,
})
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
// DeleteLabel
req = NewRequest(t, "DELETE", singleURLStr)
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
}
func TestAPIAddIssueLabels(t *testing.T) {
@@ -103,7 +102,7 @@ func TestAPIAddIssueLabels(t *testing.T) {
req := NewRequestWithJSON(t, "POST", urlStr, &api.IssueLabelsOption{
Labels: []int64{1, 2},
})
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiLabels []*api.Label
DecodeJSON(t, resp, &apiLabels)
assert.Len(t, apiLabels, unittest.GetCount(t, &issues_model.IssueLabel{IssueID: issue.ID}))
@@ -126,7 +125,7 @@ func TestAPIReplaceIssueLabels(t *testing.T) {
req := NewRequestWithJSON(t, "PUT", urlStr, &api.IssueLabelsOption{
Labels: []int64{label.ID},
})
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiLabels []*api.Label
DecodeJSON(t, resp, &apiLabels)
if assert.Len(t, apiLabels, 1) {
@@ -153,7 +152,7 @@ func TestAPIModifyOrgLabels(t *testing.T) {
Color: "abcdef",
Description: "test label",
})
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
apiLabel := new(api.Label)
DecodeJSON(t, resp, &apiLabel)
dbLabel := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: apiLabel.ID, OrgID: owner.ID})
@@ -165,16 +164,16 @@ func TestAPIModifyOrgLabels(t *testing.T) {
Color: "#123456",
Description: "jet another test label",
})
- session.MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusCreated)
req = NewRequestWithJSON(t, "POST", urlStr, &api.CreateLabelOption{
Name: "WrongTestL",
Color: "#12345g",
})
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
// ListLabels
req = NewRequest(t, "GET", urlStr)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
var apiLabels []*api.Label
DecodeJSON(t, resp, &apiLabels)
assert.Len(t, apiLabels, 4)
@@ -182,7 +181,7 @@ func TestAPIModifyOrgLabels(t *testing.T) {
// GetLabel
singleURLStr := fmt.Sprintf("/api/v1/orgs/%s/labels/%d?token=%s", owner.Name, dbLabel.ID, token)
req = NewRequest(t, "GET", singleURLStr)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiLabel)
assert.EqualValues(t, strings.TrimLeft(dbLabel.Color, "#"), apiLabel.Color)
@@ -194,15 +193,15 @@ func TestAPIModifyOrgLabels(t *testing.T) {
Name: &newName,
Color: &newColor,
})
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiLabel)
assert.EqualValues(t, newColor, apiLabel.Color)
req = NewRequestWithJSON(t, "PATCH", singleURLStr, &api.EditLabelOption{
Color: &newColorWrong,
})
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
// DeleteLabel
req = NewRequest(t, "DELETE", singleURLStr)
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
}
diff --git a/tests/integration/api_issue_milestone_test.go b/tests/integration/api_issue_milestone_test.go
index e22a091bb..60766e10f 100644
--- a/tests/integration/api_issue_milestone_test.go
+++ b/tests/integration/api_issue_milestone_test.go
@@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -38,13 +37,13 @@ func TestAPIIssuesMilestone(t *testing.T) {
req := NewRequestWithJSON(t, "PATCH", urlStr, structs.EditMilestoneOption{
State: &milestoneState,
})
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiMilestone structs.Milestone
DecodeJSON(t, resp, &apiMilestone)
assert.EqualValues(t, "closed", apiMilestone.State)
req = NewRequest(t, "GET", urlStr)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
var apiMilestone2 structs.Milestone
DecodeJSON(t, resp, &apiMilestone2)
assert.EqualValues(t, "closed", apiMilestone2.State)
@@ -54,28 +53,28 @@ func TestAPIIssuesMilestone(t *testing.T) {
Description: "closed one",
State: "closed",
})
- resp = session.MakeRequest(t, req, http.StatusCreated)
+ resp = MakeRequest(t, req, http.StatusCreated)
DecodeJSON(t, resp, &apiMilestone)
assert.Equal(t, "wow", apiMilestone.Title)
assert.Equal(t, structs.StateClosed, apiMilestone.State)
var apiMilestones []structs.Milestone
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/milestones?state=%s&token=%s", owner.Name, repo.Name, "all", token))
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiMilestones)
assert.Len(t, apiMilestones, 4)
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/milestones/%s?token=%s", owner.Name, repo.Name, apiMilestones[2].Title, token))
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiMilestone)
assert.EqualValues(t, apiMilestones[2], apiMilestone)
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/milestones?state=%s&name=%s&token=%s", owner.Name, repo.Name, "all", "milestone2", token))
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiMilestones)
assert.Len(t, apiMilestones, 1)
assert.Equal(t, int64(2), apiMilestones[0].ID)
req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/milestones/%d?token=%s", owner.Name, repo.Name, apiMilestone.ID, token))
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
}
diff --git a/tests/integration/api_issue_reaction_test.go b/tests/integration/api_issue_reaction_test.go
index a3cb9303f..ec239d762 100644
--- a/tests/integration/api_issue_reaction_test.go
+++ b/tests/integration/api_issue_reaction_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -39,28 +38,28 @@ func TestAPIIssuesReactions(t *testing.T) {
req := NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
Reaction: "wrong",
})
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
// Delete not allowed reaction
req = NewRequestWithJSON(t, "DELETE", urlStr, &api.EditReactionOption{
Reaction: "zzz",
})
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// Add allowed reaction
req = NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
Reaction: "rocket",
})
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var apiNewReaction api.Reaction
DecodeJSON(t, resp, &apiNewReaction)
// Add existing reaction
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
// Get end result of reaction list of issue #1
req = NewRequestf(t, "GET", urlStr)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
var apiReactions []*api.Reaction
DecodeJSON(t, resp, &apiReactions)
expectResponse := make(map[int]api.Reaction)
@@ -82,7 +81,7 @@ func TestAPICommentReactions(t *testing.T) {
defer tests.PrepareTestEnv(t)()
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 2})
- _ = comment.LoadIssue()
+ _ = comment.LoadIssue(db.DefaultContext)
issue := comment.Issue
_ = issue.LoadRepo(db.DefaultContext)
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID})
@@ -99,28 +98,28 @@ func TestAPICommentReactions(t *testing.T) {
req := NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
Reaction: "wrong",
})
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
// Delete none existing reaction
req = NewRequestWithJSON(t, "DELETE", urlStr, &api.EditReactionOption{
Reaction: "eyes",
})
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// Add allowed reaction
req = NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
Reaction: "+1",
})
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var apiNewReaction api.Reaction
DecodeJSON(t, resp, &apiNewReaction)
// Add existing reaction
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
// Get end result of reaction list of issue #1
req = NewRequestf(t, "GET", urlStr)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
var apiReactions []*api.Reaction
DecodeJSON(t, resp, &apiReactions)
expectResponse := make(map[int]api.Reaction)
diff --git a/tests/integration/api_issue_stopwatch_test.go b/tests/integration/api_issue_stopwatch_test.go
index c2ad9c45e..d1a3e86fd 100644
--- a/tests/integration/api_issue_stopwatch_test.go
+++ b/tests/integration/api_issue_stopwatch_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -28,7 +27,7 @@ func TestAPIListStopWatches(t *testing.T) {
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
req := NewRequestf(t, "GET", "/api/v1/user/stopwatches?token=%s", token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiWatches []*api.StopWatch
DecodeJSON(t, resp, &apiWatches)
stopwatch := unittest.AssertExistsAndLoadBean(t, &issues_model.Stopwatch{UserID: owner.ID})
@@ -55,8 +54,8 @@ func TestAPIStopStopWatches(t *testing.T) {
token := getTokenForLoggedInUser(t, session)
req := NewRequestf(t, "POST", "/api/v1/repos/%s/%s/issues/%d/stopwatch/stop?token=%s", owner.Name, issue.Repo.Name, issue.Index, token)
- session.MakeRequest(t, req, http.StatusCreated)
- session.MakeRequest(t, req, http.StatusConflict)
+ MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusConflict)
}
func TestAPICancelStopWatches(t *testing.T) {
@@ -71,8 +70,8 @@ func TestAPICancelStopWatches(t *testing.T) {
token := getTokenForLoggedInUser(t, session)
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/%d/stopwatch/delete?token=%s", owner.Name, issue.Repo.Name, issue.Index, token)
- session.MakeRequest(t, req, http.StatusNoContent)
- session.MakeRequest(t, req, http.StatusConflict)
+ MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusConflict)
}
func TestAPIStartStopWatches(t *testing.T) {
@@ -87,6 +86,6 @@ func TestAPIStartStopWatches(t *testing.T) {
token := getTokenForLoggedInUser(t, session)
req := NewRequestf(t, "POST", "/api/v1/repos/%s/%s/issues/%d/stopwatch/start?token=%s", owner.Name, issue.Repo.Name, issue.Index, token)
- session.MakeRequest(t, req, http.StatusCreated)
- session.MakeRequest(t, req, http.StatusConflict)
+ MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusConflict)
}
diff --git a/tests/integration/api_issue_subscription_test.go b/tests/integration/api_issue_subscription_test.go
index f4588fbbc..a32b51e6f 100644
--- a/tests/integration/api_issue_subscription_test.go
+++ b/tests/integration/api_issue_subscription_test.go
@@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -38,7 +37,7 @@ func TestAPIIssueSubscriptions(t *testing.T) {
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/check?token=%s", issueRepo.OwnerName, issueRepo.Name, issue.Index, token)
req := NewRequest(t, "GET", urlStr)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
wi := new(api.WatchInfo)
DecodeJSON(t, resp, wi)
@@ -58,20 +57,20 @@ func TestAPIIssueSubscriptions(t *testing.T) {
issue1Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue1.RepoID})
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/%s?token=%s", issue1Repo.OwnerName, issue1Repo.Name, issue1.Index, owner.Name, token)
req := NewRequest(t, "DELETE", urlStr)
- session.MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusCreated)
testSubscription(issue1, false)
req = NewRequest(t, "DELETE", urlStr)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
testSubscription(issue1, false)
issue5Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue5.RepoID})
urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/%s?token=%s", issue5Repo.OwnerName, issue5Repo.Name, issue5.Index, owner.Name, token)
req = NewRequest(t, "PUT", urlStr)
- session.MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusCreated)
testSubscription(issue5, true)
req = NewRequest(t, "PUT", urlStr)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
testSubscription(issue5, true)
}
diff --git a/tests/integration/api_issue_test.go b/tests/integration/api_issue_test.go
index 3e651c620..2074bbee7 100644
--- a/tests/integration/api_issue_test.go
+++ b/tests/integration/api_issue_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -34,7 +33,7 @@ func TestAPIListIssues(t *testing.T) {
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues", owner.Name, repo.Name))
link.RawQuery = url.Values{"token": {token}, "state": {"all"}}.Encode()
- resp := session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
+ resp := MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
var apiIssues []*api.Issue
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, unittest.GetCount(t, &issues_model.Issue{RepoID: repo.ID}))
@@ -44,7 +43,7 @@ func TestAPIListIssues(t *testing.T) {
// test milestone filter
link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "type": {"all"}, "milestones": {"ignore,milestone1,3,4"}}.Encode()
- resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
+ resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
if assert.Len(t, apiIssues, 2) {
assert.EqualValues(t, 3, apiIssues[0].Milestone.ID)
@@ -52,21 +51,21 @@ func TestAPIListIssues(t *testing.T) {
}
link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "created_by": {"user2"}}.Encode()
- resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
+ resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
if assert.Len(t, apiIssues, 1) {
assert.EqualValues(t, 5, apiIssues[0].ID)
}
link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "assigned_by": {"user1"}}.Encode()
- resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
+ resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
if assert.Len(t, apiIssues, 1) {
assert.EqualValues(t, 1, apiIssues[0].ID)
}
link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "mentioned_by": {"user4"}}.Encode()
- resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
+ resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
if assert.Len(t, apiIssues, 1) {
assert.EqualValues(t, 1, apiIssues[0].ID)
@@ -88,7 +87,7 @@ func TestAPICreateIssue(t *testing.T) {
Title: title,
Assignee: owner.Name,
})
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var apiIssue api.Issue
DecodeJSON(t, resp, &apiIssue)
assert.Equal(t, body, apiIssue.Body)
@@ -136,7 +135,7 @@ func TestAPIEditIssue(t *testing.T) {
// ToDo change more
})
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var apiIssue api.Issue
DecodeJSON(t, resp, &apiIssue)
diff --git a/tests/integration/api_issue_tracked_time_test.go b/tests/integration/api_issue_tracked_time_test.go
index 6e2c77030..eda4150f8 100644
--- a/tests/integration/api_issue_tracked_time_test.go
+++ b/tests/integration/api_issue_tracked_time_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -31,7 +30,7 @@ func TestAPIGetTrackedTimes(t *testing.T) {
token := getTokenForLoggedInUser(t, session)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/times?token=%s", user2.Name, issue2.Repo.Name, issue2.Index, token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiTimes api.TrackedTimeList
DecodeJSON(t, resp, &apiTimes)
expect, err := issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: issue2.ID})
@@ -44,7 +43,7 @@ func TestAPIGetTrackedTimes(t *testing.T) {
assert.EqualValues(t, issue2.ID, apiTimes[i].IssueID)
assert.Equal(t, time.Created.Unix(), apiTimes[i].Created.Unix())
assert.Equal(t, time.Time, apiTimes[i].Time)
- user, err := user_model.GetUserByID(time.UserID)
+ user, err := user_model.GetUserByID(db.DefaultContext, time.UserID)
assert.NoError(t, err)
assert.Equal(t, user.Name, apiTimes[i].UserName)
}
@@ -54,7 +53,7 @@ func TestAPIGetTrackedTimes(t *testing.T) {
before := "2000-01-01T00%3A00%3A12%2B00%3A00" // 946684812
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/times?since=%s&before=%s&token=%s", user2.Name, issue2.Repo.Name, issue2.Index, since, before, token)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
var filterAPITimes api.TrackedTimeList
DecodeJSON(t, resp, &filterAPITimes)
assert.Len(t, filterAPITimes, 2)
@@ -75,13 +74,13 @@ func TestAPIDeleteTrackedTime(t *testing.T) {
// Deletion not allowed
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/%d/times/%d?token=%s", user2.Name, issue2.Repo.Name, issue2.Index, time6.ID, token)
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
time3 := unittest.AssertExistsAndLoadBean(t, &issues_model.TrackedTime{ID: 3})
req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/%d/times/%d?token=%s", user2.Name, issue2.Repo.Name, issue2.Index, time3.ID, token)
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
// Delete non existing time
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Reset time of user 2 on issue 2
trackedSeconds, err := issues_model.GetTrackedSeconds(db.DefaultContext, issues_model.FindTrackedTimesOptions{IssueID: 2, UserID: 2})
@@ -89,8 +88,8 @@ func TestAPIDeleteTrackedTime(t *testing.T) {
assert.Equal(t, int64(3661), trackedSeconds)
req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/%d/times?token=%s", user2.Name, issue2.Repo.Name, issue2.Index, token)
- session.MakeRequest(t, req, http.StatusNoContent)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNotFound)
trackedSeconds, err = issues_model.GetTrackedSeconds(db.DefaultContext, issues_model.FindTrackedTimesOptions{IssueID: 2, UserID: 2})
assert.NoError(t, err)
@@ -115,7 +114,7 @@ func TestAPIAddTrackedTimes(t *testing.T) {
User: user2.Name,
Created: time.Unix(947688818, 0),
})
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiNewTime api.TrackedTime
DecodeJSON(t, resp, &apiNewTime)
diff --git a/tests/integration/api_keys_test.go b/tests/integration/api_keys_test.go
index 1cb0b20ff..d24db2bd1 100644
--- a/tests/integration/api_keys_test.go
+++ b/tests/integration/api_keys_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gogs Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -62,7 +61,7 @@ func TestCreateReadOnlyDeployKey(t *testing.T) {
ReadOnly: true,
}
req := NewRequestWithJSON(t, "POST", keysURL, rawKeyBody)
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var newDeployKey api.DeployKey
DecodeJSON(t, resp, &newDeployKey)
@@ -87,7 +86,7 @@ func TestCreateReadWriteDeployKey(t *testing.T) {
Key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4cn+iXnA4KvcQYSV88vGn0Yi91vG47t1P7okprVmhNTkipNRIHWr6WdCO4VDr/cvsRkuVJAsLO2enwjGWWueOO6BodiBgyAOZ/5t5nJNMCNuLGT5UIo/RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1PDeDL0JuTjL+tr1SZi/EyxCngpYszKdXllJEHyI79KQgeD0Vt3pTrkbNVTOEcCNqZePSVmUH8X8Vhugz3bnE0/iE9Pb5fkWO9c4AnM1FgI/8Bvp27Fw2ShryIXuR6kKvUqhVMTuOSDHwu6A8jLE5Owt3GAYugDpDYuwTVNGrHLXKpPzrGGPE/jPmaLCMZcsdkec95dYeU3zKODEm8UQZFhmJmDeWVJ36nGrGZHL4J5aTTaeFUJmmXDaJYiJ+K2/ioKgXqnXvltu0A9R8/LGy4nrTJRr4JMLuJFoUXvGm1gXQ70w2LSpk6yl71RNC0hCtsBe8BP8IhYCM0EP5jh7eCMQZNvM= nocomment\n",
}
req := NewRequestWithJSON(t, "POST", keysURL, rawKeyBody)
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var newDeployKey api.DeployKey
DecodeJSON(t, resp, &newDeployKey)
@@ -113,7 +112,7 @@ func TestCreateUserKey(t *testing.T) {
Key: keyType + " " + keyContent,
}
req := NewRequestWithJSON(t, "POST", keysURL, rawKeyBody)
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var newPublicKey api.PublicKey
DecodeJSON(t, resp, &newPublicKey)
@@ -131,7 +130,7 @@ func TestCreateUserKey(t *testing.T) {
fingerprintURL := fmt.Sprintf("/api/v1/user/keys?token=%s&fingerprint=%s", token, newPublicKey.Fingerprint)
req = NewRequest(t, "GET", fingerprintURL)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
var fingerprintPublicKeys []api.PublicKey
DecodeJSON(t, resp, &fingerprintPublicKeys)
@@ -142,7 +141,7 @@ func TestCreateUserKey(t *testing.T) {
fingerprintURL = fmt.Sprintf("/api/v1/users/%s/keys?token=%s&fingerprint=%s", user.Name, token, newPublicKey.Fingerprint)
req = NewRequest(t, "GET", fingerprintURL)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fingerprintPublicKeys)
assert.Equal(t, newPublicKey.Fingerprint, fingerprintPublicKeys[0].Fingerprint)
@@ -153,7 +152,7 @@ func TestCreateUserKey(t *testing.T) {
fingerprintURL = fmt.Sprintf("/api/v1/user/keys?token=%s&fingerprint=%sA", token, newPublicKey.Fingerprint)
req = NewRequest(t, "GET", fingerprintURL)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fingerprintPublicKeys)
assert.Len(t, fingerprintPublicKeys, 0)
@@ -161,7 +160,7 @@ func TestCreateUserKey(t *testing.T) {
// Fail searching for wrong users key
fingerprintURL = fmt.Sprintf("/api/v1/users/%s/keys?token=%s&fingerprint=%s", "user2", token, newPublicKey.Fingerprint)
req = NewRequest(t, "GET", fingerprintURL)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fingerprintPublicKeys)
assert.Len(t, fingerprintPublicKeys, 0)
@@ -173,7 +172,7 @@ func TestCreateUserKey(t *testing.T) {
// Should find key even though not ours, but we shouldn't know whose it is
fingerprintURL = fmt.Sprintf("/api/v1/user/keys?token=%s&fingerprint=%s", token2, newPublicKey.Fingerprint)
req = NewRequest(t, "GET", fingerprintURL)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fingerprintPublicKeys)
assert.Equal(t, newPublicKey.Fingerprint, fingerprintPublicKeys[0].Fingerprint)
@@ -184,7 +183,7 @@ func TestCreateUserKey(t *testing.T) {
fingerprintURL = fmt.Sprintf("/api/v1/users/%s/keys?token=%s&fingerprint=%s", user.Name, token2, newPublicKey.Fingerprint)
req = NewRequest(t, "GET", fingerprintURL)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fingerprintPublicKeys)
assert.Equal(t, newPublicKey.Fingerprint, fingerprintPublicKeys[0].Fingerprint)
@@ -194,7 +193,7 @@ func TestCreateUserKey(t *testing.T) {
// Fail when searching for key if it is not ours
fingerprintURL = fmt.Sprintf("/api/v1/users/%s/keys?token=%s&fingerprint=%s", "user2", token2, newPublicKey.Fingerprint)
req = NewRequest(t, "GET", fingerprintURL)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fingerprintPublicKeys)
assert.Len(t, fingerprintPublicKeys, 0)
diff --git a/tests/integration/api_nodeinfo_test.go b/tests/integration/api_nodeinfo_test.go
index 2446acec9..a7313f3b2 100644
--- a/tests/integration/api_nodeinfo_test.go
+++ b/tests/integration/api_nodeinfo_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_notification_test.go b/tests/integration/api_notification_test.go
index bf85520bb..cd230d688 100644
--- a/tests/integration/api_notification_test.go
+++ b/tests/integration/api_notification_test.go
@@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -10,6 +9,7 @@ import (
"testing"
activities_model "code.gitea.io/gitea/models/activities"
+ "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -25,7 +25,7 @@ func TestAPINotification(t *testing.T) {
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
- assert.NoError(t, thread5.LoadAttributes())
+ assert.NoError(t, thread5.LoadAttributes(db.DefaultContext))
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session)
@@ -33,7 +33,7 @@ func TestAPINotification(t *testing.T) {
// test filter
since := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?since=%s&token=%s", since, token))
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiNL []api.NotificationThread
DecodeJSON(t, resp, &apiNL)
@@ -44,7 +44,7 @@ func TestAPINotification(t *testing.T) {
before := "2000-01-01T01%3A06%3A59%2B00%3A00" // 946688819
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?all=%s&before=%s&token=%s", "true", before, token))
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
assert.Len(t, apiNL, 3)
@@ -60,7 +60,7 @@ func TestAPINotification(t *testing.T) {
// -- GET /repos/{owner}/{repo}/notifications --
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?status-types=unread&token=%s", user2.Name, repo1.Name, token))
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
assert.Len(t, apiNL, 1)
@@ -68,7 +68,7 @@ func TestAPINotification(t *testing.T) {
// -- GET /repos/{owner}/{repo}/notifications -- multiple status-types
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?status-types=unread&status-types=pinned&token=%s", user2.Name, repo1.Name, token))
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
assert.Len(t, apiNL, 2)
@@ -82,11 +82,11 @@ func TestAPINotification(t *testing.T) {
// -- GET /notifications/threads/{id} --
// get forbidden
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", 1, token))
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
// get own
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", thread5.ID, token))
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
var apiN api.NotificationThread
DecodeJSON(t, resp, &apiN)
@@ -104,28 +104,28 @@ func TestAPINotification(t *testing.T) {
// -- check notifications --
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token))
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &new)
assert.True(t, new.New > 0)
// -- mark notifications as read --
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?status-types=unread&token=%s", token))
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
assert.Len(t, apiNL, 2)
lastReadAt := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801 <- only Notification 4 is in this filter ...
req = NewRequest(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?last_read_at=%s&token=%s", user2.Name, repo1.Name, lastReadAt, token))
- session.MakeRequest(t, req, http.StatusResetContent)
+ MakeRequest(t, req, http.StatusResetContent)
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?status-types=unread&token=%s", token))
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
assert.Len(t, apiNL, 1)
// -- PATCH /notifications/threads/{id} --
req = NewRequest(t, "PATCH", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", thread5.ID, token))
- session.MakeRequest(t, req, http.StatusResetContent)
+ MakeRequest(t, req, http.StatusResetContent)
assert.Equal(t, activities_model.NotificationStatusUnread, thread5.Status)
thread5 = unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
@@ -133,7 +133,7 @@ func TestAPINotification(t *testing.T) {
// -- check notifications --
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token))
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &new)
assert.True(t, new.New == 0)
}
@@ -143,13 +143,13 @@ func TestAPINotificationPUT(t *testing.T) {
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
- assert.NoError(t, thread5.LoadAttributes())
+ assert.NoError(t, thread5.LoadAttributes(db.DefaultContext))
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session)
// Check notifications are as expected
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?all=true&token=%s", token))
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiNL []api.NotificationThread
DecodeJSON(t, resp, &apiNL)
@@ -172,7 +172,7 @@ func TestAPINotificationPUT(t *testing.T) {
// change it to unread.
//
req = NewRequest(t, "PUT", fmt.Sprintf("/api/v1/notifications?status-types=read&status-type=pinned&to-status=unread&token=%s", token))
- resp = session.MakeRequest(t, req, http.StatusResetContent)
+ resp = MakeRequest(t, req, http.StatusResetContent)
DecodeJSON(t, resp, &apiNL)
assert.Len(t, apiNL, 1)
assert.EqualValues(t, 2, apiNL[0].ID)
@@ -183,7 +183,7 @@ func TestAPINotificationPUT(t *testing.T) {
// Now nofication ID 2 is the first in the list and is unread.
//
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?all=true&token=%s", token))
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
assert.Len(t, apiNL, 4)
diff --git a/tests/integration/api_oauth2_apps_test.go b/tests/integration/api_oauth2_apps_test.go
index 6352449d6..d2a85992a 100644
--- a/tests/integration/api_oauth2_apps_test.go
+++ b/tests/integration/api_oauth2_apps_test.go
@@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.package models
+// SPDX-License-Identifier: MIT
package integration
@@ -69,7 +68,7 @@ func testAPIListOAuth2Applications(t *testing.T) {
urlStr := fmt.Sprintf("/api/v1/user/applications/oauth2?token=%s", token)
req := NewRequest(t, "GET", urlStr)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var appList api.OAuth2ApplicationList
DecodeJSON(t, resp, &appList)
@@ -96,13 +95,13 @@ func testAPIDeleteOAuth2Application(t *testing.T) {
urlStr := fmt.Sprintf("/api/v1/user/applications/oauth2/%d?token=%s", oldApp.ID, token)
req := NewRequest(t, "DELETE", urlStr)
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
unittest.AssertNotExistsBean(t, &auth.OAuth2Application{UID: oldApp.UID, Name: oldApp.Name})
// Delete again will return not found
req = NewRequest(t, "DELETE", urlStr)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
}
func testAPIGetOAuth2Application(t *testing.T) {
@@ -121,7 +120,7 @@ func testAPIGetOAuth2Application(t *testing.T) {
urlStr := fmt.Sprintf("/api/v1/user/applications/oauth2/%d?token=%s", existApp.ID, token)
req := NewRequest(t, "GET", urlStr)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var app api.OAuth2Application
DecodeJSON(t, resp, &app)
diff --git a/tests/integration/api_org_test.go b/tests/integration/api_org_test.go
index 16e53d6b8..0be0c170d 100644
--- a/tests/integration/api_org_test.go
+++ b/tests/integration/api_org_test.go
@@ -1,6 +1,5 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -89,7 +88,7 @@ func TestAPIOrgEdit(t *testing.T) {
Visibility: "private",
}
req := NewRequestWithJSON(t, "PATCH", "/api/v1/orgs/user3?token="+token, &org)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiOrg api.Organization
DecodeJSON(t, resp, &apiOrg)
@@ -116,7 +115,7 @@ func TestAPIOrgEditBadVisibility(t *testing.T) {
Visibility: "badvisibility",
}
req := NewRequestWithJSON(t, "PATCH", "/api/v1/orgs/user3?token="+token, &org)
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
})
}
diff --git a/tests/integration/api_packages_composer_test.go b/tests/integration/api_packages_composer_test.go
index 90285f78d..87647cc47 100644
--- a/tests/integration/api_packages_composer_test.go
+++ b/tests/integration/api_packages_composer_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_packages_conan_test.go b/tests/integration/api_packages_conan_test.go
index 40c8b7088..5ced388b4 100644
--- a/tests/integration/api_packages_conan_test.go
+++ b/tests/integration/api_packages_conan_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_packages_container_test.go b/tests/integration/api_packages_container_test.go
index ba76ee4ba..851021da1 100644
--- a/tests/integration/api_packages_container_test.go
+++ b/tests/integration/api_packages_container_test.go
@@ -1,15 +1,16 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
import (
"bytes"
+ "crypto/sha256"
"encoding/base64"
"fmt"
"net/http"
"strings"
+ "sync"
"testing"
"code.gitea.io/gitea/models/db"
@@ -594,6 +595,32 @@ func TestPackageContainer(t *testing.T) {
})
}
+ // https://github.com/go-gitea/gitea/issues/19586
+ t.Run("ParallelUpload", func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
+
+ url := fmt.Sprintf("%sv2/%s/parallel", setting.AppURL, user.Name)
+
+ var wg sync.WaitGroup
+ for i := 0; i < 10; i++ {
+ wg.Add(1)
+
+ content := []byte{byte(i)}
+ digest := fmt.Sprintf("sha256:%x", sha256.Sum256(content))
+
+ go func() {
+ defer wg.Done()
+
+ req := NewRequestWithBody(t, "POST", fmt.Sprintf("%s/blobs/uploads?digest=%s", url, digest), bytes.NewReader(content))
+ addTokenAuthHeader(req, userToken)
+ resp := MakeRequest(t, req, http.StatusCreated)
+
+ assert.Equal(t, digest, resp.Header().Get("Docker-Content-Digest"))
+ }()
+ }
+ wg.Wait()
+ })
+
t.Run("OwnerNameChange", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
diff --git a/tests/integration/api_packages_generic_test.go b/tests/integration/api_packages_generic_test.go
index 4c5c0c615..875b9ed96 100644
--- a/tests/integration/api_packages_generic_test.go
+++ b/tests/integration/api_packages_generic_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_packages_helm_test.go b/tests/integration/api_packages_helm_test.go
index 393bf3cbe..4a7d56343 100644
--- a/tests/integration/api_packages_helm_test.go
+++ b/tests/integration/api_packages_helm_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -22,7 +21,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
- "gopkg.in/yaml.v2"
+ "gopkg.in/yaml.v3"
)
func TestPackageHelm(t *testing.T) {
diff --git a/tests/integration/api_packages_maven_test.go b/tests/integration/api_packages_maven_test.go
index 87d95557c..5c0dbfc99 100644
--- a/tests/integration/api_packages_maven_test.go
+++ b/tests/integration/api_packages_maven_test.go
@@ -1,12 +1,12 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
import (
"fmt"
"net/http"
+ "strconv"
"strings"
"testing"
@@ -39,6 +39,12 @@ func TestPackageMaven(t *testing.T) {
MakeRequest(t, req, expectedStatus)
}
+ checkHeaders := func(t *testing.T, h http.Header, contentType string, contentLength int64) {
+ assert.Equal(t, contentType, h.Get("Content-Type"))
+ assert.Equal(t, strconv.FormatInt(contentLength, 10), h.Get("Content-Length"))
+ assert.NotEmpty(t, h.Get("Last-Modified"))
+ }
+
t.Run("Upload", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
@@ -77,10 +83,18 @@ func TestPackageMaven(t *testing.T) {
t.Run("Download", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
- req := NewRequest(t, "GET", fmt.Sprintf("%s/%s/%s", root, packageVersion, filename))
+ req := NewRequest(t, "HEAD", fmt.Sprintf("%s/%s/%s", root, packageVersion, filename))
req = AddBasicAuthHeader(req, user.Name)
resp := MakeRequest(t, req, http.StatusOK)
+ checkHeaders(t, resp.Header(), "application/java-archive", 4)
+
+ req = NewRequest(t, "GET", fmt.Sprintf("%s/%s/%s", root, packageVersion, filename))
+ req = AddBasicAuthHeader(req, user.Name)
+ resp = MakeRequest(t, req, http.StatusOK)
+
+ checkHeaders(t, resp.Header(), "application/java-archive", 4)
+
assert.Equal(t, []byte("test"), resp.Body.Bytes())
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeMaven)
@@ -150,10 +164,18 @@ func TestPackageMaven(t *testing.T) {
t.Run("DownloadPOM", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
- req := NewRequest(t, "GET", fmt.Sprintf("%s/%s/%s.pom", root, packageVersion, filename))
+ req := NewRequest(t, "HEAD", fmt.Sprintf("%s/%s/%s.pom", root, packageVersion, filename))
req = AddBasicAuthHeader(req, user.Name)
resp := MakeRequest(t, req, http.StatusOK)
+ checkHeaders(t, resp.Header(), "text/xml", int64(len(pomContent)))
+
+ req = NewRequest(t, "GET", fmt.Sprintf("%s/%s/%s.pom", root, packageVersion, filename))
+ req = AddBasicAuthHeader(req, user.Name)
+ resp = MakeRequest(t, req, http.StatusOK)
+
+ checkHeaders(t, resp.Header(), "text/xml", int64(len(pomContent)))
+
assert.Equal(t, []byte(pomContent), resp.Body.Bytes())
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeMaven)
@@ -191,6 +213,9 @@ func TestPackageMaven(t *testing.T) {
resp := MakeRequest(t, req, http.StatusOK)
expectedMetadata := `<?xml version="1.0" encoding="UTF-8"?>` + "\n<metadata><groupId>com.gitea</groupId><artifactId>test-project</artifactId><versioning><release>1.0.1</release><latest>1.0.1</latest><versions><version>1.0.1</version></versions></versioning></metadata>"
+
+ checkHeaders(t, resp.Header(), "text/xml", int64(len(expectedMetadata)))
+
assert.Equal(t, expectedMetadata, resp.Body.String())
for key, checksum := range map[string]string{
diff --git a/tests/integration/api_packages_npm_test.go b/tests/integration/api_packages_npm_test.go
index 20412fe72..39d1c91e8 100644
--- a/tests/integration/api_packages_npm_test.go
+++ b/tests/integration/api_packages_npm_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_packages_nuget_test.go b/tests/integration/api_packages_nuget_test.go
index bf4217ef2..cc4ff180d 100644
--- a/tests/integration/api_packages_nuget_test.go
+++ b/tests/integration/api_packages_nuget_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -11,7 +10,6 @@ import (
"encoding/xml"
"fmt"
"io"
- "io/ioutil"
"net/http"
"net/http/httptest"
"testing"
@@ -106,7 +104,7 @@ func TestPackageNuGet(t *testing.T) {
return &buf
}
- content, _ := ioutil.ReadAll(createPackage(packageName, packageVersion))
+ content, _ := io.ReadAll(createPackage(packageName, packageVersion))
url := fmt.Sprintf("/api/packages/%s/nuget", user.Name)
diff --git a/tests/integration/api_packages_pub_test.go b/tests/integration/api_packages_pub_test.go
index 9e4ce63fa..325401fe7 100644
--- a/tests/integration/api_packages_pub_test.go
+++ b/tests/integration/api_packages_pub_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_packages_pypi_test.go b/tests/integration/api_packages_pypi_test.go
index 0cd6ff7d1..71197f92a 100644
--- a/tests/integration/api_packages_pypi_test.go
+++ b/tests/integration/api_packages_pypi_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -29,7 +28,7 @@ func TestPackagePyPI(t *testing.T) {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
packageName := "test-package"
- packageVersion := "1.0.1+r1234"
+ packageVersion := "1!1.0.1+r1234"
packageAuthor := "KN4CK3R"
packageDescription := "Test Description"
@@ -72,7 +71,7 @@ func TestPackagePyPI(t *testing.T) {
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
assert.NoError(t, err)
- assert.NotNil(t, pd.SemVer)
+ assert.Nil(t, pd.SemVer)
assert.IsType(t, &pypi.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
@@ -100,7 +99,7 @@ func TestPackagePyPI(t *testing.T) {
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
assert.NoError(t, err)
- assert.NotNil(t, pd.SemVer)
+ assert.Nil(t, pd.SemVer)
assert.IsType(t, &pypi.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
diff --git a/tests/integration/api_packages_rubygems_test.go b/tests/integration/api_packages_rubygems_test.go
index 6cf5af710..c85ff9aaf 100644
--- a/tests/integration/api_packages_rubygems_test.go
+++ b/tests/integration/api_packages_rubygems_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_packages_test.go b/tests/integration/api_packages_test.go
index 25f5b3f2a..8346e3bcc 100644
--- a/tests/integration/api_packages_test.go
+++ b/tests/integration/api_packages_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -16,6 +15,7 @@ import (
container_model "code.gitea.io/gitea/models/packages/container"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
+ "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
packages_service "code.gitea.io/gitea/services/packages"
"code.gitea.io/gitea/tests"
@@ -166,25 +166,207 @@ func TestPackageAccess(t *testing.T) {
uploadPackage(admin, user, http.StatusCreated)
}
+func TestPackageQuota(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ limitTotalOwnerCount, limitTotalOwnerSize, limitSizeGeneric := setting.Packages.LimitTotalOwnerCount, setting.Packages.LimitTotalOwnerSize, setting.Packages.LimitSizeGeneric
+
+ admin := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
+ user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 10})
+
+ uploadPackage := func(doer *user_model.User, version string, expectedStatus int) {
+ url := fmt.Sprintf("/api/packages/%s/generic/test-package/%s/file.bin", user.Name, version)
+ req := NewRequestWithBody(t, "PUT", url, bytes.NewReader([]byte{1}))
+ AddBasicAuthHeader(req, doer.Name)
+ MakeRequest(t, req, expectedStatus)
+ }
+
+ // Exceeded quota result in StatusForbidden for normal users but admins are always allowed to upload.
+
+ setting.Packages.LimitTotalOwnerCount = 0
+ uploadPackage(user, "1.0", http.StatusForbidden)
+ uploadPackage(admin, "1.0", http.StatusCreated)
+ setting.Packages.LimitTotalOwnerCount = limitTotalOwnerCount
+
+ setting.Packages.LimitTotalOwnerSize = 0
+ uploadPackage(user, "1.1", http.StatusForbidden)
+ uploadPackage(admin, "1.1", http.StatusCreated)
+ setting.Packages.LimitTotalOwnerSize = limitTotalOwnerSize
+
+ setting.Packages.LimitSizeGeneric = 0
+ uploadPackage(user, "1.2", http.StatusForbidden)
+ uploadPackage(admin, "1.2", http.StatusCreated)
+ setting.Packages.LimitSizeGeneric = limitSizeGeneric
+}
+
func TestPackageCleanup(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- time.Sleep(time.Second)
+ duration, _ := time.ParseDuration("-1h")
+
+ t.Run("Common", func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
- pbs, err := packages_model.FindExpiredUnreferencedBlobs(db.DefaultContext, time.Duration(0))
- assert.NoError(t, err)
- assert.NotEmpty(t, pbs)
+ pbs, err := packages_model.FindExpiredUnreferencedBlobs(db.DefaultContext, duration)
+ assert.NoError(t, err)
+ assert.NotEmpty(t, pbs)
- _, err = packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, 2, packages_model.TypeContainer, "test", container_model.UploadVersion)
- assert.NoError(t, err)
+ _, err = packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, 2, packages_model.TypeContainer, "test", container_model.UploadVersion)
+ assert.NoError(t, err)
- err = packages_service.Cleanup(nil, time.Duration(0))
- assert.NoError(t, err)
+ err = packages_service.Cleanup(db.DefaultContext, duration)
+ assert.NoError(t, err)
- pbs, err = packages_model.FindExpiredUnreferencedBlobs(db.DefaultContext, time.Duration(0))
- assert.NoError(t, err)
- assert.Empty(t, pbs)
+ pbs, err = packages_model.FindExpiredUnreferencedBlobs(db.DefaultContext, duration)
+ assert.NoError(t, err)
+ assert.Empty(t, pbs)
- _, err = packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, 2, packages_model.TypeContainer, "test", container_model.UploadVersion)
- assert.ErrorIs(t, err, packages_model.ErrPackageNotExist)
+ _, err = packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, 2, packages_model.TypeContainer, "test", container_model.UploadVersion)
+ assert.ErrorIs(t, err, packages_model.ErrPackageNotExist)
+ })
+
+ t.Run("CleanupRules", func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
+
+ user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
+
+ type version struct {
+ Version string
+ ShouldExist bool
+ Created int64
+ }
+
+ cases := []struct {
+ Name string
+ Versions []version
+ Rule *packages_model.PackageCleanupRule
+ }{
+ {
+ Name: "Disabled",
+ Versions: []version{
+ {Version: "keep", ShouldExist: true},
+ },
+ Rule: &packages_model.PackageCleanupRule{
+ Enabled: false,
+ },
+ },
+ {
+ Name: "KeepCount",
+ Versions: []version{
+ {Version: "keep", ShouldExist: true},
+ {Version: "v1.0", ShouldExist: true},
+ {Version: "test-3", ShouldExist: false, Created: 1},
+ {Version: "test-4", ShouldExist: false, Created: 1},
+ },
+ Rule: &packages_model.PackageCleanupRule{
+ Enabled: true,
+ KeepCount: 2,
+ },
+ },
+ {
+ Name: "KeepPattern",
+ Versions: []version{
+ {Version: "keep", ShouldExist: true},
+ {Version: "v1.0", ShouldExist: false},
+ },
+ Rule: &packages_model.PackageCleanupRule{
+ Enabled: true,
+ KeepPattern: "k.+p",
+ },
+ },
+ {
+ Name: "RemoveDays",
+ Versions: []version{
+ {Version: "keep", ShouldExist: true},
+ {Version: "v1.0", ShouldExist: false, Created: 1},
+ },
+ Rule: &packages_model.PackageCleanupRule{
+ Enabled: true,
+ RemoveDays: 60,
+ },
+ },
+ {
+ Name: "RemovePattern",
+ Versions: []version{
+ {Version: "test", ShouldExist: true},
+ {Version: "test-3", ShouldExist: false},
+ {Version: "test-4", ShouldExist: false},
+ },
+ Rule: &packages_model.PackageCleanupRule{
+ Enabled: true,
+ RemovePattern: `t[e]+st-\d+`,
+ },
+ },
+ {
+ Name: "MatchFullName",
+ Versions: []version{
+ {Version: "keep", ShouldExist: true},
+ {Version: "test", ShouldExist: false},
+ },
+ Rule: &packages_model.PackageCleanupRule{
+ Enabled: true,
+ RemovePattern: `package/test|different/keep`,
+ MatchFullName: true,
+ },
+ },
+ {
+ Name: "Mixed",
+ Versions: []version{
+ {Version: "keep", ShouldExist: true, Created: time.Now().Add(time.Duration(10000)).Unix()},
+ {Version: "dummy", ShouldExist: true, Created: 1},
+ {Version: "test-3", ShouldExist: true},
+ {Version: "test-4", ShouldExist: false, Created: 1},
+ },
+ Rule: &packages_model.PackageCleanupRule{
+ Enabled: true,
+ KeepCount: 1,
+ KeepPattern: `dummy`,
+ RemoveDays: 7,
+ RemovePattern: `t[e]+st-\d+`,
+ },
+ },
+ }
+
+ for _, c := range cases {
+ t.Run(c.Name, func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
+
+ for _, v := range c.Versions {
+ url := fmt.Sprintf("/api/packages/%s/generic/package/%s/file.bin", user.Name, v.Version)
+ req := NewRequestWithBody(t, "PUT", url, bytes.NewReader([]byte{1}))
+ AddBasicAuthHeader(req, user.Name)
+ MakeRequest(t, req, http.StatusCreated)
+
+ if v.Created != 0 {
+ pv, err := packages_model.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeGeneric, "package", v.Version)
+ assert.NoError(t, err)
+ _, err = db.GetEngine(db.DefaultContext).Exec("UPDATE package_version SET created_unix = ? WHERE id = ?", v.Created, pv.ID)
+ assert.NoError(t, err)
+ }
+ }
+
+ c.Rule.OwnerID = user.ID
+ c.Rule.Type = packages_model.TypeGeneric
+
+ pcr, err := packages_model.InsertCleanupRule(db.DefaultContext, c.Rule)
+ assert.NoError(t, err)
+
+ err = packages_service.Cleanup(db.DefaultContext, duration)
+ assert.NoError(t, err)
+
+ for _, v := range c.Versions {
+ pv, err := packages_model.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeGeneric, "package", v.Version)
+ if v.ShouldExist {
+ assert.NoError(t, err)
+ err = packages_service.DeletePackageVersionAndReferences(db.DefaultContext, pv)
+ assert.NoError(t, err)
+ } else {
+ assert.ErrorIs(t, err, packages_model.ErrPackageNotExist)
+ }
+ }
+
+ assert.NoError(t, packages_model.DeleteCleanupRuleByID(db.DefaultContext, pcr.ID))
+ })
+ }
+ })
}
diff --git a/tests/integration/api_packages_vagrant_test.go b/tests/integration/api_packages_vagrant_test.go
index 1d2952e1a..b4f04b0c8 100644
--- a/tests/integration/api_packages_vagrant_test.go
+++ b/tests/integration/api_packages_vagrant_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -88,7 +87,7 @@ func TestPackageVagrant(t *testing.T) {
req = NewRequest(t, "HEAD", boxURL)
resp := MakeRequest(t, req, http.StatusOK)
- assert.True(t, strings.HasPrefix(resp.HeaderMap.Get("Content-Type"), "application/json"))
+ assert.True(t, strings.HasPrefix(resp.Header().Get("Content-Type"), "application/json"))
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeVagrant)
assert.NoError(t, err)
diff --git a/tests/integration/api_private_serv_test.go b/tests/integration/api_private_serv_test.go
index 6fd6d616d..d26935f44 100644
--- a/tests/integration/api_private_serv_test.go
+++ b/tests/integration/api_private_serv_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_pull_commits_test.go b/tests/integration/api_pull_commits_test.go
index aa58f44bb..0bcfb9068 100644
--- a/tests/integration/api_pull_commits_test.go
+++ b/tests/integration/api_pull_commits_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -8,6 +7,7 @@ import (
"net/http"
"testing"
+ "code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
@@ -19,13 +19,12 @@ import (
func TestAPIPullCommits(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- pullIssue := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
- assert.NoError(t, pullIssue.LoadIssue())
- repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue.HeadRepoID})
+ pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
+ assert.NoError(t, pr.LoadIssue(db.DefaultContext))
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pr.HeadRepoID})
- session := loginUser(t, "user2")
- req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pullIssue.Index)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pr.Index)
+ resp := MakeRequest(t, req, http.StatusOK)
var commits []*api.Commit
DecodeJSON(t, resp, &commits)
diff --git a/tests/integration/api_pull_review_test.go b/tests/integration/api_pull_review_test.go
index 6ebad106f..4b9c60178 100644
--- a/tests/integration/api_pull_review_test.go
+++ b/tests/integration/api_pull_review_test.go
@@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -30,7 +29,7 @@ func TestAPIPullReview(t *testing.T) {
session := loginUser(t, "user2")
token := getTokenForLoggedInUser(t, session)
req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var reviews []*api.PullReview
DecodeJSON(t, resp, &reviews)
@@ -55,20 +54,20 @@ func TestAPIPullReview(t *testing.T) {
// test GetPullReview
req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews/%d?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, reviews[3].ID, token)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
var review api.PullReview
DecodeJSON(t, resp, &review)
assert.EqualValues(t, *reviews[3], review)
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/pulls/%d/reviews/%d?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, reviews[5].ID, token)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &review)
assert.EqualValues(t, *reviews[5], review)
// test GetPullReviewComments
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 7})
req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews/%d/comments?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, 10, token)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
var reviewComments []*api.PullReviewComment
DecodeJSON(t, resp, &reviewComments)
assert.Len(t, reviewComments, 1)
@@ -101,7 +100,7 @@ func TestAPIPullReview(t *testing.T) {
},
},
})
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &review)
assert.EqualValues(t, 6, review.ID)
assert.EqualValues(t, "PENDING", review.State)
@@ -112,7 +111,7 @@ func TestAPIPullReview(t *testing.T) {
Event: "APPROVED",
Body: "just two nits",
})
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &review)
assert.EqualValues(t, 6, review.ID)
assert.EqualValues(t, "APPROVED", review.State)
@@ -122,14 +121,14 @@ func TestAPIPullReview(t *testing.T) {
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews/%d/dismissals?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, review.ID, token), &api.DismissPullReviewOptions{
Message: "test",
})
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &review)
assert.EqualValues(t, 6, review.ID)
assert.True(t, review.Dismissed)
// test dismiss review
req = NewRequest(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews/%d/undismissals?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, review.ID, token))
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &review)
assert.EqualValues(t, 6, review.ID)
assert.False(t, review.Dismissed)
@@ -139,12 +138,12 @@ func TestAPIPullReview(t *testing.T) {
Body: "just a comment",
Event: "COMMENT",
})
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &review)
assert.EqualValues(t, "COMMENT", review.State)
assert.EqualValues(t, 0, review.CodeCommentsCount)
req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%s/pulls/%d/reviews/%d?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, review.ID, token)
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
// test CreatePullReview Comment without body but with comments
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.CreatePullReviewOptions{
@@ -166,7 +165,7 @@ func TestAPIPullReview(t *testing.T) {
})
var commentReview api.PullReview
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &commentReview)
assert.EqualValues(t, "COMMENT", commentReview.State)
assert.EqualValues(t, 2, commentReview.CodeCommentsCount)
@@ -181,7 +180,7 @@ func TestAPIPullReview(t *testing.T) {
Comments: []api.CreatePullReviewComment{},
})
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &commentReview)
assert.EqualValues(t, "COMMENT", commentReview.State)
assert.EqualValues(t, 0, commentReview.CodeCommentsCount)
@@ -194,7 +193,7 @@ func TestAPIPullReview(t *testing.T) {
Event: "COMMENT",
Comments: []api.CreatePullReviewComment{},
})
- resp = session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ resp = MakeRequest(t, req, http.StatusUnprocessableEntity)
errMap := make(map[string]interface{})
json.Unmarshal(resp.Body.Bytes(), &errMap)
assert.EqualValues(t, "review event COMMENT requires a body or a comment", errMap["message"].(string))
@@ -206,7 +205,7 @@ func TestAPIPullReview(t *testing.T) {
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue12.RepoID})
req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &reviews)
assert.EqualValues(t, 11, reviews[0].ID)
assert.EqualValues(t, "REQUEST_REVIEW", reviews[0].State)
@@ -235,19 +234,19 @@ func TestAPIPullReviewRequest(t *testing.T) {
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.PullReviewRequestOptions{
Reviewers: []string{"user4@example.com", "user8"},
})
- session.MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusCreated)
// poster of pr can't be reviewer
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.PullReviewRequestOptions{
Reviewers: []string{"user1"},
})
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
// test user not exist
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.PullReviewRequestOptions{
Reviewers: []string{"testOther"},
})
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test Remove Review Request
session2 := loginUser(t, "user4")
@@ -256,18 +255,18 @@ func TestAPIPullReviewRequest(t *testing.T) {
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token2), &api.PullReviewRequestOptions{
Reviewers: []string{"user4"},
})
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
// doer is not admin
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token2), &api.PullReviewRequestOptions{
Reviewers: []string{"user8"},
})
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.PullReviewRequestOptions{
Reviewers: []string{"user8"},
})
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
// Test team review request
pullIssue12 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 12})
@@ -278,30 +277,30 @@ func TestAPIPullReviewRequest(t *testing.T) {
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token), &api.PullReviewRequestOptions{
TeamReviewers: []string{"team1", "owners"},
})
- session.MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusCreated)
// Test add Team Review Request to not allowned
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token), &api.PullReviewRequestOptions{
TeamReviewers: []string{"test_team"},
})
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
// Test add Team Review Request to not exist
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token), &api.PullReviewRequestOptions{
TeamReviewers: []string{"not_exist_team"},
})
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test Remove team Review Request
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token), &api.PullReviewRequestOptions{
TeamReviewers: []string{"team1"},
})
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
// empty request test
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token), &api.PullReviewRequestOptions{})
- session.MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusCreated)
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token), &api.PullReviewRequestOptions{})
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
}
diff --git a/tests/integration/api_pull_test.go b/tests/integration/api_pull_test.go
index 8ce92f3d4..89d39179a 100644
--- a/tests/integration/api_pull_test.go
+++ b/tests/integration/api_pull_test.go
@@ -1,15 +1,15 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
import (
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"testing"
+ "code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
@@ -41,7 +41,7 @@ func TestAPIViewPulls(t *testing.T) {
pull := pulls[0]
if assert.EqualValues(t, 5, pull.ID) {
resp = ctx.Session.MakeRequest(t, NewRequest(t, "GET", pull.DiffURL), http.StatusOK)
- _, err := ioutil.ReadAll(resp.Body)
+ _, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
// TODO: use diff to generate stats to test against
@@ -65,11 +65,11 @@ func TestAPIMergePullWIP(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{Status: issues_model.PullRequestStatusMergeable}, unittest.Cond("has_merged = ?", false))
- pr.LoadIssue()
+ pr.LoadIssue(db.DefaultContext)
issue_service.ChangeTitle(pr.Issue, owner, setting.Repository.PullRequest.WorkInProgressPrefixes[0]+" "+pr.Issue.Title)
// force reload
- pr.LoadAttributes()
+ pr.LoadAttributes(db.DefaultContext)
assert.Contains(t, pr.Issue.Title, setting.Repository.PullRequest.WorkInProgressPrefixes[0])
@@ -80,7 +80,7 @@ func TestAPIMergePullWIP(t *testing.T) {
Do: string(repo_model.MergeStyleMerge),
})
- session.MakeRequest(t, req, http.StatusMethodNotAllowed)
+ MakeRequest(t, req, http.StatusMethodNotAllowed)
}
func TestAPICreatePullSuccess(t *testing.T) {
@@ -99,8 +99,8 @@ func TestAPICreatePullSuccess(t *testing.T) {
Base: "master",
Title: "create a failure pr",
})
- session.MakeRequest(t, req, http.StatusCreated)
- session.MakeRequest(t, req, http.StatusUnprocessableEntity) // second request should fail
+ MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusUnprocessableEntity) // second request should fail
}
func TestAPICreatePullWithFieldsSuccess(t *testing.T) {
@@ -127,7 +127,7 @@ func TestAPICreatePullWithFieldsSuccess(t *testing.T) {
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls?token=%s", owner10.Name, repo10.Name, token), opts)
- res := session.MakeRequest(t, req, http.StatusCreated)
+ res := MakeRequest(t, req, http.StatusCreated)
pull := new(api.PullRequest)
DecodeJSON(t, res, pull)
@@ -158,19 +158,19 @@ func TestAPICreatePullWithFieldsFailure(t *testing.T) {
}
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls?token=%s", owner10.Name, repo10.Name, token), opts)
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
opts.Title = "is required"
opts.Milestone = 666
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
opts.Milestone = 5
opts.Assignees = []string{"qweruqweroiuyqweoiruywqer"}
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
opts.Assignees = []string{owner10.LoginName}
opts.Labels = []int64{55555}
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
opts.Labels = []int64{5}
}
@@ -187,7 +187,7 @@ func TestAPIEditPull(t *testing.T) {
Title: "create a success pr",
})
pull := new(api.PullRequest)
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
DecodeJSON(t, resp, pull)
assert.EqualValues(t, "master", pull.Base.Name)
@@ -195,14 +195,14 @@ func TestAPIEditPull(t *testing.T) {
Base: "feature/1",
Title: "edit a this pr",
})
- resp = session.MakeRequest(t, req, http.StatusCreated)
+ resp = MakeRequest(t, req, http.StatusCreated)
DecodeJSON(t, resp, pull)
assert.EqualValues(t, "feature/1", pull.Base.Name)
req = NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d?token=%s", owner10.Name, repo10.Name, pull.Index, token), &api.EditPullRequestOption{
Base: "not-exist",
})
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
}
func doAPIGetPullFiles(ctx APITestContext, pr *api.PullRequest, callback func(*testing.T, []*api.ChangedFile)) func(*testing.T) {
diff --git a/tests/integration/api_releases_test.go b/tests/integration/api_releases_test.go
index 0c7f5e2d5..12d2a02fb 100644
--- a/tests/integration/api_releases_test.go
+++ b/tests/integration/api_releases_test.go
@@ -1,6 +1,5 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -80,7 +79,7 @@ func createNewReleaseUsingAPI(t *testing.T, session *TestSession, token string,
IsPrerelease: false,
Target: target,
})
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var newRelease api.Release
DecodeJSON(t, resp, &newRelease)
@@ -118,7 +117,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/releases/%d?token=%s",
owner.Name, repo.Name, newRelease.ID, token)
req := NewRequest(t, "GET", urlStr)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var release api.Release
DecodeJSON(t, resp, &release)
@@ -135,7 +134,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
IsPrerelease: &release.IsPrerelease,
Target: release.Target,
})
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &newRelease)
rel := &repo_model.Release{
@@ -181,7 +180,6 @@ func TestAPIGetReleaseByTag(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
- session := loginUser(t, owner.LowerName)
tag := "v1.1"
@@ -189,7 +187,7 @@ func TestAPIGetReleaseByTag(t *testing.T) {
owner.Name, repo.Name, tag)
req := NewRequestf(t, "GET", urlStr)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var release *api.Release
DecodeJSON(t, resp, &release)
@@ -202,7 +200,7 @@ func TestAPIGetReleaseByTag(t *testing.T) {
owner.Name, repo.Name, nonexistingtag)
req = NewRequestf(t, "GET", urlStr)
- resp = session.MakeRequest(t, req, http.StatusNotFound)
+ resp = MakeRequest(t, req, http.StatusNotFound)
var err *api.APIError
DecodeJSON(t, resp, &err)
@@ -221,13 +219,13 @@ func TestAPIDeleteReleaseByTagName(t *testing.T) {
// delete release
req := NewRequestf(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/releases/tags/release-tag?token=%s", owner.Name, repo.Name, token))
- _ = session.MakeRequest(t, req, http.StatusNoContent)
+ _ = MakeRequest(t, req, http.StatusNoContent)
// make sure release is deleted
req = NewRequestf(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/releases/tags/release-tag?token=%s", owner.Name, repo.Name, token))
- _ = session.MakeRequest(t, req, http.StatusNotFound)
+ _ = MakeRequest(t, req, http.StatusNotFound)
// delete release tag too
req = NewRequestf(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/tags/release-tag?token=%s", owner.Name, repo.Name, token))
- _ = session.MakeRequest(t, req, http.StatusNoContent)
+ _ = MakeRequest(t, req, http.StatusNoContent)
}
diff --git a/tests/integration/api_repo_archive_test.go b/tests/integration/api_repo_archive_test.go
index 3707cb7c1..a3c03ba2f 100644
--- a/tests/integration/api_repo_archive_test.go
+++ b/tests/integration/api_repo_archive_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_repo_collaborator_test.go b/tests/integration/api_repo_collaborator_test.go
index 3527e1657..318c86e2c 100644
--- a/tests/integration/api_repo_collaborator_test.go
+++ b/tests/integration/api_repo_collaborator_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -28,12 +27,11 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) {
user10 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 10})
user11 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 11})
- session := loginUser(t, repo2Owner.Name)
testCtx := NewAPITestContext(t, repo2Owner.Name, repo2.Name)
t.Run("RepoOwnerShouldBeOwner", func(t *testing.T) {
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, repo2Owner.Name, testCtx.Token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var repoPermission api.RepoCollaboratorPermission
DecodeJSON(t, resp, &repoPermission)
@@ -45,7 +43,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) {
t.Run("AddUserAsCollaboratorWithReadAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeRead))
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user4.Name, testCtx.Token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var repoPermission api.RepoCollaboratorPermission
DecodeJSON(t, resp, &repoPermission)
@@ -57,7 +55,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) {
t.Run("AddUserAsCollaboratorWithWriteAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeWrite))
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user4.Name, testCtx.Token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var repoPermission api.RepoCollaboratorPermission
DecodeJSON(t, resp, &repoPermission)
@@ -69,7 +67,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) {
t.Run("AddUserAsCollaboratorWithAdminAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeAdmin))
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user4.Name, testCtx.Token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var repoPermission api.RepoCollaboratorPermission
DecodeJSON(t, resp, &repoPermission)
@@ -79,7 +77,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) {
t.Run("CollaboratorNotFound", func(t *testing.T) {
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, "non-existent-user", testCtx.Token)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
})
t.Run("CollaboratorCanQueryItsPermissions", func(t *testing.T) {
diff --git a/tests/integration/api_repo_edit_test.go b/tests/integration/api_repo_edit_test.go
index 4dfae97e4..716cebeb7 100644
--- a/tests/integration/api_repo_edit_test.go
+++ b/tests/integration/api_repo_edit_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -10,6 +9,7 @@ import (
"net/url"
"testing"
+ "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
unit_model "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/models/unittest"
@@ -28,7 +28,7 @@ func getRepoEditOptionFromRepo(repo *repo_model.Repository) *api.EditRepoOption
hasIssues := false
var internalTracker *api.InternalTracker
var externalTracker *api.ExternalTracker
- if unit, err := repo.GetUnit(unit_model.TypeIssues); err == nil {
+ if unit, err := repo.GetUnit(db.DefaultContext, unit_model.TypeIssues); err == nil {
config := unit.IssuesConfig()
hasIssues = true
internalTracker = &api.InternalTracker{
@@ -36,7 +36,7 @@ func getRepoEditOptionFromRepo(repo *repo_model.Repository) *api.EditRepoOption
AllowOnlyContributorsToTrackTime: config.AllowOnlyContributorsToTrackTime,
EnableIssueDependencies: config.EnableDependencies,
}
- } else if unit, err := repo.GetUnit(unit_model.TypeExternalTracker); err == nil {
+ } else if unit, err := repo.GetUnit(db.DefaultContext, unit_model.TypeExternalTracker); err == nil {
config := unit.ExternalTrackerConfig()
hasIssues = true
externalTracker = &api.ExternalTracker{
@@ -48,9 +48,9 @@ func getRepoEditOptionFromRepo(repo *repo_model.Repository) *api.EditRepoOption
}
hasWiki := false
var externalWiki *api.ExternalWiki
- if _, err := repo.GetUnit(unit_model.TypeWiki); err == nil {
+ if _, err := repo.GetUnit(db.DefaultContext, unit_model.TypeWiki); err == nil {
hasWiki = true
- } else if unit, err := repo.GetUnit(unit_model.TypeExternalWiki); err == nil {
+ } else if unit, err := repo.GetUnit(db.DefaultContext, unit_model.TypeExternalWiki); err == nil {
hasWiki = true
config := unit.ExternalWikiConfig()
externalWiki = &api.ExternalWiki{
@@ -64,7 +64,7 @@ func getRepoEditOptionFromRepo(repo *repo_model.Repository) *api.EditRepoOption
allowRebase := false
allowRebaseMerge := false
allowSquash := false
- if unit, err := repo.GetUnit(unit_model.TypePullRequests); err == nil {
+ if unit, err := repo.GetUnit(db.DefaultContext, unit_model.TypePullRequests); err == nil {
config := unit.PullRequestsConfig()
hasPullRequests = true
ignoreWhitespaceConflicts = config.IgnoreWhitespaceConflicts
@@ -150,14 +150,13 @@ func TestAPIRepoEdit(t *testing.T) {
// Get user4's token
session = loginUser(t, user4.Name)
token4 := getTokenForLoggedInUser(t, session)
- session = emptyTestSession(t)
// Test editing a repo1 which user2 owns, changing name and many properties
origRepoEditOption := getRepoEditOptionFromRepo(repo1)
repoEditOption := getNewRepoEditOption(origRepoEditOption)
url := fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, repo1.Name, token2)
req := NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var repo api.Repository
DecodeJSON(t, resp, &repo)
assert.NotNil(t, repo)
@@ -188,7 +187,7 @@ func TestAPIRepoEdit(t *testing.T) {
repoEditOption.ExternalWiki = nil
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, *repoEditOption.Name, token2)
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &repo)
assert.NotNil(t, repo)
// check repo1 was written to database
@@ -210,7 +209,7 @@ func TestAPIRepoEdit(t *testing.T) {
ExternalWikiURL: "http://www.somewebsite.com",
}
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &repo)
assert.NotNil(t, repo)
// check repo1 was written to database
@@ -224,7 +223,7 @@ func TestAPIRepoEdit(t *testing.T) {
repoEditOption.ExternalTracker.ExternalTrackerStyle = "regexp"
repoEditOption.ExternalTracker.ExternalTrackerRegexpPattern = `(\d+)`
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &repo)
assert.NotNil(t, repo)
repo1edited = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
@@ -235,15 +234,15 @@ func TestAPIRepoEdit(t *testing.T) {
// Do some tests with invalid URL for external tracker and wiki
repoEditOption.ExternalTracker.ExternalTrackerURL = "htp://www.somewebsite.com"
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
repoEditOption.ExternalTracker.ExternalTrackerURL = "http://www.somewebsite.com"
repoEditOption.ExternalTracker.ExternalTrackerFormat = "http://www.somewebsite.com/{user/{repo}?issue={index}"
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
repoEditOption.ExternalTracker.ExternalTrackerFormat = "http://www.somewebsite.com/{user}/{repo}?issue={index}"
repoEditOption.ExternalWiki.ExternalWikiURL = "htp://www.somewebsite.com"
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
// Test small repo change through API with issue and wiki option not set; They shall not be touched.
*repoEditOption.Description = "small change"
@@ -252,7 +251,7 @@ func TestAPIRepoEdit(t *testing.T) {
repoEditOption.HasWiki = nil
repoEditOption.ExternalWiki = nil
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &repo)
assert.NotNil(t, repo)
// check repo1 was written to database
@@ -267,38 +266,38 @@ func TestAPIRepoEdit(t *testing.T) {
// reset repo in db
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, *repoEditOption.Name, token2)
req = NewRequestWithJSON(t, "PATCH", url, &origRepoEditOption)
- _ = session.MakeRequest(t, req, http.StatusOK)
+ _ = MakeRequest(t, req, http.StatusOK)
// Test editing a non-existing repo
name := "repodoesnotexist"
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, name, token2)
req = NewRequestWithJSON(t, "PATCH", url, &api.EditRepoOption{Name: &name})
- _ = session.MakeRequest(t, req, http.StatusNotFound)
+ _ = MakeRequest(t, req, http.StatusNotFound)
// Test editing repo16 by user4 who does not have write access
origRepoEditOption = getRepoEditOptionFromRepo(repo16)
repoEditOption = getNewRepoEditOption(origRepoEditOption)
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, repo16.Name, token4)
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Tests a repo with no token given so will fail
origRepoEditOption = getRepoEditOptionFromRepo(repo16)
repoEditOption = getNewRepoEditOption(origRepoEditOption)
url = fmt.Sprintf("/api/v1/repos/%s/%s", user2.Name, repo16.Name)
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- _ = session.MakeRequest(t, req, http.StatusNotFound)
+ _ = MakeRequest(t, req, http.StatusNotFound)
// Test using access token for a private repo that the user of the token owns
origRepoEditOption = getRepoEditOptionFromRepo(repo16)
repoEditOption = getNewRepoEditOption(origRepoEditOption)
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, repo16.Name, token2)
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- _ = session.MakeRequest(t, req, http.StatusOK)
+ _ = MakeRequest(t, req, http.StatusOK)
// reset repo in db
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, *repoEditOption.Name, token2)
req = NewRequestWithJSON(t, "PATCH", url, &origRepoEditOption)
- _ = session.MakeRequest(t, req, http.StatusOK)
+ _ = MakeRequest(t, req, http.StatusOK)
// Test making a repo public that is private
repo16 = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 16})
@@ -308,13 +307,13 @@ func TestAPIRepoEdit(t *testing.T) {
}
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, repo16.Name, token2)
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- _ = session.MakeRequest(t, req, http.StatusOK)
+ _ = MakeRequest(t, req, http.StatusOK)
repo16 = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 16})
assert.False(t, repo16.IsPrivate)
// Make it private again
repoEditOption.Private = &bTrue
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- _ = session.MakeRequest(t, req, http.StatusOK)
+ _ = MakeRequest(t, req, http.StatusOK)
// Test to change empty repo
assert.False(t, repo15.IsArchived)
@@ -322,37 +321,37 @@ func TestAPIRepoEdit(t *testing.T) {
req = NewRequestWithJSON(t, "PATCH", url, &api.EditRepoOption{
Archived: &bTrue,
})
- _ = session.MakeRequest(t, req, http.StatusOK)
+ _ = MakeRequest(t, req, http.StatusOK)
repo15 = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 15})
assert.True(t, repo15.IsArchived)
req = NewRequestWithJSON(t, "PATCH", url, &api.EditRepoOption{
Archived: &bFalse,
})
- _ = session.MakeRequest(t, req, http.StatusOK)
+ _ = MakeRequest(t, req, http.StatusOK)
// Test using org repo "user3/repo3" where user2 is a collaborator
origRepoEditOption = getRepoEditOptionFromRepo(repo3)
repoEditOption = getNewRepoEditOption(origRepoEditOption)
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user3.Name, repo3.Name, token2)
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// reset repo in db
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user3.Name, *repoEditOption.Name, token2)
req = NewRequestWithJSON(t, "PATCH", url, &origRepoEditOption)
- _ = session.MakeRequest(t, req, http.StatusOK)
+ _ = MakeRequest(t, req, http.StatusOK)
// Test using org repo "user3/repo3" with no user token
origRepoEditOption = getRepoEditOptionFromRepo(repo3)
repoEditOption = getNewRepoEditOption(origRepoEditOption)
url = fmt.Sprintf("/api/v1/repos/%s/%s", user3.Name, repo3.Name)
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test using repo "user2/repo1" where user4 is a NOT collaborator
origRepoEditOption = getRepoEditOptionFromRepo(repo1)
repoEditOption = getNewRepoEditOption(origRepoEditOption)
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, repo1.Name, token4)
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
})
}
diff --git a/tests/integration/api_repo_file_create_test.go b/tests/integration/api_repo_file_create_test.go
index f03efaa0e..476441dbb 100644
--- a/tests/integration/api_repo_file_create_test.go
+++ b/tests/integration/api_repo_file_create_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -155,7 +154,6 @@ func TestAPICreateFile(t *testing.T) {
// Get user4's token
session = loginUser(t, user4.Name)
token4 := getTokenForLoggedInUser(t, session)
- session = emptyTestSession(t)
// Test creating a file in repo1 which user2 owns, try both with branch and empty branch
for _, branch := range [...]string{
@@ -168,7 +166,7 @@ func TestAPICreateFile(t *testing.T) {
treePath := fmt.Sprintf("new/file%d.txt", fileID)
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req := NewRequestWithJSON(t, "POST", url, &createFileOptions)
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath())
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
@@ -195,7 +193,7 @@ func TestAPICreateFile(t *testing.T) {
treePath := fmt.Sprintf("new/file%d.txt", fileID)
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req := NewRequestWithJSON(t, "POST", url, &createFileOptions)
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var fileResponse api.FileResponse
DecodeJSON(t, resp, &fileResponse)
expectedSHA := "a635aa942442ddfdba07468cf9661c08fbdf0ebf"
@@ -213,7 +211,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- resp = session.MakeRequest(t, req, http.StatusCreated)
+ resp = MakeRequest(t, req, http.StatusCreated)
DecodeJSON(t, resp, &fileResponse)
expectedMessage := "Add '" + treePath + "'\n"
assert.EqualValues(t, expectedMessage, fileResponse.Commit.Message)
@@ -223,7 +221,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = "README.md"
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- resp = session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ resp = MakeRequest(t, req, http.StatusUnprocessableEntity)
expectedAPIError := context.APIError{
Message: "repository file already exists [path: " + treePath + "]",
URL: setting.API.SwaggerURL,
@@ -238,7 +236,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token4)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Tests a repo with no token given so will fail
createFileOptions = getCreateFileOptions()
@@ -246,7 +244,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test using access token for a private repo that the user of the token owns
createFileOptions = getCreateFileOptions()
@@ -254,7 +252,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token2)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- session.MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusCreated)
// Test using org repo "user3/repo3" where user2 is a collaborator
createFileOptions = getCreateFileOptions()
@@ -262,7 +260,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user3.Name, repo3.Name, treePath, token2)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- session.MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusCreated)
// Test using org repo "user3/repo3" with no user token
createFileOptions = getCreateFileOptions()
@@ -270,7 +268,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user3.Name, repo3.Name, treePath)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test using repo "user2/repo1" where user4 is a NOT collaborator
createFileOptions = getCreateFileOptions()
@@ -278,7 +276,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token4)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
// Test creating a file in an empty repository
doAPICreateRepository(NewAPITestContext(t, "user2", "empty-repo"), true)(t)
@@ -287,7 +285,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, "empty-repo", treePath, token2)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- resp = session.MakeRequest(t, req, http.StatusCreated)
+ resp = MakeRequest(t, req, http.StatusCreated)
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "empty-repo"}) // public repo
gitRepo, _ := git.OpenRepository(stdCtx.Background(), emptyRepo.RepoPath())
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
diff --git a/tests/integration/api_repo_file_delete_test.go b/tests/integration/api_repo_file_delete_test.go
index 2c8b1e381..196d3208f 100644
--- a/tests/integration/api_repo_file_delete_test.go
+++ b/tests/integration/api_repo_file_delete_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -53,7 +52,6 @@ func TestAPIDeleteFile(t *testing.T) {
// Get user4's token
session = loginUser(t, user4.Name)
token4 := getTokenForLoggedInUser(t, session)
- session = emptyTestSession(t)
// Test deleting a file in repo1 which user2 owns, try both with branch and empty branch
for _, branch := range [...]string{
@@ -67,7 +65,7 @@ func TestAPIDeleteFile(t *testing.T) {
deleteFileOptions.BranchName = branch
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req := NewRequestWithJSON(t, "DELETE", url, &deleteFileOptions)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var fileResponse api.FileResponse
DecodeJSON(t, resp, &fileResponse)
assert.NotNil(t, fileResponse)
@@ -83,7 +81,7 @@ func TestAPIDeleteFile(t *testing.T) {
deleteFileOptions.NewBranchName = "new_branch"
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req := NewRequestWithJSON(t, "DELETE", url, &deleteFileOptions)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var fileResponse api.FileResponse
DecodeJSON(t, resp, &fileResponse)
assert.NotNil(t, fileResponse)
@@ -98,7 +96,7 @@ func TestAPIDeleteFile(t *testing.T) {
deleteFileOptions.Message = ""
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req = NewRequestWithJSON(t, "DELETE", url, &deleteFileOptions)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fileResponse)
expectedMessage := "Delete '" + treePath + "'\n"
assert.EqualValues(t, expectedMessage, fileResponse.Commit.Message)
@@ -111,7 +109,7 @@ func TestAPIDeleteFile(t *testing.T) {
deleteFileOptions.SHA = "badsha"
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req = NewRequestWithJSON(t, "DELETE", url, &deleteFileOptions)
- session.MakeRequest(t, req, http.StatusBadRequest)
+ MakeRequest(t, req, http.StatusBadRequest)
// Test creating a file in repo16 by user4 who does not have write access
fileID++
@@ -120,7 +118,7 @@ func TestAPIDeleteFile(t *testing.T) {
deleteFileOptions = getDeleteFileOptions()
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token4)
req = NewRequestWithJSON(t, "DELETE", url, &deleteFileOptions)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Tests a repo with no token given so will fail
fileID++
@@ -129,7 +127,7 @@ func TestAPIDeleteFile(t *testing.T) {
deleteFileOptions = getDeleteFileOptions()
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath)
req = NewRequestWithJSON(t, "DELETE", url, &deleteFileOptions)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test using access token for a private repo that the user of the token owns
fileID++
@@ -138,7 +136,7 @@ func TestAPIDeleteFile(t *testing.T) {
deleteFileOptions = getDeleteFileOptions()
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token2)
req = NewRequestWithJSON(t, "DELETE", url, &deleteFileOptions)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// Test using org repo "user3/repo3" where user2 is a collaborator
fileID++
@@ -147,7 +145,7 @@ func TestAPIDeleteFile(t *testing.T) {
deleteFileOptions = getDeleteFileOptions()
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user3.Name, repo3.Name, treePath, token2)
req = NewRequestWithJSON(t, "DELETE", url, &deleteFileOptions)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// Test using org repo "user3/repo3" with no user token
fileID++
@@ -156,7 +154,7 @@ func TestAPIDeleteFile(t *testing.T) {
deleteFileOptions = getDeleteFileOptions()
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user3.Name, repo3.Name, treePath)
req = NewRequestWithJSON(t, "DELETE", url, &deleteFileOptions)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test using repo "user2/repo1" where user4 is a NOT collaborator
fileID++
@@ -165,6 +163,6 @@ func TestAPIDeleteFile(t *testing.T) {
deleteFileOptions = getDeleteFileOptions()
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token4)
req = NewRequestWithJSON(t, "DELETE", url, &deleteFileOptions)
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
})
}
diff --git a/tests/integration/api_repo_file_get_test.go b/tests/integration/api_repo_file_get_test.go
index cca72c2b3..4fca55c93 100644
--- a/tests/integration/api_repo_file_get_test.go
+++ b/tests/integration/api_repo_file_get_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_repo_file_helpers.go b/tests/integration/api_repo_file_helpers.go
index 298bae95c..d773bcd62 100644
--- a/tests/integration/api_repo_file_helpers.go
+++ b/tests/integration/api_repo_file_helpers.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_repo_file_update_test.go b/tests/integration/api_repo_file_update_test.go
index a3be67ad8..6dd06b712 100644
--- a/tests/integration/api_repo_file_update_test.go
+++ b/tests/integration/api_repo_file_update_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -121,7 +120,6 @@ func TestAPIUpdateFile(t *testing.T) {
// Get user4's token
session = loginUser(t, user4.Name)
token4 := getTokenForLoggedInUser(t, session)
- session = emptyTestSession(t)
// Test updating a file in repo1 which user2 owns, try both with branch and empty branch
for _, branch := range [...]string{
@@ -135,7 +133,7 @@ func TestAPIUpdateFile(t *testing.T) {
updateFileOptions.BranchName = branch
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req := NewRequestWithJSON(t, "PUT", url, &updateFileOptions)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath())
commitID, _ := gitRepo.GetBranchCommitID(updateFileOptions.NewBranchName)
lasCommit, _ := gitRepo.GetCommitByPath(treePath)
@@ -159,7 +157,7 @@ func TestAPIUpdateFile(t *testing.T) {
createFile(user2, repo1, treePath)
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req := NewRequestWithJSON(t, "PUT", url, &updateFileOptions)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var fileResponse api.FileResponse
DecodeJSON(t, resp, &fileResponse)
expectedSHA := "08bd14b2e2852529157324de9c226b3364e76136"
@@ -180,7 +178,7 @@ func TestAPIUpdateFile(t *testing.T) {
treePath = "rename/" + treePath
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req = NewRequestWithJSON(t, "PUT", url, &updateFileOptions)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fileResponse)
expectedSHA = "08bd14b2e2852529157324de9c226b3364e76136"
expectedHTMLURL = fmt.Sprintf(setting.AppURL+"user2/repo1/src/branch/master/rename/update/file%d.txt", fileID)
@@ -198,7 +196,7 @@ func TestAPIUpdateFile(t *testing.T) {
createFile(user2, repo1, treePath)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req = NewRequestWithJSON(t, "PUT", url, &updateFileOptions)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fileResponse)
expectedMessage := "Update '" + treePath + "'\n"
assert.EqualValues(t, expectedMessage, fileResponse.Commit.Message)
@@ -212,7 +210,7 @@ func TestAPIUpdateFile(t *testing.T) {
updateFileOptions.SHA = "badsha"
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req = NewRequestWithJSON(t, "PUT", url, &updateFileOptions)
- resp = session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ resp = MakeRequest(t, req, http.StatusUnprocessableEntity)
expectedAPIError := context.APIError{
Message: "sha does not match [given: " + updateFileOptions.SHA + ", expected: " + correctSHA + "]",
URL: setting.API.SwaggerURL,
@@ -228,7 +226,7 @@ func TestAPIUpdateFile(t *testing.T) {
updateFileOptions = getUpdateFileOptions()
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token4)
req = NewRequestWithJSON(t, "PUT", url, &updateFileOptions)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Tests a repo with no token given so will fail
fileID++
@@ -237,7 +235,7 @@ func TestAPIUpdateFile(t *testing.T) {
updateFileOptions = getUpdateFileOptions()
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath)
req = NewRequestWithJSON(t, "PUT", url, &updateFileOptions)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test using access token for a private repo that the user of the token owns
fileID++
@@ -246,7 +244,7 @@ func TestAPIUpdateFile(t *testing.T) {
updateFileOptions = getUpdateFileOptions()
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token2)
req = NewRequestWithJSON(t, "PUT", url, &updateFileOptions)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// Test using org repo "user3/repo3" where user2 is a collaborator
fileID++
@@ -255,7 +253,7 @@ func TestAPIUpdateFile(t *testing.T) {
updateFileOptions = getUpdateFileOptions()
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user3.Name, repo3.Name, treePath, token2)
req = NewRequestWithJSON(t, "PUT", url, &updateFileOptions)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// Test using org repo "user3/repo3" with no user token
fileID++
@@ -264,7 +262,7 @@ func TestAPIUpdateFile(t *testing.T) {
updateFileOptions = getUpdateFileOptions()
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user3.Name, repo3.Name, treePath)
req = NewRequestWithJSON(t, "PUT", url, &updateFileOptions)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test using repo "user2/repo1" where user4 is a NOT collaborator
fileID++
@@ -273,6 +271,6 @@ func TestAPIUpdateFile(t *testing.T) {
updateFileOptions = getUpdateFileOptions()
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token4)
req = NewRequestWithJSON(t, "PUT", url, &updateFileOptions)
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
})
}
diff --git a/tests/integration/api_repo_get_contents_list_test.go b/tests/integration/api_repo_get_contents_list_test.go
index 4f2f5cb52..2c7b44120 100644
--- a/tests/integration/api_repo_get_contents_list_test.go
+++ b/tests/integration/api_repo_get_contents_list_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -69,7 +68,6 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
// Get user4's token
session = loginUser(t, user4.Name)
token4 := getTokenForLoggedInUser(t, session)
- session = emptyTestSession(t)
// Make a new branch in repo1
newBranch := "test_branch"
@@ -91,7 +89,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
ref := repo1.DefaultBranch
refType := "branch"
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var contentsListResponse []*api.ContentsResponse
DecodeJSON(t, resp, &contentsListResponse)
assert.NotNil(t, contentsListResponse)
@@ -103,7 +101,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
// No ref
refType = "branch"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsListResponse)
assert.NotNil(t, contentsListResponse)
@@ -114,7 +112,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
ref = newBranch
refType = "branch"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsListResponse)
assert.NotNil(t, contentsListResponse)
branchCommit, err := gitRepo.GetBranchCommit(ref)
@@ -128,7 +126,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
ref = newTag
refType = "tag"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsListResponse)
assert.NotNil(t, contentsListResponse)
tagCommit, err := gitRepo.GetTagCommit(ref)
@@ -142,7 +140,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
ref = commitID
refType = "commit"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsListResponse)
assert.NotNil(t, contentsListResponse)
expectedContentsListResponse = getExpectedContentsListResponseForContents(ref, refType, commitID)
@@ -151,17 +149,17 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
// Test file contents a file with a bad ref
ref = "badref"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test accessing private ref with user token that does not have access - should fail
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token4)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test access private ref of owner of token
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/readme.md?token=%s", user2.Name, repo16.Name, token2)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// Test access of org user3 private repo file by owner user2
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?token=%s", user3.Name, repo3.Name, treePath, token2)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
}
diff --git a/tests/integration/api_repo_get_contents_test.go b/tests/integration/api_repo_get_contents_test.go
index dddc316e1..f7d9c716a 100644
--- a/tests/integration/api_repo_get_contents_test.go
+++ b/tests/integration/api_repo_get_contents_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -70,7 +69,6 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
// Get user4's token
session = loginUser(t, user4.Name)
token4 := getTokenForLoggedInUser(t, session)
- session = emptyTestSession(t)
// Make a new branch in repo1
newBranch := "test_branch"
@@ -93,7 +91,7 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
ref := repo1.DefaultBranch
refType := "branch"
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var contentsResponse api.ContentsResponse
DecodeJSON(t, resp, &contentsResponse)
assert.NotNil(t, contentsResponse)
@@ -104,7 +102,7 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
// No ref
refType = "branch"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsResponse)
assert.NotNil(t, contentsResponse)
expectedContentsResponse = getExpectedContentsResponseForContents(repo1.DefaultBranch, refType, lastCommit.ID.String())
@@ -114,7 +112,7 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
ref = newBranch
refType = "branch"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsResponse)
assert.NotNil(t, contentsResponse)
branchCommit, _ := gitRepo.GetBranchCommit(ref)
@@ -126,7 +124,7 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
ref = newTag
refType = "tag"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsResponse)
assert.NotNil(t, contentsResponse)
tagCommit, _ := gitRepo.GetTagCommit(ref)
@@ -138,7 +136,7 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
ref = commitID
refType = "commit"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsResponse)
assert.NotNil(t, contentsResponse)
expectedContentsResponse = getExpectedContentsResponseForContents(ref, refType, commitID)
@@ -147,17 +145,17 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
// Test file contents a file with a bad ref
ref = "badref"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test accessing private ref with user token that does not have access - should fail
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token4)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test access private ref of owner of token
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/readme.md?token=%s", user2.Name, repo16.Name, token2)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// Test access of org user3 private repo file by owner user2
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?token=%s", user3.Name, repo3.Name, treePath, token2)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
}
diff --git a/tests/integration/api_repo_git_blobs_test.go b/tests/integration/api_repo_git_blobs_test.go
index cb5116c74..02652e593 100644
--- a/tests/integration/api_repo_git_blobs_test.go
+++ b/tests/integration/api_repo_git_blobs_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -33,11 +32,10 @@ func TestAPIReposGitBlobs(t *testing.T) {
// Login as User2.
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session)
- session = emptyTestSession(t) // don't want anyone logged in for this
// Test a public repo that anyone can GET the blob of
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s", user2.Name, repo1.Name, repo1ReadmeSHA)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var gitBlobResponse api.GitBlobResponse
DecodeJSON(t, resp, &gitBlobResponse)
assert.NotNil(t, gitBlobResponse)
@@ -46,34 +44,33 @@ func TestAPIReposGitBlobs(t *testing.T) {
// Tests a private repo with no token so will fail
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s", user2.Name, repo16.Name, repo16ReadmeSHA)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test using access token for a private repo that the user of the token owns
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s?token=%s", user2.Name, repo16.Name, repo16ReadmeSHA, token)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// Test using bad sha
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s", user2.Name, repo1.Name, badSHA)
- session.MakeRequest(t, req, http.StatusBadRequest)
+ MakeRequest(t, req, http.StatusBadRequest)
// Test using org repo "user3/repo3" where user2 is a collaborator
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s?token=%s", user3.Name, repo3.Name, repo3ReadmeSHA, token)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// Test using org repo "user3/repo3" where user2 is a collaborator
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s?token=%s", user3.Name, repo3.Name, repo3ReadmeSHA, token)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// Test using org repo "user3/repo3" with no user token
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s", user3.Name, repo3ReadmeSHA, repo3.Name)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Login as User4.
session = loginUser(t, user4.Name)
token4 := getTokenForLoggedInUser(t, session)
- session = emptyTestSession(t) // don't want anyone logged in for this
// Test using org repo "user3/repo3" where user4 is a NOT collaborator
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/d56a3073c1dbb7b15963110a049d50cdb5db99fc?access=%s", user3.Name, repo3.Name, token4)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
}
diff --git a/tests/integration/api_repo_git_commits_test.go b/tests/integration/api_repo_git_commits_test.go
index 99f83f943..17750a279 100644
--- a/tests/integration/api_repo_git_commits_test.go
+++ b/tests/integration/api_repo_git_commits_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -33,13 +32,13 @@ func TestAPIReposGitCommits(t *testing.T) {
// check invalid requests
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/commits/12345?token="+token, user.Name)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/commits/..?token="+token, user.Name)
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/commits/branch-not-exist?token="+token, user.Name)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
for _, ref := range [...]string{
"master", // Branch
@@ -48,7 +47,7 @@ func TestAPIReposGitCommits(t *testing.T) {
"65f1bf27bc3bf70f64657658635e66094edbcb4d", // full sha
} {
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/commits/%s?token="+token, user.Name, ref)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
}
}
@@ -61,7 +60,7 @@ func TestAPIReposGitCommitList(t *testing.T) {
// Test getting commits (Page 1)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo16/commits?token="+token, user.Name)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiData []api.Commit
DecodeJSON(t, resp, &apiData)
@@ -84,7 +83,7 @@ func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
// Test getting commits (Page=2)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo16/commits?token="+token+"&page=2", user.Name)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiData []api.Commit
DecodeJSON(t, resp, &apiData)
@@ -101,7 +100,7 @@ func TestAPIReposGitCommitListDifferentBranch(t *testing.T) {
// Test getting commits (Page=1, Branch=good-sign)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo16/commits?token="+token+"&sha=good-sign", user.Name)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiData []api.Commit
DecodeJSON(t, resp, &apiData)
@@ -120,14 +119,14 @@ func TestDownloadCommitDiffOrPatch(t *testing.T) {
// Test getting diff
reqDiff := NewRequestf(t, "GET", "/api/v1/repos/%s/repo16/git/commits/f27c2b2b03dcab38beaf89b0ab4ff61f6de63441.diff?token="+token, user.Name)
- resp := session.MakeRequest(t, reqDiff, http.StatusOK)
+ resp := MakeRequest(t, reqDiff, http.StatusOK)
assert.EqualValues(t,
"commit f27c2b2b03dcab38beaf89b0ab4ff61f6de63441\nAuthor: User2 <user2@example.com>\nDate: Sun Aug 6 19:55:01 2017 +0200\n\n good signed commit\n\ndiff --git a/readme.md b/readme.md\nnew file mode 100644\nindex 0000000..458121c\n--- /dev/null\n+++ b/readme.md\n@@ -0,0 +1 @@\n+good sign\n",
resp.Body.String())
// Test getting patch
reqPatch := NewRequestf(t, "GET", "/api/v1/repos/%s/repo16/git/commits/f27c2b2b03dcab38beaf89b0ab4ff61f6de63441.patch?token="+token, user.Name)
- resp = session.MakeRequest(t, reqPatch, http.StatusOK)
+ resp = MakeRequest(t, reqPatch, http.StatusOK)
assert.EqualValues(t,
"From f27c2b2b03dcab38beaf89b0ab4ff61f6de63441 Mon Sep 17 00:00:00 2001\nFrom: User2 <user2@example.com>\nDate: Sun, 6 Aug 2017 19:55:01 +0200\nSubject: [PATCH] good signed commit\n\n---\n readme.md | 1 +\n 1 file changed, 1 insertion(+)\n create mode 100644 readme.md\n\ndiff --git a/readme.md b/readme.md\nnew file mode 100644\nindex 0000000..458121c\n--- /dev/null\n+++ b/readme.md\n@@ -0,0 +1 @@\n+good sign\n",
resp.Body.String())
@@ -141,7 +140,7 @@ func TestGetFileHistory(t *testing.T) {
token := getTokenForLoggedInUser(t, session)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo16/commits?path=readme.md&token="+token+"&sha=good-sign", user.Name)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiData []api.Commit
DecodeJSON(t, resp, &apiData)
diff --git a/tests/integration/api_repo_git_hook_test.go b/tests/integration/api_repo_git_hook_test.go
index a6c4f91d4..a3bbe9bba 100644
--- a/tests/integration/api_repo_git_hook_test.go
+++ b/tests/integration/api_repo_git_hook_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_repo_git_notes_test.go b/tests/integration/api_repo_git_notes_test.go
index 713c7599c..1448f4057 100644
--- a/tests/integration/api_repo_git_notes_test.go
+++ b/tests/integration/api_repo_git_notes_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -25,14 +24,14 @@ func TestAPIReposGitNotes(t *testing.T) {
// check invalid requests
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/notes/12345?token=%s", user.Name, token)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/notes/..?token=%s", user.Name, token)
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
// check valid request
req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/notes/65f1bf27bc3bf70f64657658635e66094edbcb4d?token=%s", user.Name, token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiData api.Note
DecodeJSON(t, resp, &apiData)
diff --git a/tests/integration/api_repo_git_ref_test.go b/tests/integration/api_repo_git_ref_test.go
index e8fc47f8d..aac01ca9a 100644
--- a/tests/integration/api_repo_git_ref_test.go
+++ b/tests/integration/api_repo_git_ref_test.go
@@ -1,6 +1,5 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -25,12 +24,12 @@ func TestAPIReposGitRefs(t *testing.T) {
"refs/tags/v1.1", // Tag
} {
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/%s?token="+token, user.Name, ref)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
}
// Test getting all refs
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/refs?token="+token, user.Name)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// Test getting non-existent refs
req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/refs/heads/unknown?token="+token, user.Name)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
}
diff --git a/tests/integration/api_repo_git_tags_test.go b/tests/integration/api_repo_git_tags_test.go
index 3357f9568..146b4b74b 100644
--- a/tests/integration/api_repo_git_tags_test.go
+++ b/tests/integration/api_repo_git_tags_test.go
@@ -1,6 +1,5 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -46,7 +45,7 @@ func TestAPIGitTags(t *testing.T) {
// SHOULD work for annotated tags
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/tags/%s?token=%s", user.Name, repo.Name, aTag.ID.String(), token)
- res := session.MakeRequest(t, req, http.StatusOK)
+ res := MakeRequest(t, req, http.StatusOK)
var tag *api.AnnotatedTag
DecodeJSON(t, res, &tag)
@@ -61,7 +60,7 @@ func TestAPIGitTags(t *testing.T) {
// Should NOT work for lightweight tags
badReq := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/tags/%s?token=%s", user.Name, repo.Name, commit.ID.String(), token)
- session.MakeRequest(t, badReq, http.StatusBadRequest)
+ MakeRequest(t, badReq, http.StatusBadRequest)
}
func TestAPIDeleteTagByName(t *testing.T) {
@@ -76,7 +75,7 @@ func TestAPIDeleteTagByName(t *testing.T) {
owner.Name, repo.Name, token)
req := NewRequestf(t, http.MethodDelete, urlStr)
- _ = session.MakeRequest(t, req, http.StatusNoContent)
+ _ = MakeRequest(t, req, http.StatusNoContent)
// Make sure that actual releases can't be deleted outright
createNewReleaseUsingAPI(t, session, token, owner, repo, "release-tag", "", "Release Tag", "test")
@@ -84,5 +83,5 @@ func TestAPIDeleteTagByName(t *testing.T) {
owner.Name, repo.Name, token)
req = NewRequestf(t, http.MethodDelete, urlStr)
- _ = session.MakeRequest(t, req, http.StatusConflict)
+ _ = MakeRequest(t, req, http.StatusConflict)
}
diff --git a/tests/integration/api_repo_git_trees_test.go b/tests/integration/api_repo_git_trees_test.go
index 385fec12b..d1d49e462 100644
--- a/tests/integration/api_repo_git_trees_test.go
+++ b/tests/integration/api_repo_git_trees_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -30,7 +29,6 @@ func TestAPIReposGitTrees(t *testing.T) {
// Login as User2.
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session)
- session = emptyTestSession(t) // don't want anyone logged in for this
// Test a public repo that anyone can GET the tree of
for _, ref := range [...]string{
@@ -38,7 +36,7 @@ func TestAPIReposGitTrees(t *testing.T) {
repo1TreeSHA, // Tree SHA
} {
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/trees/%s", user2.Name, repo1.Name, ref)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
}
// Tests a private repo with no token so will fail
@@ -47,31 +45,30 @@ func TestAPIReposGitTrees(t *testing.T) {
repo1TreeSHA, // Tag
} {
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/trees/%s", user2.Name, repo16.Name, ref)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
}
// Test using access token for a private repo that the user of the token owns
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/trees/%s?token=%s", user2.Name, repo16.Name, repo16TreeSHA, token)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// Test using bad sha
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/trees/%s", user2.Name, repo1.Name, badSHA)
- session.MakeRequest(t, req, http.StatusBadRequest)
+ MakeRequest(t, req, http.StatusBadRequest)
// Test using org repo "user3/repo3" where user2 is a collaborator
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/trees/%s?token=%s", user3.Name, repo3.Name, repo3TreeSHA, token)
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
// Test using org repo "user3/repo3" with no user token
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/trees/%s", user3.Name, repo3TreeSHA, repo3.Name)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Login as User4.
session = loginUser(t, user4.Name)
token4 := getTokenForLoggedInUser(t, session)
- session = emptyTestSession(t) // don't want anyone logged in for this
// Test using org repo "user3/repo3" where user4 is a NOT collaborator
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/trees/d56a3073c1dbb7b15963110a049d50cdb5db99fc?access=%s", user3.Name, repo3.Name, token4)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
}
diff --git a/tests/integration/api_repo_hook_test.go b/tests/integration/api_repo_hook_test.go
index e503834e1..cf080575d 100644
--- a/tests/integration/api_repo_hook_test.go
+++ b/tests/integration/api_repo_hook_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_repo_languages_test.go b/tests/integration/api_repo_languages_test.go
index 98373fb6b..1045aef57 100644
--- a/tests/integration/api_repo_languages_test.go
+++ b/tests/integration/api_repo_languages_test.go
@@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -40,7 +39,7 @@ func TestRepoLanguages(t *testing.T) {
// Save new file to master branch
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/languages")
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
var languages map[string]int64
DecodeJSON(t, resp, &languages)
diff --git a/tests/integration/api_repo_lfs_locks_test.go b/tests/integration/api_repo_lfs_locks_test.go
index 2186933bd..5aa139694 100644
--- a/tests/integration/api_repo_lfs_locks_test.go
+++ b/tests/integration/api_repo_lfs_locks_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_repo_lfs_migrate_test.go b/tests/integration/api_repo_lfs_migrate_test.go
index d2edf67e8..50d0c5966 100644
--- a/tests/integration/api_repo_lfs_migrate_test.go
+++ b/tests/integration/api_repo_lfs_migrate_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_repo_lfs_test.go b/tests/integration/api_repo_lfs_test.go
index 440dd04a8..73599242d 100644
--- a/tests/integration/api_repo_lfs_test.go
+++ b/tests/integration/api_repo_lfs_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -12,6 +11,7 @@ import (
"strings"
"testing"
+ "code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
@@ -62,7 +62,7 @@ func createLFSTestRepository(t *testing.T, name string) *repo_model.Repository {
ctx := NewAPITestContext(t, "user2", "lfs-"+name+"-repo")
t.Run("CreateRepo", doAPICreateRepository(ctx, false))
- repo, err := repo_model.GetRepositoryByOwnerAndName("user2", "lfs-"+name+"-repo")
+ repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "lfs-"+name+"-repo")
assert.NoError(t, err)
return repo
diff --git a/tests/integration/api_repo_raw_test.go b/tests/integration/api_repo_raw_test.go
index 9793e12b4..a35f1285b 100644
--- a/tests/integration/api_repo_raw_test.go
+++ b/tests/integration/api_repo_raw_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -28,11 +27,11 @@ func TestAPIReposRaw(t *testing.T) {
"65f1bf27bc3bf70f64657658635e66094edbcb4d", // Commit
} {
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/raw/%s/README.md?token="+token, user.Name, ref)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
assert.EqualValues(t, "file", resp.Header().Get("x-gitea-object-type"))
}
// Test default branch
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/raw/README.md?token="+token, user.Name)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
assert.EqualValues(t, "file", resp.Header().Get("x-gitea-object-type"))
}
diff --git a/tests/integration/api_repo_tags_test.go b/tests/integration/api_repo_tags_test.go
index 5d3a209a7..6c7ab7971 100644
--- a/tests/integration/api_repo_tags_test.go
+++ b/tests/integration/api_repo_tags_test.go
@@ -1,6 +1,5 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -28,7 +27,7 @@ func TestAPIRepoTags(t *testing.T) {
repoName := "repo1"
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/tags?token=%s", user.Name, repoName, token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var tags []*api.Tag
DecodeJSON(t, resp, &tags)
@@ -42,7 +41,7 @@ func TestAPIRepoTags(t *testing.T) {
assert.Equal(t, setting.AppURL+"user2/repo1/archive/v1.1.tar.gz", tags[0].TarballURL)
newTag := createNewTagUsingAPI(t, session, token, user.Name, repoName, "gitea/22", "", "nice!\nand some text")
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &tags)
assert.Len(t, tags, 2)
for _, tag := range tags {
@@ -56,17 +55,17 @@ func TestAPIRepoTags(t *testing.T) {
// get created tag
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/tags/%s?token=%s", user.Name, repoName, newTag.Name, token)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
var tag *api.Tag
DecodeJSON(t, resp, &tag)
assert.EqualValues(t, newTag, tag)
// delete tag
delReq := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/tags/%s?token=%s", user.Name, repoName, newTag.Name, token)
- session.MakeRequest(t, delReq, http.StatusNoContent)
+ MakeRequest(t, delReq, http.StatusNoContent)
// check if it's gone
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
}
func createNewTagUsingAPI(t *testing.T, session *TestSession, token, ownerName, repoName, name, target, msg string) *api.Tag {
@@ -76,7 +75,7 @@ func createNewTagUsingAPI(t *testing.T, session *TestSession, token, ownerName,
Message: msg,
Target: target,
})
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var respObj api.Tag
DecodeJSON(t, resp, &respObj)
diff --git a/tests/integration/api_repo_teams_test.go b/tests/integration/api_repo_teams_test.go
index 1e476a89e..e4d054aaf 100644
--- a/tests/integration/api_repo_teams_test.go
+++ b/tests/integration/api_repo_teams_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -33,7 +32,7 @@ func TestAPIRepoTeams(t *testing.T) {
// ListTeams
url := fmt.Sprintf("/api/v1/repos/%s/teams?token=%s", publicOrgRepo.FullName(), token)
req := NewRequest(t, "GET", url)
- res := session.MakeRequest(t, req, http.StatusOK)
+ res := MakeRequest(t, req, http.StatusOK)
var teams []*api.Team
DecodeJSON(t, res, &teams)
if assert.Len(t, teams, 2) {
@@ -51,19 +50,19 @@ func TestAPIRepoTeams(t *testing.T) {
// IsTeam
url = fmt.Sprintf("/api/v1/repos/%s/teams/%s?token=%s", publicOrgRepo.FullName(), "Test_Team", token)
req = NewRequest(t, "GET", url)
- res = session.MakeRequest(t, req, http.StatusOK)
+ res = MakeRequest(t, req, http.StatusOK)
var team *api.Team
DecodeJSON(t, res, &team)
assert.EqualValues(t, teams[1], team)
url = fmt.Sprintf("/api/v1/repos/%s/teams/%s?token=%s", publicOrgRepo.FullName(), "NonExistingTeam", token)
req = NewRequest(t, "GET", url)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// AddTeam with user4
url = fmt.Sprintf("/api/v1/repos/%s/teams/%s?token=%s", publicOrgRepo.FullName(), "team1", token)
req = NewRequest(t, "PUT", url)
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
// AddTeam with user2
user = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
@@ -71,12 +70,12 @@ func TestAPIRepoTeams(t *testing.T) {
token = getTokenForLoggedInUser(t, session)
url = fmt.Sprintf("/api/v1/repos/%s/teams/%s?token=%s", publicOrgRepo.FullName(), "team1", token)
req = NewRequest(t, "PUT", url)
- session.MakeRequest(t, req, http.StatusNoContent)
- session.MakeRequest(t, req, http.StatusUnprocessableEntity) // test duplicate request
+ MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusUnprocessableEntity) // test duplicate request
// DeleteTeam
url = fmt.Sprintf("/api/v1/repos/%s/teams/%s?token=%s", publicOrgRepo.FullName(), "team1", token)
req = NewRequest(t, "DELETE", url)
- session.MakeRequest(t, req, http.StatusNoContent)
- session.MakeRequest(t, req, http.StatusUnprocessableEntity) // test duplicate request
+ MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusUnprocessableEntity) // test duplicate request
}
diff --git a/tests/integration/api_repo_test.go b/tests/integration/api_repo_test.go
index bfe0c0aa9..76850fb82 100644
--- a/tests/integration/api_repo_test.go
+++ b/tests/integration/api_repo_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -82,9 +81,9 @@ func TestAPISearchRepo(t *testing.T) {
}{
{
name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{
- nil: {count: 30},
- user: {count: 30},
- user2: {count: 30},
+ nil: {count: 31},
+ user: {count: 31},
+ user2: {count: 31},
},
},
{
@@ -199,7 +198,7 @@ func TestAPISearchRepo(t *testing.T) {
t.Run(testName, func(t *testing.T) {
request := NewRequest(t, "GET", testCase.requestURL+"&token="+token)
- response := session.MakeRequest(t, request, http.StatusOK)
+ response := MakeRequest(t, request, http.StatusOK)
var body api.SearchResults
DecodeJSON(t, response, &body)
@@ -307,7 +306,7 @@ func TestAPIOrgRepos(t *testing.T) {
}
t.Run(testName, func(t *testing.T) {
req := NewRequestf(t, "GET", "/api/v1/orgs/%s/repos?token="+token, sourceOrg.Name)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiRepos []*api.Repository
DecodeJSON(t, resp, &apiRepos)
@@ -327,7 +326,7 @@ func TestAPIGetRepoByIDUnauthorized(t *testing.T) {
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
req := NewRequestf(t, "GET", "/api/v1/repositories/2?token="+token)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
}
func TestAPIRepoMigrate(t *testing.T) {
@@ -423,7 +422,7 @@ func TestAPIMirrorSyncNonMirrorRepo(t *testing.T) {
assert.EqualValues(t, false, repo.Mirror)
req = NewRequestf(t, "POST", "/api/v1/repos/user2/repo1/mirror-sync?token=%s", token)
- resp = session.MakeRequest(t, req, http.StatusBadRequest)
+ resp = MakeRequest(t, req, http.StatusBadRequest)
errRespJSON := map[string]string{}
DecodeJSON(t, resp, &errRespJSON)
assert.Equal(t, "Repository is not a mirror", errRespJSON["message"])
@@ -450,7 +449,7 @@ func TestAPIOrgRepoCreate(t *testing.T) {
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/org/%s/repos?token="+token, testCase.orgName), &api.CreateRepoOption{
Name: testCase.repoName,
})
- session.MakeRequest(t, req, testCase.expectedStatus)
+ MakeRequest(t, req, testCase.expectedStatus)
}
}
@@ -520,7 +519,7 @@ func TestAPIRepoTransfer(t *testing.T) {
Readme: "Default",
AutoInit: true,
})
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
DecodeJSON(t, resp, apiRepo)
// start testing
@@ -533,7 +532,7 @@ func TestAPIRepoTransfer(t *testing.T) {
NewOwner: testCase.newOwner,
TeamIDs: testCase.teams,
})
- session.MakeRequest(t, req, testCase.expectedStatus)
+ MakeRequest(t, req, testCase.expectedStatus)
}
// cleanup
@@ -556,14 +555,14 @@ func transfer(t *testing.T) *repo_model.Repository {
AutoInit: true,
})
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
DecodeJSON(t, resp, apiRepo)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID})
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer?token=%s", repo.OwnerName, repo.Name, token), &api.TransferRepoOption{
NewOwner: "user4",
})
- session.MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusCreated)
return repo
}
@@ -577,18 +576,18 @@ func TestAPIAcceptTransfer(t *testing.T) {
session := loginUser(t, "user2")
token := getTokenForLoggedInUser(t, session)
req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/reject?token=%s", repo.OwnerName, repo.Name, token))
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
// try to accept repo that's not marked as transferred
req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/accept?token=%s", "user2", "repo1", token))
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// accept transfer
session = loginUser(t, "user4")
token = getTokenForLoggedInUser(t, session)
req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/accept?token=%s", repo.OwnerName, repo.Name, token))
- resp := session.MakeRequest(t, req, http.StatusAccepted)
+ resp := MakeRequest(t, req, http.StatusAccepted)
apiRepo := new(api.Repository)
DecodeJSON(t, resp, apiRepo)
assert.Equal(t, "user4", apiRepo.Owner.UserName)
@@ -603,18 +602,18 @@ func TestAPIRejectTransfer(t *testing.T) {
session := loginUser(t, "user2")
token := getTokenForLoggedInUser(t, session)
req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/reject?token=%s", repo.OwnerName, repo.Name, token))
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
// try to reject repo that's not marked as transferred
req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/reject?token=%s", "user2", "repo1", token))
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// reject transfer
session = loginUser(t, "user4")
token = getTokenForLoggedInUser(t, session)
req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/reject?token=%s", repo.OwnerName, repo.Name, token))
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
apiRepo := new(api.Repository)
DecodeJSON(t, resp, apiRepo)
assert.Equal(t, "user2", apiRepo.Owner.UserName)
@@ -638,7 +637,7 @@ func TestAPIGenerateRepo(t *testing.T) {
Private: false,
GitContent: true,
})
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
DecodeJSON(t, resp, repo)
assert.Equal(t, "new-repo", repo.Name)
@@ -651,7 +650,7 @@ func TestAPIGenerateRepo(t *testing.T) {
Private: false,
GitContent: true,
})
- resp = session.MakeRequest(t, req, http.StatusCreated)
+ resp = MakeRequest(t, req, http.StatusCreated)
DecodeJSON(t, resp, repo)
assert.Equal(t, "new-repo", repo.Name)
@@ -665,7 +664,7 @@ func TestAPIRepoGetReviewers(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/reviewers?token=%s", user.Name, repo.Name, token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var reviewers []*api.User
DecodeJSON(t, resp, &reviewers)
assert.Len(t, reviewers, 4)
@@ -679,7 +678,7 @@ func TestAPIRepoGetAssignees(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/assignees?token=%s", user.Name, repo.Name, token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var assignees []*api.User
DecodeJSON(t, resp, &assignees)
assert.Len(t, assignees, 1)
diff --git a/tests/integration/api_repo_topic_test.go b/tests/integration/api_repo_topic_test.go
index 4e1e29389..81eb1a942 100644
--- a/tests/integration/api_repo_topic_test.go
+++ b/tests/integration/api_repo_topic_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_settings_test.go b/tests/integration/api_settings_test.go
index b8da17b96..9881578fb 100644
--- a/tests/integration/api_settings_test.go
+++ b/tests/integration/api_settings_test.go
@@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_team_test.go b/tests/integration/api_team_test.go
index a667949c0..46207203b 100644
--- a/tests/integration/api_team_test.go
+++ b/tests/integration/api_team_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -32,7 +31,7 @@ func TestAPITeam(t *testing.T) {
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
req := NewRequestf(t, "GET", "/api/v1/teams/%d?token="+token, teamUser.TeamID)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiTeam api.Team
DecodeJSON(t, resp, &apiTeam)
@@ -46,10 +45,10 @@ func TestAPITeam(t *testing.T) {
session = loginUser(t, user2.Name)
token = getTokenForLoggedInUser(t, session)
req = NewRequestf(t, "GET", "/api/v1/teams/%d?token="+token, teamUser.TeamID)
- _ = session.MakeRequest(t, req, http.StatusForbidden)
+ _ = MakeRequest(t, req, http.StatusForbidden)
req = NewRequestf(t, "GET", "/api/v1/teams/%d", teamUser.TeamID)
- _ = session.MakeRequest(t, req, http.StatusUnauthorized)
+ _ = MakeRequest(t, req, http.StatusUnauthorized)
// Get an admin user able to create, update and delete teams.
user = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
@@ -67,7 +66,7 @@ func TestAPITeam(t *testing.T) {
Units: []string{"repo.code", "repo.issues"},
}
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/orgs/%s/teams?token=%s", org.Name, token), teamToCreate)
- resp = session.MakeRequest(t, req, http.StatusCreated)
+ resp = MakeRequest(t, req, http.StatusCreated)
apiTeam = api.Team{}
DecodeJSON(t, resp, &apiTeam)
checkTeamResponse(t, "CreateTeam1", &apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories,
@@ -88,7 +87,7 @@ func TestAPITeam(t *testing.T) {
}
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/teams/%d?token=%s", teamID, token), teamToEdit)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
apiTeam = api.Team{}
DecodeJSON(t, resp, &apiTeam)
checkTeamResponse(t, "EditTeam1", &apiTeam, teamToEdit.Name, *teamToEdit.Description, *teamToEdit.IncludesAllRepositories,
@@ -100,7 +99,7 @@ func TestAPITeam(t *testing.T) {
editDescription = "first team"
teamToEditDesc := api.EditTeamOption{Description: &editDescription}
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/teams/%d?token=%s", teamID, token), teamToEditDesc)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
apiTeam = api.Team{}
DecodeJSON(t, resp, &apiTeam)
checkTeamResponse(t, "EditTeam1_DescOnly", &apiTeam, teamToEdit.Name, *teamToEditDesc.Description, *teamToEdit.IncludesAllRepositories,
@@ -112,7 +111,7 @@ func TestAPITeam(t *testing.T) {
teamRead := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
assert.NoError(t, teamRead.GetUnits())
req = NewRequestf(t, "GET", "/api/v1/teams/%d?token="+token, teamID)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
apiTeam = api.Team{}
DecodeJSON(t, resp, &apiTeam)
checkTeamResponse(t, "ReadTeam1", &apiTeam, teamRead.Name, *teamToEditDesc.Description, teamRead.IncludesAllRepositories,
@@ -120,7 +119,7 @@ func TestAPITeam(t *testing.T) {
// Delete team.
req = NewRequestf(t, "DELETE", "/api/v1/teams/%d?token="+token, teamID)
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
unittest.AssertNotExistsBean(t, &organization.Team{ID: teamID})
// create team again via UnitsMap
@@ -133,7 +132,7 @@ func TestAPITeam(t *testing.T) {
UnitsMap: map[string]string{"repo.code": "read", "repo.issues": "write", "repo.wiki": "none"},
}
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/orgs/%s/teams?token=%s", org.Name, token), teamToCreate)
- resp = session.MakeRequest(t, req, http.StatusCreated)
+ resp = MakeRequest(t, req, http.StatusCreated)
apiTeam = api.Team{}
DecodeJSON(t, resp, &apiTeam)
checkTeamResponse(t, "CreateTeam2", &apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories,
@@ -154,7 +153,7 @@ func TestAPITeam(t *testing.T) {
}
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/teams/%d?token=%s", teamID, token), teamToEdit)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
apiTeam = api.Team{}
DecodeJSON(t, resp, &apiTeam)
checkTeamResponse(t, "EditTeam2", &apiTeam, teamToEdit.Name, *teamToEdit.Description, *teamToEdit.IncludesAllRepositories,
@@ -166,7 +165,7 @@ func TestAPITeam(t *testing.T) {
editDescription = "second team"
teamToEditDesc = api.EditTeamOption{Description: &editDescription}
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/teams/%d?token=%s", teamID, token), teamToEditDesc)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
apiTeam = api.Team{}
DecodeJSON(t, resp, &apiTeam)
checkTeamResponse(t, "EditTeam2_DescOnly", &apiTeam, teamToEdit.Name, *teamToEditDesc.Description, *teamToEdit.IncludesAllRepositories,
@@ -177,7 +176,7 @@ func TestAPITeam(t *testing.T) {
// Read team.
teamRead = unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
req = NewRequestf(t, "GET", "/api/v1/teams/%d?token="+token, teamID)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
apiTeam = api.Team{}
DecodeJSON(t, resp, &apiTeam)
assert.NoError(t, teamRead.GetUnits())
@@ -186,7 +185,7 @@ func TestAPITeam(t *testing.T) {
// Delete team.
req = NewRequestf(t, "DELETE", "/api/v1/teams/%d?token="+token, teamID)
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
unittest.AssertNotExistsBean(t, &organization.Team{ID: teamID})
}
diff --git a/tests/integration/api_team_user_test.go b/tests/integration/api_team_user_test.go
index b999b97a2..78f98680c 100644
--- a/tests/integration/api_team_user_test.go
+++ b/tests/integration/api_team_user_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -25,10 +24,10 @@ func TestAPITeamUser(t *testing.T) {
session := loginUser(t, normalUsername)
token := getTokenForLoggedInUser(t, session)
req := NewRequest(t, "GET", "/api/v1/teams/1/members/user1?token="+token)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
req = NewRequest(t, "GET", "/api/v1/teams/1/members/user2?token="+token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var user2 *api.User
DecodeJSON(t, resp, &user2)
user2.Created = user2.Created.In(time.Local)
diff --git a/tests/integration/api_token_test.go b/tests/integration/api_token_test.go
index 023bf3017..498bd41b0 100644
--- a/tests/integration/api_token_test.go
+++ b/tests/integration/api_token_test.go
@@ -1,6 +1,5 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_user_email_test.go b/tests/integration/api_user_email_test.go
index 7bd265187..147f703e9 100644
--- a/tests/integration/api_user_email_test.go
+++ b/tests/integration/api_user_email_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -22,7 +21,7 @@ func TestAPIListEmails(t *testing.T) {
token := getTokenForLoggedInUser(t, session)
req := NewRequest(t, "GET", "/api/v1/user/emails?token="+token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var emails []*api.Email
DecodeJSON(t, resp, &emails)
@@ -53,13 +52,13 @@ func TestAPIAddEmail(t *testing.T) {
}
req := NewRequestWithJSON(t, "POST", "/api/v1/user/emails?token="+token, &opts)
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
opts = api.CreateEmailOption{
Emails: []string{"user2-3@example.com"},
}
req = NewRequestWithJSON(t, "POST", "/api/v1/user/emails?token="+token, &opts)
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var emails []*api.Email
DecodeJSON(t, resp, &emails)
@@ -75,7 +74,7 @@ func TestAPIAddEmail(t *testing.T) {
Emails: []string{"notAEmail"},
}
req = NewRequestWithJSON(t, "POST", "/api/v1/user/emails?token="+token, &opts)
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
}
func TestAPIDeleteEmail(t *testing.T) {
@@ -89,16 +88,16 @@ func TestAPIDeleteEmail(t *testing.T) {
Emails: []string{"user2-3@example.com"},
}
req := NewRequestWithJSON(t, "DELETE", "/api/v1/user/emails?token="+token, &opts)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
opts = api.DeleteEmailOption{
Emails: []string{"user2-2@example.com"},
}
req = NewRequestWithJSON(t, "DELETE", "/api/v1/user/emails?token="+token, &opts)
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
req = NewRequest(t, "GET", "/api/v1/user/emails?token="+token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var emails []*api.Email
DecodeJSON(t, resp, &emails)
diff --git a/tests/integration/api_user_follow_test.go b/tests/integration/api_user_follow_test.go
index e21556aa5..65749521c 100644
--- a/tests/integration/api_user_follow_test.go
+++ b/tests/integration/api_user_follow_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_user_heatmap_test.go b/tests/integration/api_user_heatmap_test.go
index da6af0118..432306914 100644
--- a/tests/integration/api_user_heatmap_test.go
+++ b/tests/integration/api_user_heatmap_test.go
@@ -1,6 +1,5 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.package models
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_user_info_test.go b/tests/integration/api_user_info_test.go
index 27fec1d58..65262792b 100644
--- a/tests/integration/api_user_info_test.go
+++ b/tests/integration/api_user_info_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_user_org_perm_test.go b/tests/integration/api_user_org_perm_test.go
index fef653545..8df418494 100644
--- a/tests/integration/api_user_org_perm_test.go
+++ b/tests/integration/api_user_org_perm_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -25,9 +24,8 @@ type apiUserOrgPermTestCase struct {
func TestTokenNeeded(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- session := emptyTestSession(t)
req := NewRequest(t, "GET", "/api/v1/users/user1/orgs/user6/permissions")
- session.MakeRequest(t, req, http.StatusUnauthorized)
+ MakeRequest(t, req, http.StatusUnauthorized)
}
func sampleTest(t *testing.T, auoptc apiUserOrgPermTestCase) {
@@ -37,7 +35,7 @@ func sampleTest(t *testing.T, auoptc apiUserOrgPermTestCase) {
token := getTokenForLoggedInUser(t, session)
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/users/%s/orgs/%s/permissions?token=%s", auoptc.User, auoptc.Organization, token))
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiOP api.OrganizationPermissions
DecodeJSON(t, resp, &apiOP)
@@ -130,7 +128,7 @@ func TestUnknowUser(t *testing.T) {
token := getTokenForLoggedInUser(t, session)
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/users/unknow/orgs/org25/permissions?token=%s", token))
- resp := session.MakeRequest(t, req, http.StatusNotFound)
+ resp := MakeRequest(t, req, http.StatusNotFound)
var apiError api.APIError
DecodeJSON(t, resp, &apiError)
@@ -144,7 +142,7 @@ func TestUnknowOrganization(t *testing.T) {
token := getTokenForLoggedInUser(t, session)
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/users/user1/orgs/unknow/permissions?token=%s", token))
- resp := session.MakeRequest(t, req, http.StatusNotFound)
+ resp := MakeRequest(t, req, http.StatusNotFound)
var apiError api.APIError
DecodeJSON(t, resp, &apiError)
assert.Equal(t, "GetUserByName", apiError.Message)
diff --git a/tests/integration/api_user_orgs_test.go b/tests/integration/api_user_orgs_test.go
index c28bf391e..1f9ee2ea6 100644
--- a/tests/integration/api_user_orgs_test.go
+++ b/tests/integration/api_user_orgs_test.go
@@ -1,6 +1,5 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.package models
+// SPDX-License-Identifier: MIT
package integration
@@ -69,14 +68,12 @@ func TestUserOrgs(t *testing.T) {
func getUserOrgs(t *testing.T, userDoer, userCheck string) (orgs []*api.Organization) {
token := ""
- session := emptyTestSession(t)
if len(userDoer) != 0 {
- session = loginUser(t, userDoer)
- token = getTokenForLoggedInUser(t, session)
+ token = getUserToken(t, userDoer)
}
urlStr := fmt.Sprintf("/api/v1/users/%s/orgs?token=%s", userCheck, token)
req := NewRequest(t, "GET", urlStr)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &orgs)
return orgs
}
@@ -84,15 +81,13 @@ func getUserOrgs(t *testing.T, userDoer, userCheck string) (orgs []*api.Organiza
func TestMyOrgs(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- session := emptyTestSession(t)
req := NewRequest(t, "GET", "/api/v1/user/orgs")
- session.MakeRequest(t, req, http.StatusUnauthorized)
+ MakeRequest(t, req, http.StatusUnauthorized)
normalUsername := "user2"
- session = loginUser(t, normalUsername)
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, normalUsername)
req = NewRequest(t, "GET", "/api/v1/user/orgs?token="+token)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var orgs []*api.Organization
DecodeJSON(t, resp, &orgs)
user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user3"})
diff --git a/tests/integration/api_user_search_test.go b/tests/integration/api_user_search_test.go
index 9e9276077..dc11281c4 100644
--- a/tests/integration/api_user_search_test.go
+++ b/tests/integration/api_user_search_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.package models
+// SPDX-License-Identifier: MIT
package integration
@@ -30,7 +29,7 @@ func TestAPIUserSearchLoggedIn(t *testing.T) {
token := getTokenForLoggedInUser(t, session)
query := "user2"
req := NewRequestf(t, "GET", "/api/v1/users/search?token=%s&q=%s", token, query)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var results SearchResults
DecodeJSON(t, resp, &results)
@@ -70,7 +69,7 @@ func TestAPIUserSearchAdminLoggedInUserHidden(t *testing.T) {
query := "user31"
req := NewRequestf(t, "GET", "/api/v1/users/search?token=%s&q=%s", token, query)
req.SetBasicAuth(token, "x-oauth-basic")
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var results SearchResults
DecodeJSON(t, resp, &results)
diff --git a/tests/integration/api_user_star_test.go b/tests/integration/api_user_star_test.go
index 76c3dc2d1..63363f22d 100644
--- a/tests/integration/api_user_star_test.go
+++ b/tests/integration/api_user_star_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_user_watch_test.go b/tests/integration/api_user_watch_test.go
index e45050a27..295e639fd 100644
--- a/tests/integration/api_user_watch_test.go
+++ b/tests/integration/api_user_watch_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/api_wiki_test.go b/tests/integration/api_wiki_test.go
index c6f4841d0..546f4d0e3 100644
--- a/tests/integration/api_wiki_test.go
+++ b/tests/integration/api_wiki_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -20,12 +19,11 @@ func TestAPIGetWikiPage(t *testing.T) {
defer tests.PrepareTestEnv(t)()
username := "user2"
- session := loginUser(t, username)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/wiki/page/Home", username, "repo1")
req := NewRequest(t, "GET", urlStr)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var page *api.WikiPage
DecodeJSON(t, resp, &page)
@@ -66,12 +64,11 @@ func TestAPIListWikiPages(t *testing.T) {
defer tests.PrepareTestEnv(t)()
username := "user2"
- session := loginUser(t, username)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/wiki/pages", username, "repo1")
req := NewRequest(t, "GET", urlStr)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var meta []*api.WikiPageMetaData
DecodeJSON(t, resp, &meta)
@@ -191,7 +188,7 @@ func TestAPINewWikiPage(t *testing.T) {
ContentBase64: base64.StdEncoding.EncodeToString([]byte("Wiki page content for API unit tests")),
Message: "",
})
- session.MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusCreated)
}
}
@@ -208,18 +205,17 @@ func TestAPIEditWikiPage(t *testing.T) {
ContentBase64: base64.StdEncoding.EncodeToString([]byte("Edited wiki page content for API unit tests")),
Message: "",
})
- session.MakeRequest(t, req, http.StatusOK)
+ MakeRequest(t, req, http.StatusOK)
}
func TestAPIListPageRevisions(t *testing.T) {
defer tests.PrepareTestEnv(t)()
username := "user2"
- session := loginUser(t, username)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/wiki/revisions/Home", username, "repo1")
req := NewRequest(t, "GET", urlStr)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var revisions *api.WikiCommitList
DecodeJSON(t, resp, &revisions)
diff --git a/tests/integration/attachment_test.go b/tests/integration/attachment_test.go
index 2d2c979f7..a92814ece 100644
--- a/tests/integration/attachment_test.go
+++ b/tests/integration/attachment_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/auth_ldap_test.go b/tests/integration/auth_ldap_test.go
index f3c3e6d7b..88571ecd6 100644
--- a/tests/integration/auth_ldap_test.go
+++ b/tests/integration/auth_ldap_test.go
@@ -1,6 +1,5 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/benchmarks_test.go b/tests/integration/benchmarks_test.go
index bf66d221f..2f91f8273 100644
--- a/tests/integration/benchmarks_test.go
+++ b/tests/integration/benchmarks_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/branches_test.go b/tests/integration/branches_test.go
index bd0bd63c5..efb3798bd 100644
--- a/tests/integration/branches_test.go
+++ b/tests/integration/branches_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/change_default_branch_test.go b/tests/integration/change_default_branch_test.go
index 8edc0e63c..703834b71 100644
--- a/tests/integration/change_default_branch_test.go
+++ b/tests/integration/change_default_branch_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/cmd_keys_test.go b/tests/integration/cmd_keys_test.go
index 0c72956c2..ccde04891 100644
--- a/tests/integration/cmd_keys_test.go
+++ b/tests/integration/cmd_keys_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go
index 134ae520a..dc2bff89f 100644
--- a/tests/integration/compare_test.go
+++ b/tests/integration/compare_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/cors_test.go b/tests/integration/cors_test.go
index c702c62e4..cc2d85b41 100644
--- a/tests/integration/cors_test.go
+++ b/tests/integration/cors_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/create_no_session_test.go b/tests/integration/create_no_session_test.go
index c617b1828..9a96ed61f 100644
--- a/tests/integration/create_no_session_test.go
+++ b/tests/integration/create_no_session_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/csrf_test.go b/tests/integration/csrf_test.go
index 18a157412..a78985988 100644
--- a/tests/integration/csrf_test.go
+++ b/tests/integration/csrf_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/delete_user_test.go b/tests/integration/delete_user_test.go
index 1d9d257f1..806b87dc4 100644
--- a/tests/integration/delete_user_test.go
+++ b/tests/integration/delete_user_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/download_test.go b/tests/integration/download_test.go
index 9d3b17d10..efe5ac791 100644
--- a/tests/integration/download_test.go
+++ b/tests/integration/download_test.go
@@ -1,6 +1,5 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -35,9 +34,9 @@ func TestDownloadByIDForSVGUsesSecureHeaders(t *testing.T) {
req := NewRequest(t, "GET", "/user2/repo2/raw/blob/6395b68e1feebb1e4c657b4f9f6ba2676a283c0b")
resp := session.MakeRequest(t, req, http.StatusOK)
- assert.Equal(t, "default-src 'none'; style-src 'unsafe-inline'; sandbox", resp.HeaderMap.Get("Content-Security-Policy"))
- assert.Equal(t, "image/svg+xml", resp.HeaderMap.Get("Content-Type"))
- assert.Equal(t, "nosniff", resp.HeaderMap.Get("X-Content-Type-Options"))
+ assert.Equal(t, "default-src 'none'; style-src 'unsafe-inline'; sandbox", resp.Header().Get("Content-Security-Policy"))
+ assert.Equal(t, "image/svg+xml", resp.Header().Get("Content-Type"))
+ assert.Equal(t, "nosniff", resp.Header().Get("X-Content-Type-Options"))
}
func TestDownloadByIDMedia(t *testing.T) {
@@ -61,9 +60,9 @@ func TestDownloadByIDMediaForSVGUsesSecureHeaders(t *testing.T) {
req := NewRequest(t, "GET", "/user2/repo2/media/blob/6395b68e1feebb1e4c657b4f9f6ba2676a283c0b")
resp := session.MakeRequest(t, req, http.StatusOK)
- assert.Equal(t, "default-src 'none'; style-src 'unsafe-inline'; sandbox", resp.HeaderMap.Get("Content-Security-Policy"))
- assert.Equal(t, "image/svg+xml", resp.HeaderMap.Get("Content-Type"))
- assert.Equal(t, "nosniff", resp.HeaderMap.Get("X-Content-Type-Options"))
+ assert.Equal(t, "default-src 'none'; style-src 'unsafe-inline'; sandbox", resp.Header().Get("Content-Security-Policy"))
+ assert.Equal(t, "image/svg+xml", resp.Header().Get("Content-Type"))
+ assert.Equal(t, "nosniff", resp.Header().Get("X-Content-Type-Options"))
}
func TestDownloadRawTextFileWithoutMimeTypeMapping(t *testing.T) {
@@ -74,7 +73,7 @@ func TestDownloadRawTextFileWithoutMimeTypeMapping(t *testing.T) {
req := NewRequest(t, "GET", "/user2/repo2/raw/branch/master/test.xml")
resp := session.MakeRequest(t, req, http.StatusOK)
- assert.Equal(t, "text/plain; charset=utf-8", resp.HeaderMap.Get("Content-Type"))
+ assert.Equal(t, "text/plain; charset=utf-8", resp.Header().Get("Content-Type"))
}
func TestDownloadRawTextFileWithMimeTypeMapping(t *testing.T) {
@@ -87,7 +86,7 @@ func TestDownloadRawTextFileWithMimeTypeMapping(t *testing.T) {
req := NewRequest(t, "GET", "/user2/repo2/raw/branch/master/test.xml")
resp := session.MakeRequest(t, req, http.StatusOK)
- assert.Equal(t, "text/xml; charset=utf-8", resp.HeaderMap.Get("Content-Type"))
+ assert.Equal(t, "text/xml; charset=utf-8", resp.Header().Get("Content-Type"))
delete(setting.MimeTypeMap.Map, ".xml")
setting.MimeTypeMap.Enabled = false
diff --git a/tests/integration/dump_restore_test.go b/tests/integration/dump_restore_test.go
index 19513d027..e34738aaf 100644
--- a/tests/integration/dump_restore_test.go
+++ b/tests/integration/dump_restore_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -25,7 +24,7 @@ import (
"code.gitea.io/gitea/services/migrations"
"github.com/stretchr/testify/assert"
- "gopkg.in/yaml.v2"
+ "gopkg.in/yaml.v3"
)
func TestDumpRestore(t *testing.T) {
diff --git a/tests/integration/editor_test.go b/tests/integration/editor_test.go
index 19e80dc7b..4355dd0a4 100644
--- a/tests/integration/editor_test.go
+++ b/tests/integration/editor_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/empty_repo_test.go b/tests/integration/empty_repo_test.go
index 8810363dc..4bc1d811b 100644
--- a/tests/integration/empty_repo_test.go
+++ b/tests/integration/empty_repo_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/eventsource_test.go b/tests/integration/eventsource_test.go
index cd496e012..e810a9fa2 100644
--- a/tests/integration/eventsource_test.go
+++ b/tests/integration/eventsource_test.go
@@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -11,6 +10,7 @@ import (
"time"
activities_model "code.gitea.io/gitea/models/activities"
+ "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -57,7 +57,7 @@ func TestEventSourceManagerRun(t *testing.T) {
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
- assert.NoError(t, thread5.LoadAttributes())
+ assert.NoError(t, thread5.LoadAttributes(db.DefaultContext))
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session)
diff --git a/tests/integration/explore_repos_test.go b/tests/integration/explore_repos_test.go
index dca325275..26fd1dde6 100644
--- a/tests/integration/explore_repos_test.go
+++ b/tests/integration/explore_repos_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/git_clone_wiki_test.go b/tests/integration/git_clone_wiki_test.go
index e8764e6bd..d7949dfe2 100644
--- a/tests/integration/git_clone_wiki_test.go
+++ b/tests/integration/git_clone_wiki_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/git_helper_for_declarative_test.go b/tests/integration/git_helper_for_declarative_test.go
index 45b4f4447..9e3ff9c44 100644
--- a/tests/integration/git_helper_for_declarative_test.go
+++ b/tests/integration/git_helper_for_declarative_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/git_smart_http_test.go b/tests/integration/git_smart_http_test.go
index 02b0e9387..15336b9b8 100644
--- a/tests/integration/git_smart_http_test.go
+++ b/tests/integration/git_smart_http_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/git_test.go b/tests/integration/git_test.go
index 6f656ef2c..8d29a161d 100644
--- a/tests/integration/git_test.go
+++ b/tests/integration/git_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -571,7 +570,7 @@ func doPushCreate(ctx APITestContext, u *url.URL) func(t *testing.T) {
t.Run("SuccessfullyPushAndCreateTestRepository", doGitPushTestRepository(tmpDir, "origin", "master"))
// Finally, fetch repo from database and ensure the correct repository has been created
- repo, err := repo_model.GetRepositoryByOwnerAndName(ctx.Username, ctx.Reponame)
+ repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, ctx.Username, ctx.Reponame)
assert.NoError(t, err)
assert.False(t, repo.IsEmpty)
assert.True(t, repo.IsPrivate)
@@ -699,7 +698,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
pr1, pr2 *issues_model.PullRequest
commit string
)
- repo, err := repo_model.GetRepositoryByOwnerAndName(ctx.Username, ctx.Reponame)
+ repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, ctx.Username, ctx.Reponame)
if !assert.NoError(t, err) {
return
}
diff --git a/tests/integration/goget_test.go b/tests/integration/goget_test.go
index c969f4aff..fab391146 100644
--- a/tests/integration/goget_test.go
+++ b/tests/integration/goget_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/gpg_git_test.go b/tests/integration/gpg_git_test.go
index 4dcf6276c..669212ff1 100644
--- a/tests/integration/gpg_git_test.go
+++ b/tests/integration/gpg_git_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/html_helper.go b/tests/integration/html_helper.go
index 35d61f7b3..933bb51cf 100644
--- a/tests/integration/html_helper.go
+++ b/tests/integration/html_helper.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go
index 416cc126b..9bf4c38ee 100644
--- a/tests/integration/integration_test.go
+++ b/tests/integration/integration_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go
index 1f0f894ca..c913a2000 100644
--- a/tests/integration/issue_test.go
+++ b/tests/integration/issue_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/lfs_getobject_test.go b/tests/integration/lfs_getobject_test.go
index f2b0ac80c..a191bcb61 100644
--- a/tests/integration/lfs_getobject_test.go
+++ b/tests/integration/lfs_getobject_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -12,6 +11,7 @@ import (
"net/http/httptest"
"testing"
+ "code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/json"
@@ -41,7 +41,7 @@ func storeObjectInRepo(t *testing.T, repositoryID int64, content *[]byte) string
}
func storeAndGetLfs(t *testing.T, content *[]byte, extraHeader *http.Header, expectedStatus int) *httptest.ResponseRecorder {
- repo, err := repo_model.GetRepositoryByOwnerAndName("user2", "repo1")
+ repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "repo1")
assert.NoError(t, err)
oid := storeObjectInRepo(t, repo.ID, content)
defer git_model.RemoveLFSMetaObjectByOid(repo.ID, oid)
diff --git a/tests/integration/lfs_local_endpoint_test.go b/tests/integration/lfs_local_endpoint_test.go
index 4042dc95b..d42888bbe 100644
--- a/tests/integration/lfs_local_endpoint_test.go
+++ b/tests/integration/lfs_local_endpoint_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/links_test.go b/tests/integration/links_test.go
index 4eb29f0ce..9136f8f91 100644
--- a/tests/integration/links_test.go
+++ b/tests/integration/links_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/markup_external_test.go b/tests/integration/markup_external_test.go
new file mode 100644
index 000000000..6ea0226ec
--- /dev/null
+++ b/tests/integration/markup_external_test.go
@@ -0,0 +1,40 @@
+// Copyright 2022 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package integration
+
+import (
+ "bytes"
+ "io"
+ "net/http"
+ "strings"
+ "testing"
+
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/tests"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestExternalMarkupRenderer(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+ if !setting.Database.UseSQLite3 {
+ t.Skip()
+ return
+ }
+
+ const repoURL = "user30/renderer"
+ req := NewRequest(t, "GET", repoURL+"/src/branch/master/README.html")
+ resp := MakeRequest(t, req, http.StatusOK)
+ assert.EqualValues(t, "text/html; charset=UTF-8", resp.Header()["Content-Type"][0])
+
+ bs, err := io.ReadAll(resp.Body)
+ assert.NoError(t, err)
+
+ doc := NewHTMLParser(t, bytes.NewBuffer(bs))
+ div := doc.Find("div.file-view")
+ data, err := div.Html()
+ assert.NoError(t, err)
+ assert.EqualValues(t, "<div>\n\ttest external renderer\n</div>", strings.TrimSpace(data))
+}
diff --git a/tests/integration/migrate_test.go b/tests/integration/migrate_test.go
index 99d5d6c8d..9eca69cfc 100644
--- a/tests/integration/migrate_test.go
+++ b/tests/integration/migrate_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/migration-test/migration_test.go b/tests/integration/migration-test/migration_test.go
index 0159fb4f3..170a6dd44 100644
--- a/tests/integration/migration-test/migration_test.go
+++ b/tests/integration/migration-test/migration_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package migrations
diff --git a/tests/integration/mirror_pull_test.go b/tests/integration/mirror_pull_test.go
index 707cf46fa..1bd91a48b 100644
--- a/tests/integration/mirror_pull_test.go
+++ b/tests/integration/mirror_pull_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -8,6 +7,7 @@ import (
"context"
"testing"
+ "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -58,7 +58,7 @@ func TestMirrorPull(t *testing.T) {
defer gitRepo.Close()
findOptions := repo_model.FindReleasesOptions{IncludeDrafts: true, IncludeTags: true}
- initCount, err := repo_model.GetReleaseCountByRepoID(mirror.ID, findOptions)
+ initCount, err := repo_model.GetReleaseCountByRepoID(db.DefaultContext, mirror.ID, findOptions)
assert.NoError(t, err)
assert.NoError(t, release_service.CreateRelease(gitRepo, &repo_model.Release{
@@ -81,7 +81,7 @@ func TestMirrorPull(t *testing.T) {
ok := mirror_service.SyncPullMirror(ctx, mirror.ID)
assert.True(t, ok)
- count, err := repo_model.GetReleaseCountByRepoID(mirror.ID, findOptions)
+ count, err := repo_model.GetReleaseCountByRepoID(db.DefaultContext, mirror.ID, findOptions)
assert.NoError(t, err)
assert.EqualValues(t, initCount+1, count)
@@ -92,7 +92,7 @@ func TestMirrorPull(t *testing.T) {
ok = mirror_service.SyncPullMirror(ctx, mirror.ID)
assert.True(t, ok)
- count, err = repo_model.GetReleaseCountByRepoID(mirror.ID, findOptions)
+ count, err = repo_model.GetReleaseCountByRepoID(db.DefaultContext, mirror.ID, findOptions)
assert.NoError(t, err)
assert.EqualValues(t, initCount, count)
}
diff --git a/tests/integration/mirror_push_test.go b/tests/integration/mirror_push_test.go
index f2adf5f5a..b2ec6c093 100644
--- a/tests/integration/mirror_push_test.go
+++ b/tests/integration/mirror_push_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/nonascii_branches_test.go b/tests/integration/nonascii_branches_test.go
index 638b9a616..8917a9b57 100644
--- a/tests/integration/nonascii_branches_test.go
+++ b/tests/integration/nonascii_branches_test.go
@@ -1,6 +1,5 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -23,7 +22,7 @@ func testSrcRouteRedirect(t *testing.T, session *TestSession, user, repo, route,
resp := session.MakeRequest(t, req, http.StatusSeeOther)
// Check Location header
- location := resp.HeaderMap.Get("Location")
+ location := resp.Header().Get("Location")
assert.Equal(t, path.Join(prefix, expectedLocation), location)
// Perform redirect
diff --git a/tests/integration/oauth_test.go b/tests/integration/oauth_test.go
index 7863313b1..9649b256a 100644
--- a/tests/integration/oauth_test.go
+++ b/tests/integration/oauth_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/org_count_test.go b/tests/integration/org_count_test.go
index 96f39924f..a6fe7f188 100644
--- a/tests/integration/org_count_test.go
+++ b/tests/integration/org_count_test.go
@@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/org_team_invite_test.go b/tests/integration/org_team_invite_test.go
index 470478589..4d848dfc6 100644
--- a/tests/integration/org_team_invite_test.go
+++ b/tests/integration/org_team_invite_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/org_test.go b/tests/integration/org_test.go
index d04fcf7f5..09a5f4208 100644
--- a/tests/integration/org_test.go
+++ b/tests/integration/org_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/privateactivity_test.go b/tests/integration/privateactivity_test.go
index 3f352e49c..06019406d 100644
--- a/tests/integration/privateactivity_test.go
+++ b/tests/integration/privateactivity_test.go
@@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/pull_compare_test.go b/tests/integration/pull_compare_test.go
index 60e69e97e..fa385ddae 100644
--- a/tests/integration/pull_compare_test.go
+++ b/tests/integration/pull_compare_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/pull_create_test.go b/tests/integration/pull_create_test.go
index b5cb7877b..35f7cb8ab 100644
--- a/tests/integration/pull_create_test.go
+++ b/tests/integration/pull_create_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go
index bec85e8a8..e72d00ffb 100644
--- a/tests/integration/pull_merge_test.go
+++ b/tests/integration/pull_merge_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/pull_review_test.go b/tests/integration/pull_review_test.go
index d713c0f85..68d80a102 100644
--- a/tests/integration/pull_review_test.go
+++ b/tests/integration/pull_review_test.go
@@ -1,6 +1,6 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
+
package integration
import (
diff --git a/tests/integration/pull_status_test.go b/tests/integration/pull_status_test.go
index 381cc73cd..bca8ec848 100644
--- a/tests/integration/pull_status_test.go
+++ b/tests/integration/pull_status_test.go
@@ -1,6 +1,6 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
+
package integration
import (
diff --git a/tests/integration/pull_update_test.go b/tests/integration/pull_update_test.go
index c08faaaeb..1e20a63e6 100644
--- a/tests/integration/pull_update_test.go
+++ b/tests/integration/pull_update_test.go
@@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -35,8 +34,8 @@ func TestAPIPullUpdate(t *testing.T) {
assert.NoError(t, err)
assert.EqualValues(t, 1, diffCount.Behind)
assert.EqualValues(t, 1, diffCount.Ahead)
- assert.NoError(t, pr.LoadBaseRepo())
- assert.NoError(t, pr.LoadIssue())
+ assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
+ assert.NoError(t, pr.LoadIssue(db.DefaultContext))
session := loginUser(t, "user2")
token := getTokenForLoggedInUser(t, session)
@@ -63,8 +62,8 @@ func TestAPIPullUpdateByRebase(t *testing.T) {
assert.NoError(t, err)
assert.EqualValues(t, 1, diffCount.Behind)
assert.EqualValues(t, 1, diffCount.Ahead)
- assert.NoError(t, pr.LoadBaseRepo())
- assert.NoError(t, pr.LoadIssue())
+ assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
+ assert.NoError(t, pr.LoadIssue(db.DefaultContext))
session := loginUser(t, "user2")
token := getTokenForLoggedInUser(t, session)
diff --git a/tests/integration/release_test.go b/tests/integration/release_test.go
index 2a52a5cde..3fcd4a5b5 100644
--- a/tests/integration/release_test.go
+++ b/tests/integration/release_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -54,7 +53,7 @@ func checkLatestReleaseAndCount(t *testing.T, session *TestSession, repoURL, ver
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
- labelText := htmlDoc.doc.Find("#release-list > li .meta .label").First().Text()
+ labelText := htmlDoc.doc.Find("#release-list > li .detail .label").First().Text()
assert.EqualValues(t, label, labelText)
titleText := htmlDoc.doc.Find("#release-list > li .detail h4 a").First().Text()
assert.EqualValues(t, version, titleText)
diff --git a/tests/integration/rename_branch_test.go b/tests/integration/rename_branch_test.go
index 9ea69702a..9a55193cc 100644
--- a/tests/integration/rename_branch_test.go
+++ b/tests/integration/rename_branch_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -36,7 +35,7 @@ func TestRenameBranch(t *testing.T) {
// check old branch link
req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/master/README.md", postData)
resp = session.MakeRequest(t, req, http.StatusSeeOther)
- location := resp.HeaderMap.Get("Location")
+ location := resp.Header().Get("Location")
assert.Equal(t, "/user2/repo1/src/branch/main/README.md", location)
// check db
diff --git a/tests/integration/repo_activity_test.go b/tests/integration/repo_activity_test.go
index ea8845ac3..c8d0c46d6 100644
--- a/tests/integration/repo_activity_test.go
+++ b/tests/integration/repo_activity_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/repo_branch_test.go b/tests/integration/repo_branch_test.go
index 96ffa5a46..c56aa43c5 100644
--- a/tests/integration/repo_branch_test.go
+++ b/tests/integration/repo_branch_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/repo_commits_search_test.go b/tests/integration/repo_commits_search_test.go
index 83f30758a..1c27b6db9 100644
--- a/tests/integration/repo_commits_search_test.go
+++ b/tests/integration/repo_commits_search_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go
index c9e775359..0d794cec7 100644
--- a/tests/integration/repo_commits_test.go
+++ b/tests/integration/repo_commits_test.go
@@ -1,13 +1,14 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
import (
+ "fmt"
"net/http"
"net/http/httptest"
"path"
+ "sync"
"testing"
"code.gitea.io/gitea/modules/json"
@@ -115,3 +116,32 @@ func TestRepoCommitsWithStatusFailure(t *testing.T) {
func TestRepoCommitsWithStatusWarning(t *testing.T) {
doTestRepoCommitWithStatus(t, "warning", "gitea-exclamation", "yellow")
}
+
+func TestRepoCommitsStatusParallel(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ session := loginUser(t, "user2")
+
+ // Request repository commits page
+ req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
+ resp := session.MakeRequest(t, req, http.StatusOK)
+
+ doc := NewHTMLParser(t, resp.Body)
+ // Get first commit URL
+ commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href")
+ assert.True(t, exists)
+ assert.NotEmpty(t, commitURL)
+
+ var wg sync.WaitGroup
+ for i := 0; i < 10; i++ {
+ wg.Add(1)
+ go func(parentT *testing.T, i int) {
+ parentT.Run(fmt.Sprintf("ParallelCreateStatus_%d", i), func(t *testing.T) {
+ runBody := doAPICreateCommitStatus(NewAPITestContext(t, "user2", "repo1"), path.Base(commitURL), api.CommitStatusState("pending"))
+ runBody(t)
+ wg.Done()
+ })
+ }(t, i)
+ }
+ wg.Wait()
+}
diff --git a/tests/integration/repo_fork_test.go b/tests/integration/repo_fork_test.go
index 4ab3577b5..26c81f5be 100644
--- a/tests/integration/repo_fork_test.go
+++ b/tests/integration/repo_fork_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/repo_generate_test.go b/tests/integration/repo_generate_test.go
index 61a632721..4654fd70f 100644
--- a/tests/integration/repo_generate_test.go
+++ b/tests/integration/repo_generate_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/repo_migrate_test.go b/tests/integration/repo_migrate_test.go
index c69a2642c..91e2961d6 100644
--- a/tests/integration/repo_migrate_test.go
+++ b/tests/integration/repo_migrate_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/repo_search_test.go b/tests/integration/repo_search_test.go
index b20943c22..d113d1e57 100644
--- a/tests/integration/repo_search_test.go
+++ b/tests/integration/repo_search_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -8,6 +7,7 @@ import (
"net/http"
"testing"
+ "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
code_indexer "code.gitea.io/gitea/modules/indexer/code"
"code.gitea.io/gitea/modules/setting"
@@ -29,7 +29,7 @@ func resultFilenames(t testing.TB, doc *HTMLDoc) []string {
func TestSearchRepo(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- repo, err := repo_model.GetRepositoryByOwnerAndName("user2", "repo1")
+ repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "repo1")
assert.NoError(t, err)
executeIndexer(t, repo, code_indexer.UpdateRepoIndexer)
@@ -39,7 +39,7 @@ func TestSearchRepo(t *testing.T) {
setting.Indexer.IncludePatterns = setting.IndexerGlobFromString("**.txt")
setting.Indexer.ExcludePatterns = setting.IndexerGlobFromString("**/y/**")
- repo, err = repo_model.GetRepositoryByOwnerAndName("user2", "glob")
+ repo, err = repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "glob")
assert.NoError(t, err)
executeIndexer(t, repo, code_indexer.UpdateRepoIndexer)
diff --git a/tests/integration/repo_tag_test.go b/tests/integration/repo_tag_test.go
index fb08895e2..5ea9392a9 100644
--- a/tests/integration/repo_tag_test.go
+++ b/tests/integration/repo_tag_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
@@ -9,6 +8,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
@@ -74,22 +74,22 @@ func TestCreateNewTagProtected(t *testing.T) {
})
// Cleanup
- releases, err := repo_model.GetReleasesByRepoID(repo.ID, repo_model.FindReleasesOptions{
+ releases, err := repo_model.GetReleasesByRepoID(db.DefaultContext, repo.ID, repo_model.FindReleasesOptions{
IncludeTags: true,
TagNames: []string{"v-1", "v-1.1"},
})
assert.NoError(t, err)
for _, release := range releases {
- err = repo_model.DeleteReleaseByID(release.ID)
+ err = repo_model.DeleteReleaseByID(db.DefaultContext, release.ID)
assert.NoError(t, err)
}
- protectedTags, err := git_model.GetProtectedTags(repo.ID)
+ protectedTags, err := git_model.GetProtectedTags(db.DefaultContext, repo.ID)
assert.NoError(t, err)
for _, protectedTag := range protectedTags {
- err = git_model.DeleteProtectedTag(protectedTag)
+ err = git_model.DeleteProtectedTag(db.DefaultContext, protectedTag)
assert.NoError(t, err)
}
}
diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go
index 8e494a9af..3692b11ec 100644
--- a/tests/integration/repo_test.go
+++ b/tests/integration/repo_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/repo_topic_test.go b/tests/integration/repo_topic_test.go
index 5ff0c8273..58fee8418 100644
--- a/tests/integration/repo_topic_test.go
+++ b/tests/integration/repo_topic_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/repo_watch_test.go b/tests/integration/repo_watch_test.go
index 152600bf2..c47080298 100644
--- a/tests/integration/repo_watch_test.go
+++ b/tests/integration/repo_watch_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/repofiles_delete_test.go b/tests/integration/repofiles_delete_test.go
index f594efdee..6698b280b 100644
--- a/tests/integration/repofiles_delete_test.go
+++ b/tests/integration/repofiles_delete_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/repofiles_update_test.go b/tests/integration/repofiles_update_test.go
index c62c49eee..47b61c1ee 100644
--- a/tests/integration/repofiles_update_test.go
+++ b/tests/integration/repofiles_update_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/setting_test.go b/tests/integration/setting_test.go
index 6273545c2..71b28a625 100644
--- a/tests/integration/setting_test.go
+++ b/tests/integration/setting_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/signin_test.go b/tests/integration/signin_test.go
index 7dc078e27..9ae45d324 100644
--- a/tests/integration/signin_test.go
+++ b/tests/integration/signin_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/signout_test.go b/tests/integration/signout_test.go
index 1f1346a5c..0416930c6 100644
--- a/tests/integration/signout_test.go
+++ b/tests/integration/signout_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/signup_test.go b/tests/integration/signup_test.go
index 1c598fd0d..f983f98ad 100644
--- a/tests/integration/signup_test.go
+++ b/tests/integration/signup_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/ssh_key_test.go b/tests/integration/ssh_key_test.go
index fd98af512..89a277430 100644
--- a/tests/integration/ssh_key_test.go
+++ b/tests/integration/ssh_key_test.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/timetracking_test.go b/tests/integration/timetracking_test.go
index 54b81ff3b..52081615a 100644
--- a/tests/integration/timetracking_test.go
+++ b/tests/integration/timetracking_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/user_avatar_test.go b/tests/integration/user_avatar_test.go
index 35be840c2..08ecb8b74 100644
--- a/tests/integration/user_avatar_test.go
+++ b/tests/integration/user_avatar_test.go
@@ -1,6 +1,5 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/user_test.go b/tests/integration/user_test.go
index 017700ad4..eeaa6d6e0 100644
--- a/tests/integration/user_test.go
+++ b/tests/integration/user_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/version_test.go b/tests/integration/version_test.go
index 83be62d3f..a6ae649b4 100644
--- a/tests/integration/version_test.go
+++ b/tests/integration/version_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/view_test.go b/tests/integration/view_test.go
index f55afb038..f43444680 100644
--- a/tests/integration/view_test.go
+++ b/tests/integration/view_test.go
@@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/webfinger_test.go b/tests/integration/webfinger_test.go
index bb3447c80..226c25615 100644
--- a/tests/integration/webfinger_test.go
+++ b/tests/integration/webfinger_test.go
@@ -1,6 +1,5 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/integration/xss_test.go b/tests/integration/xss_test.go
index 53b23072a..e575ed399 100644
--- a/tests/integration/xss_test.go
+++ b/tests/integration/xss_test.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package integration
diff --git a/tests/sqlite.ini.tmpl b/tests/sqlite.ini.tmpl
index f5e8895e0..f6f8c70ed 100644
--- a/tests/sqlite.ini.tmpl
+++ b/tests/sqlite.ini.tmpl
@@ -107,3 +107,10 @@ PATH = tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-sqlite/data/lfs
[packages]
ENABLED = true
+
+[markup.html]
+ENABLED = true
+FILE_EXTENSIONS = .html
+RENDER_COMMAND = `go run tools/external_renderer.go`
+IS_INPUT_FILE = false
+RENDER_CONTENT_MODE=sanitized
diff --git a/tests/test_utils.go b/tests/test_utils.go
index 066253000..b4bd4a011 100644
--- a/tests/test_utils.go
+++ b/tests/test_utils.go
@@ -1,6 +1,5 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package tests
diff --git a/tests/testlogger.go b/tests/testlogger.go
index b65573a77..a7cc27a92 100644
--- a/tests/testlogger.go
+++ b/tests/testlogger.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// SPDX-License-Identifier: MIT
package tests