summaryrefslogtreecommitdiffstats
path: root/integrations/api_packages_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'integrations/api_packages_test.go')
-rw-r--r--integrations/api_packages_test.go33
1 files changed, 30 insertions, 3 deletions
diff --git a/integrations/api_packages_test.go b/integrations/api_packages_test.go
index 263e7cea53..b3f6e88d9f 100644
--- a/integrations/api_packages_test.go
+++ b/integrations/api_packages_test.go
@@ -9,11 +9,15 @@ import (
"fmt"
"net/http"
"testing"
+ "time"
- "code.gitea.io/gitea/models/packages"
+ "code.gitea.io/gitea/models/db"
+ packages_model "code.gitea.io/gitea/models/packages"
+ container_model "code.gitea.io/gitea/models/packages/container"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
api "code.gitea.io/gitea/modules/structs"
+ packages_service "code.gitea.io/gitea/services/packages"
"github.com/stretchr/testify/assert"
)
@@ -43,7 +47,7 @@ func TestPackageAPI(t *testing.T) {
DecodeJSON(t, resp, &apiPackages)
assert.Len(t, apiPackages, 1)
- assert.Equal(t, string(packages.TypeGeneric), apiPackages[0].Type)
+ assert.Equal(t, string(packages_model.TypeGeneric), apiPackages[0].Type)
assert.Equal(t, packageName, apiPackages[0].Name)
assert.Equal(t, packageVersion, apiPackages[0].Version)
assert.NotNil(t, apiPackages[0].Creator)
@@ -62,7 +66,7 @@ func TestPackageAPI(t *testing.T) {
var p *api.Package
DecodeJSON(t, resp, &p)
- assert.Equal(t, string(packages.TypeGeneric), p.Type)
+ assert.Equal(t, string(packages_model.TypeGeneric), p.Type)
assert.Equal(t, packageName, p.Name)
assert.Equal(t, packageVersion, p.Version)
assert.NotNil(t, p.Creator)
@@ -100,3 +104,26 @@ func TestPackageAPI(t *testing.T) {
MakeRequest(t, req, http.StatusNoContent)
})
}
+
+func TestPackageCleanup(t *testing.T) {
+ defer prepareTestEnv(t)()
+
+ time.Sleep(time.Second)
+
+ pbs, err := packages_model.FindExpiredUnreferencedBlobs(db.DefaultContext, time.Duration(0))
+ 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_service.Cleanup(nil, time.Duration(0))
+ assert.NoError(t, err)
+
+ pbs, err = packages_model.FindExpiredUnreferencedBlobs(db.DefaultContext, time.Duration(0))
+ 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)
+}