mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package packages_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
packages_model "github.com/hanzoai/git/models/packages"
|
|
"github.com/hanzoai/git/models/unittest"
|
|
user_model "github.com/hanzoai/git/models/user"
|
|
|
|
_ "github.com/hanzoai/git/models"
|
|
_ "github.com/hanzoai/git/models/actions"
|
|
_ "github.com/hanzoai/git/models/activities"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
unittest.MainTest(m)
|
|
}
|
|
|
|
func TestHasOwnerPackages(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
|
|
|
p, err := packages_model.TryInsertPackage(t.Context(), &packages_model.Package{
|
|
OwnerID: owner.ID,
|
|
LowerName: "package",
|
|
})
|
|
assert.NotNil(t, p)
|
|
assert.NoError(t, err)
|
|
|
|
// A package without package versions gets automatically cleaned up and should return false
|
|
has, err := packages_model.HasOwnerPackages(t.Context(), owner.ID)
|
|
assert.False(t, has)
|
|
assert.NoError(t, err)
|
|
|
|
pv, err := packages_model.GetOrInsertVersion(t.Context(), &packages_model.PackageVersion{
|
|
PackageID: p.ID,
|
|
LowerVersion: "internal",
|
|
IsInternal: true,
|
|
})
|
|
assert.NotNil(t, pv)
|
|
assert.NoError(t, err)
|
|
|
|
// A package with an internal package version gets automatically cleaned up and should return false
|
|
has, err = packages_model.HasOwnerPackages(t.Context(), owner.ID)
|
|
assert.False(t, has)
|
|
assert.NoError(t, err)
|
|
|
|
pv, err = packages_model.GetOrInsertVersion(t.Context(), &packages_model.PackageVersion{
|
|
PackageID: p.ID,
|
|
LowerVersion: "normal",
|
|
IsInternal: false,
|
|
})
|
|
assert.NotNil(t, pv)
|
|
assert.NoError(t, err)
|
|
|
|
// A package with a normal package version should return true
|
|
has, err = packages_model.HasOwnerPackages(t.Context(), owner.ID)
|
|
assert.True(t, has)
|
|
assert.NoError(t, err)
|
|
}
|