0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-02-23 06:15:56 -05:00
forgejo/modules/packages/rpm/metadata_test.go

165 lines
5.1 KiB
Go
Raw Normal View History

// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package rpm
import (
"bytes"
"compress/gzip"
"encoding/base64"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParsePackage(t *testing.T) {
base64RpmPackageContent := `H4sICFayB2QCAGdpdGVhLXRlc3QtMS4wLjItMS14ODZfNjQucnBtAO2YV4gTQRjHJzl7wbNhhxVF
VNwk2zd2PdvZ9Sxnd3Z3NllNsmF3o6congVFsWFHRWwIImIXfRER0QcRfPBJEXvvBQvWSfZTT0VQ
8TF/MuU33zcz3+zOJGEe73lyuQBRBWKWRzDrEddjuVAkxLMc+lsFUOWfm5bvvReAalWECg/TsivU
dyKa0U61aVnl6wj0Uxe4nc8F92hZiaYE8CO/P0r7/Quegr0c7M/AvoCaGZEIWNGUqMHrhhGROIUT
Zc7gOAOraoQzCNZ0WdU0HpEI5jiB4zlek3gT85wqCBomhomxoGCs8wImWMImbxqKgXVNUKKaqShR
STKVKK9glFUNcf2g+/t27xs16v5x/eyOKftVGlIhyiuvvPLKK6+88sorr7zyyiuvvPKCO5HPnz+v
pGVhhXsTsFVeSstuWR9anwU+Bk3Vch5wTwL3JkHg+8C1gR8A169wj1KdpobAj4HbAT+Be5VewE+h
fz/g52AvBX4N9vHAb4AnA7+F8ePAH8BuA38ELgf+BLzQ50oIeBlw0OdAOXAlP57AGuCsbwGtbgCu
DrwRuAb4bwau6T/PwFbgWsDXgWuD/y3gOmC/B1wI/Bi4AcT3Arih3z9YCNzI9w9m/YKUG4Nd9N9z
pSZgHwrcFPgccFt//OADGE+F/q+Ao+D/FrijzwV1gbv4/QvaAHcFDgF3B5aB+wB3Be7rz1dQCtwP
eDxwMcw3GbgU7AasdwzYE8DjwT4L/CeAvRx4IvBCYA3iWQds+Fz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iDtcCddDECahx7SuVNP5dpmb5
9tMDyaXb7OAlk5acuPn57ss9mw6Wym0m1Fq2cej7tUt2LL4/b8enXU2fndk+fvv57ndnt55/cQob
7tpp/pEjDS7cGPZ6BY430+7danDq6f42Nw49b9F7zp6BiKpJb9s5P0AYN2+L159cnrur636rx+v1
7ae1K28QbMMcqI8CqwIrgwg9nTOp8Oj9q81plUY7ZuwXN8Vvs8wbAAA=`
rpmPackageContent, err := base64.StdEncoding.DecodeString(base64RpmPackageContent)
require.NoError(t, err)
zr, err := gzip.NewReader(bytes.NewReader(rpmPackageContent))
require.NoError(t, err)
Alt Linux Apt-Rpm repository support for Forgejo packages. (#6351) Co-authored-by: Aleksandr Gamzin alexgamz1119@gmail.com Adds support for the Apt-Rpm registry of the Alt Lunux distribution. Alt Linux uses RPM packages to store and distribute software to its users. But the logic of the Alt Linux package registry is different from the Red Hat package registry. I have added support for the Alt Linux package registry. ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [x] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [ ] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Co-authored-by: Aleksandr Gamzin <gamzin@altlinux.org> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6351 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Alex619829 <alex619829@noreply.codeberg.org> Co-committed-by: Alex619829 <alex619829@noreply.codeberg.org>
2025-01-22 14:01:49 +00:00
p, err := ParsePackage(zr, "rpm")
assert.NotNil(t, p)
require.NoError(t, err)
assert.Equal(t, "gitea-test", p.Name)
assert.Equal(t, "1.0.2-1", p.Version)
assert.NotNil(t, p.VersionMetadata)
assert.NotNil(t, p.FileMetadata)
assert.Equal(t, "MIT", p.VersionMetadata.License)
assert.Equal(t, "https://gitea.io", p.VersionMetadata.ProjectURL)
assert.Equal(t, "RPM package summary", p.VersionMetadata.Summary)
assert.Equal(t, "RPM package description", p.VersionMetadata.Description)
assert.Equal(t, "x86_64", p.FileMetadata.Architecture)
assert.Equal(t, "0", p.FileMetadata.Epoch)
assert.Equal(t, "1.0.2", p.FileMetadata.Version)
assert.Equal(t, "1", p.FileMetadata.Release)
assert.Empty(t, p.FileMetadata.Vendor)
assert.Equal(t, "KN4CK3R", p.FileMetadata.Packager)
assert.Equal(t, "gitea-test-1.0.2-1.src.rpm", p.FileMetadata.SourceRpm)
assert.Equal(t, "e44b1687d04b", p.FileMetadata.BuildHost)
assert.EqualValues(t, 1678225964, p.FileMetadata.BuildTime)
assert.EqualValues(t, 1678225964, p.FileMetadata.FileTime)
assert.EqualValues(t, 13, p.FileMetadata.InstalledSize)
assert.EqualValues(t, 272, p.FileMetadata.ArchiveSize)
assert.Empty(t, p.FileMetadata.Conflicts)
assert.Empty(t, p.FileMetadata.Obsoletes)
assert.ElementsMatch(
t,
[]*Entry{
{
Name: "gitea-test",
Flags: "EQ",
Version: "1.0.2",
Epoch: "0",
Release: "1",
},
{
Name: "gitea-test(x86-64)",
Flags: "EQ",
Version: "1.0.2",
Epoch: "0",
Release: "1",
},
},
p.FileMetadata.Provides,
)
assert.ElementsMatch(
t,
[]*Entry{
{
Name: "/bin/sh",
},
{
Name: "/bin/sh",
},
{
Name: "/bin/sh",
},
{
Name: "rpmlib(CompressedFileNames)",
Flags: "LE",
Version: "3.0.4",
Epoch: "0",
Release: "1",
},
{
Name: "rpmlib(FileDigests)",
Flags: "LE",
Version: "4.6.0",
Epoch: "0",
Release: "1",
},
{
Name: "rpmlib(PayloadFilesHavePrefix)",
Flags: "LE",
Version: "4.0",
Epoch: "0",
Release: "1",
},
{
Name: "rpmlib(PayloadIsXz)",
Flags: "LE",
Version: "5.2",
Epoch: "0",
Release: "1",
},
},
p.FileMetadata.Requires,
)
assert.ElementsMatch(
t,
[]*File{
{
Path: "/usr/local/bin/hello",
IsExecutable: true,
},
},
p.FileMetadata.Files,
)
assert.ElementsMatch(
t,
[]*Changelog{
{
Author: "KN4CK3R <dummy@gitea.io>",
Date: 1678276800,
Text: "- Changelog message.",
},
},
p.FileMetadata.Changelogs,
)
}