Fixed printing built RPMs from spec files. (#4173)
This commit is contained in:
Родитель
9c0152a0a4
Коммит
e867002a16
|
@ -211,12 +211,9 @@ func QuerySPEC(specFile, sourceDir, queryFormat, arch string, defines map[string
|
|||
|
||||
// QuerySPECForBuiltRPMs queries a SPEC file with queryFormat. Returns only the subpackages, which generate a .rpm file.
|
||||
func QuerySPECForBuiltRPMs(specFile, sourceDir, arch string, defines map[string]string) (result []string, err error) {
|
||||
const (
|
||||
builtRPMsSwitch = "--builtrpms"
|
||||
queryFormat = ""
|
||||
)
|
||||
const queryFormat = "%{nvra}\n"
|
||||
|
||||
return QuerySPEC(specFile, sourceDir, queryFormat, arch, defines, builtRPMsSwitch)
|
||||
return QuerySPEC(specFile, sourceDir, queryFormat, arch, defines, QueryBuiltRPMHeadersArgument)
|
||||
}
|
||||
|
||||
// QueryPackage queries an RPM or SRPM file with queryFormat. Returns the output split by line and trimmed.
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
package rpm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
@ -13,13 +14,17 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const specsDir = "testdata"
|
||||
const (
|
||||
definesDistKey = "dist"
|
||||
definesWithCheckKey = "with_check"
|
||||
specsDir = "testdata"
|
||||
)
|
||||
|
||||
var buildArch = goArchToRpmArch[runtime.GOARCH]
|
||||
|
||||
var defines = map[string]string{
|
||||
"dist": ".cmX",
|
||||
"with_check": "1",
|
||||
definesDistKey: ".cmX",
|
||||
definesWithCheckKey: "1",
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
@ -98,3 +103,14 @@ func TestArchShouldFailForExcludedArchitectures(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.False(t, matches)
|
||||
}
|
||||
|
||||
func TestShouldListOnlySubpackageWithArchitectureInRPMsList(t *testing.T) {
|
||||
expectedRPMs := []string{
|
||||
fmt.Sprintf("subpackage_name-1.0.0-1%s.%s", defines[definesDistKey], buildArch),
|
||||
}
|
||||
specFilePath := filepath.Join(specsDir, "no_default_package.spec")
|
||||
|
||||
builtRPMs, err := QuerySPECForBuiltRPMs(specFilePath, specsDir, buildArch, defines)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, expectedRPMs, builtRPMs)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
Summary: Test spec file with with no default package
|
||||
Name: no_default_package
|
||||
Version: 1.0.0
|
||||
Release: 1%{?dist}
|
||||
License: MIT
|
||||
URL: https://test.com
|
||||
Group: Test
|
||||
Vendor: Microsoft
|
||||
Distribution: Mariner
|
||||
|
||||
%description
|
||||
Test spec. Make sure the default package is not built!
|
||||
|
||||
%package -n subpackage_name
|
||||
Summary: Actually built subpackage
|
||||
|
||||
%description -n subpackage_name
|
||||
Test subpackage, which should be generate when this spec is built.
|
||||
|
||||
%prep
|
||||
|
||||
%build
|
||||
|
||||
%install
|
||||
|
||||
%files -n subpackage_name
|
||||
%defattr(-,root,root)
|
||||
|
||||
%changelog
|
||||
* Mon Nov 07 2022 Pawel Winogrodzki <pawelwi@microsoft.com> - 1.0.0-1
|
||||
- Initial creation.
|
Загрузка…
Ссылка в новой задаче