Replace all rpmmd.Depsolve() calls with dnfjson
All calls to rpmmd.Depsolve() are now replaced with the equivalent call to solver.Depsolve() (or dnfjson.Depsolve() for one-off calls). Attached an unconfigured dnfjson.BaseSolver to all APIs and server configurations where rpmmd.RPMMD used to be. This BaseSolver instance loads the repository credentials from the system and carries the cache directory, much like the RPMMD field used to do. The BaseSolver is used to create an initialised (configured) solver with the platform variables (module platform ID, release ver, and arch) before running a Depsolve() or FetchMetadata() using the NewWithConfig() method. The FillDependencies() call in the modulesInfoHandler() of the weldr API has been replaced by a direct call to the Depsolve() function. This rpmmd function was only used here. Replacing the rpmmd.Depsolve() call in rpmmd.FillDependencies() with dnfjson.Depsolve() would have created an import cycle. The FillDependencies() function could have been moved to dnfjson, but since it's only used in one place, moving the one-line function body into the caller is ok. For testing: The mock-dnf-json is compiled to a temporary directory during test initialisation and used for each Depsolve() or FetchMetadata() call. The weldr API tests now use the mock dnfjson. Each rpmmd_mock.Fixture now also has a dnfjson_mock.ResponseGenerator. All API calls in the tests use the proper functions from dnfjson and only the dnf-json script is mocked. Because of this, some of the expected results in responses_test had to be changed to match correct behaviour: - The "builds" array of each package in the result of a module or project list is now sorted by version number (ascending) because we sort the package list in the result of dnfjson by NVR. - 'check_gpg: true' is added to the expected response of the depsolve test. The repository configs in the test weldr API specify 'CheckGPG: True', but the mock responses returned it as false, so the expected result didn't need to include it. Since now we're using the actual dnfjson code to convert the mock response to the internal structure, the repository settings are correctly used to set flag to true for each package associated with that repository. - The word "occurred" was mistyped as "occured" in rpmmd and is now fixed in dnfjson.
This commit is contained in:
parent
e9a7a50496
commit
177ea1b08f
14 changed files with 1618 additions and 1606 deletions
|
|
@ -1,6 +1,7 @@
|
|||
// Package client contains functions for communicating with the API server
|
||||
// Copyright (C) 2020 by Red Hat, Inc.
|
||||
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package client
|
||||
|
|
@ -11,11 +12,15 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/distro/test_distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/distroregistry"
|
||||
"github.com/osbuild/osbuild-composer/internal/dnfjson"
|
||||
dnfjson_mock "github.com/osbuild/osbuild-composer/internal/mocks/dnfjson"
|
||||
rpmmd_mock "github.com/osbuild/osbuild-composer/internal/mocks/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/reporegistry"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
|
|
@ -24,6 +29,20 @@ import (
|
|||
|
||||
// Hold test state to share between tests
|
||||
var testState *TestState
|
||||
var dnfjsonPath string
|
||||
|
||||
func init() {
|
||||
// compile the mock-dnf-json binary to speed up tests
|
||||
tmpdir, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
dnfjsonPath = filepath.Join(tmpdir, "mock-dnf-json")
|
||||
cmd := exec.Command("go", "build", "-o", dnfjsonPath, "../../cmd/mock-dnf-json")
|
||||
if err := cmd.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func executeTests(m *testing.M) int {
|
||||
// Setup the mocked server running on a temporary domain socket
|
||||
|
|
@ -45,7 +64,6 @@ func executeTests(m *testing.M) int {
|
|||
panic(err)
|
||||
}
|
||||
fixture := rpmmd_mock.BaseFixture(path.Join(tmpdir, "/jobs"))
|
||||
rpm := rpmmd_mock.NewRPMMDMock(fixture)
|
||||
|
||||
distro1 := test_distro.New()
|
||||
arch, err := distro1.GetArch(test_distro.TestArchName)
|
||||
|
|
@ -67,8 +85,12 @@ func executeTests(m *testing.M) int {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
dspath, err := os.MkdirTemp(tmpdir, "")
|
||||
dnfjsonFixture := dnfjson_mock.Base(dspath)
|
||||
solver := dnfjson.NewBaseSolver(path.Join(tmpdir, "dnfjson-cache"))
|
||||
solver.SetDNFJSONPath(dnfjsonPath, dnfjsonFixture)
|
||||
logger := log.New(os.Stdout, "", 0)
|
||||
api := weldr.NewTestAPI(rpm, arch, dr, rr, logger, fixture.Store, fixture.Workers, "", nil)
|
||||
api := weldr.NewTestAPI(solver, arch, dr, rr, logger, fixture.Store, fixture.Workers, "", nil)
|
||||
server := http.Server{Handler: api}
|
||||
defer server.Close()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue