mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-04-26 13:40:20 +03:00

Some checks are pending
/ release (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
The only parameter that is ever used is a single directory, make it that only instead of a more complex option structure. Remove tests.AddFixtures that was the simpler form because it is now redundant. --- Backporting to v11.0 will help with automated backporting of bug fixes in need of custom made fixtures. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7648 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
// Copyright 2025 The Forgejo Authors.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package packages
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"forgejo.org/models/unittest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestPackagesGetOrInsertBlob(t *testing.T) {
|
|
defer unittest.OverrideFixtures("models/fixtures/TestPackagesGetOrInsertBlob")()
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
blake2bIsSet := unittest.AssertExistsAndLoadBean(t, &PackageBlob{ID: 1})
|
|
blake2bNotSet := unittest.AssertExistsAndLoadBean(t, &PackageBlob{ID: 2})
|
|
|
|
var blake2bSetToRandom PackageBlob
|
|
blake2bSetToRandom = *blake2bNotSet
|
|
blake2bSetToRandom.HashBlake2b = "SOMETHING RANDOM"
|
|
|
|
for _, testCase := range []struct {
|
|
name string
|
|
exists bool
|
|
packageBlob *PackageBlob
|
|
}{
|
|
{
|
|
name: "exists and blake2b is not null in the database",
|
|
exists: true,
|
|
packageBlob: blake2bIsSet,
|
|
},
|
|
{
|
|
name: "exists and blake2b is null in the database",
|
|
exists: true,
|
|
packageBlob: &blake2bSetToRandom,
|
|
},
|
|
{
|
|
name: "does not exists",
|
|
exists: false,
|
|
packageBlob: &PackageBlob{
|
|
Size: 30,
|
|
HashMD5: "HASHMD5_3",
|
|
HashSHA1: "HASHSHA1_3",
|
|
HashSHA256: "HASHSHA256_3",
|
|
HashSHA512: "HASHSHA512_3",
|
|
HashBlake2b: "HASHBLAKE2B_3",
|
|
},
|
|
},
|
|
} {
|
|
t.Run(testCase.name, func(t *testing.T) {
|
|
found, has, _ := GetOrInsertBlob(t.Context(), testCase.packageBlob)
|
|
assert.Equal(t, testCase.exists, has)
|
|
require.NotNil(t, found)
|
|
if testCase.exists {
|
|
assert.Equal(t, found.ID, testCase.packageBlob.ID)
|
|
} else {
|
|
unittest.BeanExists(t, &PackageBlob{ID: found.ID})
|
|
}
|
|
})
|
|
}
|
|
}
|