aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKN4CK3R2023-02-23 15:11:56 +0100
committerGitHub2023-02-23 22:11:56 +0800
commit0ae1ed749dd6581379b7ccf483d66051869b52d7 (patch)
tree0522d4888f51b9056e55a93dcb5bd46f2726ef2f /tests
parent3adfc0f02d1440d22934403b8d944218747b9289 (diff)
Remove all package data after tests (#22984)
Fixes #21020 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/api_packages_composer_test.go1
-rw-r--r--tests/integration/api_packages_conan_test.go1
-rw-r--r--tests/integration/api_packages_container_test.go2
-rw-r--r--tests/integration/api_packages_generic_test.go1
-rw-r--r--tests/integration/api_packages_helm_test.go1
-rw-r--r--tests/integration/api_packages_maven_test.go1
-rw-r--r--tests/integration/api_packages_npm_test.go1
-rw-r--r--tests/integration/api_packages_pub_test.go1
-rw-r--r--tests/integration/api_packages_pypi_test.go1
-rw-r--r--tests/integration/api_packages_rubygems_test.go1
-rw-r--r--tests/integration/api_packages_test.go26
-rw-r--r--tests/test_utils.go14
12 files changed, 46 insertions, 5 deletions
diff --git a/tests/integration/api_packages_composer_test.go b/tests/integration/api_packages_composer_test.go
index 87647cc47..ac1259056 100644
--- a/tests/integration/api_packages_composer_test.go
+++ b/tests/integration/api_packages_composer_test.go
@@ -25,6 +25,7 @@ import (
func TestPackageComposer(t *testing.T) {
defer tests.PrepareTestEnv(t)()
+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
vendorName := "gitea"
diff --git a/tests/integration/api_packages_conan_test.go b/tests/integration/api_packages_conan_test.go
index 5ced388b4..209aeecd1 100644
--- a/tests/integration/api_packages_conan_test.go
+++ b/tests/integration/api_packages_conan_test.go
@@ -205,6 +205,7 @@ func uploadConanPackageV2(t *testing.T, baseURL, token, name, version, user, cha
func TestPackageConan(t *testing.T) {
defer tests.PrepareTestEnv(t)()
+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
name := "ConanPackage"
diff --git a/tests/integration/api_packages_container_test.go b/tests/integration/api_packages_container_test.go
index bbab820ec..d925fd164 100644
--- a/tests/integration/api_packages_container_test.go
+++ b/tests/integration/api_packages_container_test.go
@@ -640,7 +640,7 @@ func TestPackageContainer(t *testing.T) {
checkCatalog := func(owner string) func(t *testing.T) {
return func(t *testing.T) {
- defer tests.PrepareTestEnv(t)()
+ defer tests.PrintCurrentTest(t)()
req := NewRequest(t, "GET", fmt.Sprintf("%sv2/_catalog", setting.AppURL))
addTokenAuthHeader(req, userToken)
diff --git a/tests/integration/api_packages_generic_test.go b/tests/integration/api_packages_generic_test.go
index 875b9ed96..765d11fd8 100644
--- a/tests/integration/api_packages_generic_test.go
+++ b/tests/integration/api_packages_generic_test.go
@@ -21,6 +21,7 @@ import (
func TestPackageGeneric(t *testing.T) {
defer tests.PrepareTestEnv(t)()
+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
packageName := "te-st_pac.kage"
diff --git a/tests/integration/api_packages_helm_test.go b/tests/integration/api_packages_helm_test.go
index 4a7d56343..4f6145207 100644
--- a/tests/integration/api_packages_helm_test.go
+++ b/tests/integration/api_packages_helm_test.go
@@ -26,6 +26,7 @@ import (
func TestPackageHelm(t *testing.T) {
defer tests.PrepareTestEnv(t)()
+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
packageName := "test-chart"
diff --git a/tests/integration/api_packages_maven_test.go b/tests/integration/api_packages_maven_test.go
index 5c0dbfc99..81112f305 100644
--- a/tests/integration/api_packages_maven_test.go
+++ b/tests/integration/api_packages_maven_test.go
@@ -22,6 +22,7 @@ import (
func TestPackageMaven(t *testing.T) {
defer tests.PrepareTestEnv(t)()
+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
groupID := "com.gitea"
diff --git a/tests/integration/api_packages_npm_test.go b/tests/integration/api_packages_npm_test.go
index 39d1c91e8..6c4503f7e 100644
--- a/tests/integration/api_packages_npm_test.go
+++ b/tests/integration/api_packages_npm_test.go
@@ -24,6 +24,7 @@ import (
func TestPackageNpm(t *testing.T) {
defer tests.PrepareTestEnv(t)()
+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
token := fmt.Sprintf("Bearer %s", getTokenForLoggedInUser(t, loginUser(t, user.Name)))
diff --git a/tests/integration/api_packages_pub_test.go b/tests/integration/api_packages_pub_test.go
index 325401fe7..24975ab62 100644
--- a/tests/integration/api_packages_pub_test.go
+++ b/tests/integration/api_packages_pub_test.go
@@ -27,6 +27,7 @@ import (
func TestPackagePub(t *testing.T) {
defer tests.PrepareTestEnv(t)()
+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
token := "Bearer " + getUserToken(t, user.Name)
diff --git a/tests/integration/api_packages_pypi_test.go b/tests/integration/api_packages_pypi_test.go
index 71197f92a..c7c466e73 100644
--- a/tests/integration/api_packages_pypi_test.go
+++ b/tests/integration/api_packages_pypi_test.go
@@ -25,6 +25,7 @@ import (
func TestPackagePyPI(t *testing.T) {
defer tests.PrepareTestEnv(t)()
+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
packageName := "test-package"
diff --git a/tests/integration/api_packages_rubygems_test.go b/tests/integration/api_packages_rubygems_test.go
index c85ff9aaf..2099357cb 100644
--- a/tests/integration/api_packages_rubygems_test.go
+++ b/tests/integration/api_packages_rubygems_test.go
@@ -23,6 +23,7 @@ import (
func TestPackageRubyGems(t *testing.T) {
defer tests.PrepareTestEnv(t)()
+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
packageName := "gitea"
diff --git a/tests/integration/api_packages_test.go b/tests/integration/api_packages_test.go
index 4a16cec01..4228003e2 100644
--- a/tests/integration/api_packages_test.go
+++ b/tests/integration/api_packages_test.go
@@ -19,6 +19,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/modules/util"
packages_service "code.gitea.io/gitea/services/packages"
packages_cleanup_service "code.gitea.io/gitea/services/packages/cleanup"
"code.gitea.io/gitea/tests"
@@ -235,16 +236,35 @@ func TestPackageQuota(t *testing.T) {
func TestPackageCleanup(t *testing.T) {
defer tests.PrepareTestEnv(t)()
+ user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
+
duration, _ := time.ParseDuration("-1h")
t.Run("Common", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
+ // Upload and delete a generic package and upload a container blob
+ data, _ := util.CryptoRandomBytes(5)
+ url := fmt.Sprintf("/api/packages/%s/generic/cleanup-test/1.1.1/file.bin", user.Name)
+ req := NewRequestWithBody(t, "PUT", url, bytes.NewReader(data))
+ AddBasicAuthHeader(req, user.Name)
+ MakeRequest(t, req, http.StatusCreated)
+
+ req = NewRequest(t, "DELETE", url)
+ AddBasicAuthHeader(req, user.Name)
+ MakeRequest(t, req, http.StatusNoContent)
+
+ data, _ = util.CryptoRandomBytes(5)
+ url = fmt.Sprintf("/v2/%s/cleanup-test/blobs/uploads?digest=sha256:%x", user.Name, sha256.Sum256(data))
+ req = NewRequestWithBody(t, "POST", url, bytes.NewReader(data))
+ AddBasicAuthHeader(req, user.Name)
+ MakeRequest(t, req, http.StatusCreated)
+
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)
+ _, err = packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, "cleanup-test", container_model.UploadVersion)
assert.NoError(t, err)
err = packages_cleanup_service.Cleanup(db.DefaultContext, duration)
@@ -254,15 +274,13 @@ func TestPackageCleanup(t *testing.T) {
assert.NoError(t, err)
assert.Empty(t, pbs)
- _, err = packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, 2, packages_model.TypeContainer, "test", container_model.UploadVersion)
+ _, err = packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, "cleanup-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
diff --git a/tests/test_utils.go b/tests/test_utils.go
index 9e9f97a5f..5cc31b814 100644
--- a/tests/test_utils.go
+++ b/tests/test_utils.go
@@ -13,6 +13,8 @@ import (
"runtime"
"testing"
+ "code.gitea.io/gitea/models/db"
+ packages_model "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/git"
@@ -204,6 +206,18 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
return err
}))
+ // clear all package data
+ assert.NoError(t, db.TruncateBeans(db.DefaultContext,
+ &packages_model.Package{},
+ &packages_model.PackageVersion{},
+ &packages_model.PackageFile{},
+ &packages_model.PackageBlob{},
+ &packages_model.PackageProperty{},
+ &packages_model.PackageBlobUpload{},
+ &packages_model.PackageCleanupRule{},
+ ))
+ assert.NoError(t, storage.Clean(storage.Packages))
+
return deferFn
}