mirror of
https://github.com/go-gitea/gitea
synced 2024-11-14 14:01:34 +01:00
bf999e4069
Co-authored-by: @awkwardbunny This PR adds a Debian package registry. You can follow [this tutorial](https://www.baeldung.com/linux/create-debian-package) to build a *.deb package for testing. Source packages are not supported at the moment and I did not find documentation of the architecture "all" and how these packages should be treated. ![grafik](https://user-images.githubusercontent.com/1666336/218126879-eb80a866-775c-4c8e-8529-5797203a64e6.png) Part of #20751. Revised copy of #22854. --------- Co-authored-by: Brian Hong <brian@hongs.me> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: Giteabot <teabot@gitea.io>
73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/packages"
|
|
"code.gitea.io/gitea/models/unittest"
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
packages_module "code.gitea.io/gitea/modules/packages"
|
|
"code.gitea.io/gitea/modules/storage"
|
|
packages_service "code.gitea.io/gitea/services/packages"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMigratePackages(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
creator := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
|
|
|
content := "package main\n\nfunc main() {\nfmt.Println(\"hi\")\n}\n"
|
|
buf, err := packages_module.CreateHashedBufferFromReaderWithSize(strings.NewReader(content), 1024)
|
|
assert.NoError(t, err)
|
|
defer buf.Close()
|
|
|
|
v, f, err := packages_service.CreatePackageAndAddFile(&packages_service.PackageCreationInfo{
|
|
PackageInfo: packages_service.PackageInfo{
|
|
Owner: creator,
|
|
PackageType: packages.TypeGeneric,
|
|
Name: "test",
|
|
Version: "1.0.0",
|
|
},
|
|
Creator: creator,
|
|
SemverCompatible: true,
|
|
VersionProperties: map[string]string{},
|
|
}, &packages_service.PackageFileCreationInfo{
|
|
PackageFileInfo: packages_service.PackageFileInfo{
|
|
Filename: "a.go",
|
|
},
|
|
Creator: creator,
|
|
Data: buf,
|
|
IsLead: true,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, v)
|
|
assert.NotNil(t, f)
|
|
|
|
ctx := context.Background()
|
|
|
|
p := t.TempDir()
|
|
|
|
dstStorage, err := storage.NewLocalStorage(
|
|
ctx,
|
|
storage.LocalStorageConfig{
|
|
Path: p,
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
err = migratePackages(ctx, dstStorage)
|
|
assert.NoError(t, err)
|
|
|
|
entries, err := os.ReadDir(p)
|
|
assert.NoError(t, err)
|
|
assert.Len(t, entries, 2)
|
|
assert.EqualValues(t, "01", entries[0].Name())
|
|
assert.EqualValues(t, "tmp", entries[1].Name())
|
|
}
|