rpmmd: test rpm list deduplication
This commit is contained in:
parent
9aef7bfc47
commit
38b8bfbd66
1 changed files with 130 additions and 0 deletions
|
|
@ -3,9 +3,12 @@ package rpmmd
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
|
@ -76,3 +79,130 @@ func Test_osbuildStagesToRPMs(t *testing.T) {
|
|||
// if neither GPG nor PGP is set, the signature is nil
|
||||
require.Nil(t, rpms[2].Signature)
|
||||
}
|
||||
|
||||
func TestRPMDeduplication(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// start with metadata, that includes duplicates, convert, then deduplicate
|
||||
metadata := osbuild.PipelineMetadata{
|
||||
"1": &osbuild.RPMStageMetadata{
|
||||
Packages: []osbuild.RPMPackageMetadata{
|
||||
// python38 twice
|
||||
{
|
||||
Name: "python38",
|
||||
Version: "3.8.8",
|
||||
Release: "4.module+el8.5.0+12205+a865257a",
|
||||
Epoch: nil,
|
||||
Arch: "x86_64",
|
||||
SigMD5: "-",
|
||||
SigPGP: "-",
|
||||
SigGPG: "-",
|
||||
},
|
||||
{
|
||||
Name: "python38",
|
||||
Version: "3.8.8",
|
||||
Release: "4.module+el8.5.0+12205+a865257a",
|
||||
Epoch: nil,
|
||||
Arch: "x86_64",
|
||||
SigMD5: "-",
|
||||
SigPGP: "-",
|
||||
SigGPG: "-",
|
||||
},
|
||||
// made up package
|
||||
{
|
||||
Name: "unique",
|
||||
Version: "1.90",
|
||||
Release: "10",
|
||||
Epoch: nil,
|
||||
Arch: "aarch64",
|
||||
SigMD5: ".",
|
||||
SigPGP: ".",
|
||||
SigGPG: ".",
|
||||
},
|
||||
// made up package with epoch
|
||||
{
|
||||
Name: "package-with-epoch",
|
||||
Version: "0.1",
|
||||
Release: "a",
|
||||
Epoch: common.StringToPtr("8"),
|
||||
Arch: "x86_64",
|
||||
SigMD5: "*",
|
||||
SigPGP: "*",
|
||||
SigGPG: "*",
|
||||
},
|
||||
},
|
||||
},
|
||||
// separate pipeline
|
||||
"2": &osbuild.RPMStageMetadata{
|
||||
Packages: []osbuild.RPMPackageMetadata{
|
||||
// duplicate package with epoch
|
||||
{
|
||||
Name: "vim-minimal",
|
||||
Version: "8.0.1763",
|
||||
Release: "15.el8",
|
||||
Epoch: common.StringToPtr("2"),
|
||||
Arch: "x86_64",
|
||||
SigMD5: "v",
|
||||
SigPGP: "v",
|
||||
SigGPG: "v",
|
||||
},
|
||||
{
|
||||
Name: "vim-minimal",
|
||||
Version: "8.0.1763",
|
||||
Release: "15.el8",
|
||||
Epoch: common.StringToPtr("2"),
|
||||
Arch: "x86_64",
|
||||
SigMD5: "v",
|
||||
SigPGP: "v",
|
||||
SigGPG: "v",
|
||||
},
|
||||
// package with same name but different version
|
||||
{
|
||||
Name: "dupename",
|
||||
Version: "1",
|
||||
Release: "1.el8",
|
||||
Epoch: nil,
|
||||
Arch: "x86_64",
|
||||
SigMD5: "2",
|
||||
SigPGP: "2",
|
||||
SigGPG: "2",
|
||||
},
|
||||
{
|
||||
Name: "dupename",
|
||||
Version: "2",
|
||||
Release: "1.el8",
|
||||
Epoch: nil,
|
||||
Arch: "x86_64",
|
||||
SigMD5: "2",
|
||||
SigPGP: "2",
|
||||
SigGPG: "2",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
testNames := []string{"dupename", "dupename", "package-with-epoch", "python38", "python38", "unique", "vim-minimal", "vim-minimal"}
|
||||
testNamesDeduped := []string{"dupename", "dupename", "package-with-epoch", "python38", "unique", "vim-minimal"}
|
||||
|
||||
rpms := OSBuildMetadataToRPMs(metadata)
|
||||
|
||||
// basic sanity checks
|
||||
assert.Len(rpms, 8)
|
||||
|
||||
sortedNames := func(rpms []RPM) []string {
|
||||
names := make([]string, len(rpms))
|
||||
for idx, rpm := range rpms {
|
||||
names[idx] = rpm.Name
|
||||
}
|
||||
|
||||
sort.Strings(names)
|
||||
return names
|
||||
}
|
||||
|
||||
names := sortedNames(rpms)
|
||||
assert.Equal(names, testNames)
|
||||
|
||||
deduped := DeduplicateRPMs(rpms)
|
||||
assert.Len(deduped, 6)
|
||||
dedupedNames := sortedNames(deduped)
|
||||
assert.Equal(dedupedNames, testNamesDeduped)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue