From fa0d8008500b2ef7db06449e02f22ccb33710a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Wed, 10 Jun 2020 13:23:51 +0200 Subject: [PATCH] test: add a test-case to prevent bad multilib depsolves When gsl with version * was specified in the blueprint, composer depsolved both x86_64 and i686 version of gsl. This test case should prevent this from happening. gsl is used because it has x86_64 and i686 versions on both RHEL and Fedora. Also, gsl-devel package exists, which is not dependant on gsl and shouldn't be depsolved. --- internal/client/blueprints_test.go | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/internal/client/blueprints_test.go b/internal/client/blueprints_test.go index e0b6ca844..35ccc975b 100644 --- a/internal/client/blueprints_test.go +++ b/internal/client/blueprints_test.go @@ -11,10 +11,13 @@ package client import ( + "encoding/json" "sort" + "strings" "testing" "github.com/BurntSushi/toml" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -916,6 +919,51 @@ func TestBlueprintDepsolveV0(t *testing.T) { } +// When gsl with version * was specified in the blueprint, +// composer depsolved both x86_64 and i686 version of gsl. +// This test case should prevent this from happening. +// gsl is used because it has x86_64 and i686 versions on both RHEL and Fedora. +// Also, gsl-devel package exists, which is not dependant on gsl and shouldn't +// be depsolved. +func TestMultilibBlueprintDepsolveV0(t *testing.T) { + if testState.unitTest { + t.Skip() + } + versionStrings := []string{"*", "2.*", ""} + for _, versionString := range versionStrings { + t.Run(versionString, func(t *testing.T) { + bp := `{ + "name": "test-multilib-deps-blueprint-v0", + "description": "CheckBlueprintDepsolveV0", + "version": "0.0.1", + "packages": [{"name": "gsl", "version": "` + versionString + `"}] + }` + + resp, err := PostJSONBlueprintV0(testState.socket, bp) + require.NoError(t, err, "POST blueprint failed with a client error") + require.True(t, resp.Status, "POST blueprint failed: %#v", resp) + + deps, api, err := DepsolveBlueprintV0(testState.socket, "test-multilib-deps-blueprint-v0") + require.NoError(t, err, "Depsolve blueprint failed with a client error") + require.Nil(t, api, "DepsolveBlueprint failed: %#v", api) + + gslCount := 0 + for _, dep := range deps.Blueprints[0].Dependencies { + if strings.HasPrefix(dep.Name, "gsl") { + gslCount += 1 + } + } + + if !assert.Equalf(t, 1, gslCount, "gsl is specified %d-times in the depsolve, should be there only once", gslCount) { + depsolveOutput, err := json.MarshalIndent(deps, "", " ") + require.NoError(t, err) + t.Logf("depsolve output:\n%s", depsolveOutput) + t.FailNow() + } + }) + } +} + // depsolve a non-existent blueprint func TestNonBlueprintDepsolveV0(t *testing.T) { resp, api, err := DepsolveBlueprintV0(testState.socket, "test-deps-non-blueprint-v0")