2022-09-03 12:01:00 -04:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-09-03 12:01:00 -04:00
|
|
|
|
|
|
|
package packages_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
packages_model "code.gitea.io/gitea/models/packages"
|
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
|
|
|
|
|
|
_ "code.gitea.io/gitea/models"
|
2023-09-08 00:51:15 -04:00
|
|
|
_ "code.gitea.io/gitea/models/actions"
|
|
|
|
_ "code.gitea.io/gitea/models/activities"
|
2022-09-03 12:01:00 -04:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-30 15:41:10 -04:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-09-03 12:01:00 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2023-09-27 21:38:53 -04:00
|
|
|
unittest.MainTest(m)
|
2022-09-03 12:01:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHasOwnerPackages(t *testing.T) {
|
2024-07-30 15:41:10 -04:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2022-09-03 12:01:00 -04:00
|
|
|
|
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
|
|
|
|
|
|
|
p, err := packages_model.TryInsertPackage(db.DefaultContext, &packages_model.Package{
|
|
|
|
OwnerID: owner.ID,
|
|
|
|
LowerName: "package",
|
|
|
|
})
|
|
|
|
assert.NotNil(t, p)
|
2024-07-30 15:41:10 -04:00
|
|
|
require.NoError(t, err)
|
2022-09-03 12:01:00 -04:00
|
|
|
|
|
|
|
// A package without package versions gets automatically cleaned up and should return false
|
|
|
|
has, err := packages_model.HasOwnerPackages(db.DefaultContext, owner.ID)
|
|
|
|
assert.False(t, has)
|
2024-07-30 15:41:10 -04:00
|
|
|
require.NoError(t, err)
|
2022-09-03 12:01:00 -04:00
|
|
|
|
|
|
|
pv, err := packages_model.GetOrInsertVersion(db.DefaultContext, &packages_model.PackageVersion{
|
|
|
|
PackageID: p.ID,
|
|
|
|
LowerVersion: "internal",
|
|
|
|
IsInternal: true,
|
|
|
|
})
|
|
|
|
assert.NotNil(t, pv)
|
2024-07-30 15:41:10 -04:00
|
|
|
require.NoError(t, err)
|
2022-09-03 12:01:00 -04:00
|
|
|
|
Fix various typos (#21103)
Found via `codespell -q 3 -S
./options/locale,./options/license,./public/vendor,./web_src/fomantic -L
actived,allways,attachements,ba,befores,commiter,pullrequest,pullrequests,readby,splitted,te,unknwon`
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2022-09-07 14:40:36 -04:00
|
|
|
// A package with an internal package version gets automatically cleaned up and should return false
|
2022-09-03 12:01:00 -04:00
|
|
|
has, err = packages_model.HasOwnerPackages(db.DefaultContext, owner.ID)
|
|
|
|
assert.False(t, has)
|
2024-07-30 15:41:10 -04:00
|
|
|
require.NoError(t, err)
|
2022-09-03 12:01:00 -04:00
|
|
|
|
|
|
|
pv, err = packages_model.GetOrInsertVersion(db.DefaultContext, &packages_model.PackageVersion{
|
|
|
|
PackageID: p.ID,
|
|
|
|
LowerVersion: "normal",
|
|
|
|
IsInternal: false,
|
|
|
|
})
|
|
|
|
assert.NotNil(t, pv)
|
2024-07-30 15:41:10 -04:00
|
|
|
require.NoError(t, err)
|
2022-09-03 12:01:00 -04:00
|
|
|
|
|
|
|
// A package with a normal package version should return true
|
|
|
|
has, err = packages_model.HasOwnerPackages(db.DefaultContext, owner.ID)
|
|
|
|
assert.True(t, has)
|
2024-07-30 15:41:10 -04:00
|
|
|
require.NoError(t, err)
|
2022-09-03 12:01:00 -04:00
|
|
|
}
|