From d1a0420cba9bd53b9e3c57bb2727d162f58b77fd Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 10:28:18 +0000 Subject: [PATCH] skip downgrade test when only one snapshot version is available (#3293) (#3297) It fixes TestStandaloneUpgradeToSpecificSnapshotBuild to work when there is only one snapshot build available by skipping the test if there aren't enough versions available. (cherry picked from commit 22c276ddc2241bb73322c7968edef9a9d7091f43) Co-authored-by: Anderson Queiroz --- pkg/testing/tools/artifacts_api.go | 7 ++++--- testing/integration/upgrade_test.go | 11 ++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/testing/tools/artifacts_api.go b/pkg/testing/tools/artifacts_api.go index e99d4c527ec..84fdf226df1 100644 --- a/pkg/testing/tools/artifacts_api.go +++ b/pkg/testing/tools/artifacts_api.go @@ -23,7 +23,7 @@ const ( artifactsAPIV1VersionsEndpoint = "v1/versions/" artifactsAPIV1VersionBuildsEndpoint = "v1/versions/%s/builds/" artifactAPIV1BuildDetailsEndpoint = "v1/versions/%s/builds/%s" - //artifactAPIV1SearchVersionPackage = "v1/search/%s/%s" + // artifactAPIV1SearchVersionPackage = "v1/search/%s/%s" ) var ( @@ -275,8 +275,9 @@ func GetLatestSnapshotVersion(ctx context.Context, log logger, aac *ArtifactAPIC return nil, ErrSnapshotVersionsEmpty } - // normally the output of the versions returned by artifact API is already sorted in ascending order, - // if we want to sort in descending order we could use + // normally the output of the versions returned by artifact API is already + // sorted in ascending order.If we want to sort in descending order we need + // to pass a sort.Reverse to sort.Sort. sort.Sort(sort.Reverse(sortedParsedVersions)) var latestSnapshotVersion *version.ParsedSemVer diff --git a/testing/integration/upgrade_test.go b/testing/integration/upgrade_test.go index 798b842b216..df3d4094129 100644 --- a/testing/integration/upgrade_test.go +++ b/testing/integration/upgrade_test.go @@ -338,7 +338,7 @@ func TestStandaloneUpgradeWithGPGFallbackOneRemoteFailing(t *testing.T) { testStandaloneUpgrade(ctx, t, agentFixture, fromVersion, toVersion, "", false, false, true, customPGP) } -func TestStandaloneUpgradeToSpecificSnapshotBuild(t *testing.T) { +func TestStandaloneDowngradeToPreviousSnapshotBuild(t *testing.T) { define.Require(t, define.Requirements{ Local: false, // requires Agent installation Sudo: true, // requires Agent installation @@ -350,7 +350,6 @@ func TestStandaloneUpgradeToSpecificSnapshotBuild(t *testing.T) { t.Skipf("Version %s is lower than min version %s", define.Version(), minVersion) } - // prepare the agent fixture agentFixture, err := define.NewFixture(t, define.Version()) require.NoError(t, err) @@ -370,10 +369,12 @@ func TestStandaloneUpgradeToSpecificSnapshotBuild(t *testing.T) { // get all the builds of the snapshot version (need to pass x.y.z-SNAPSHOT format) builds, err := aac.GetBuildsForVersion(ctx, latestSnapshotVersion.VersionWithPrerelease()) require.NoError(t, err) - // TODO if we don't have at least 2 builds, select the next older snapshot build - require.Greater(t, len(builds.Builds), 1) - // take the penultimate build of the snapshot (the builds are ordered from most to least recent) + if len(builds.Builds) < 2 { + t.Skip("there is only one SNAPSHOT version available, " + + "the test requires at least 2 so it can downgrade to the previous" + + "SNAPSHOT") + } upgradeVersionString := builds.Builds[1] t.Logf("Targeting build %q of version %q", upgradeVersionString, latestSnapshotVersion)