Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip downgrade test when only one snapshot version is available #3293

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pkg/testing/tools/artifacts_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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.
Comment on lines +278 to +280
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing the meaning of this comment maybe we can clarify the wording a bit like

Suggested change
// 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.
// normally the output of the versions returned by artifact API is already
// sorted in ascending order. Since we want to extract the most recent version,
// we sort in descending order by passing a sort.Reverse operator to sort.Sort.

sort.Sort(sort.Reverse(sortedParsedVersions))

var latestSnapshotVersion *version.ParsedSemVer
Expand Down
11 changes: 6 additions & 5 deletions testing/integration/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func TestStandaloneUpgradeWithGPGFallback(t *testing.T) {
testStandaloneUpgrade(ctx, t, agentFixture, parsedVersion, toVersion, "", false, false, true, customPGP)
}

func TestStandaloneUpgradeToSpecificSnapshotBuild(t *testing.T) {
func TestStandaloneDowngradeToPreviousSnapshotBuild(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep the previous test name as it's the feature name. we may add a comment for clarity

Suggested change
func TestStandaloneDowngradeToPreviousSnapshotBuild(t *testing.T) {
// Here we test the ability of elastic agent to upgrade to a given snapshot build (not necessarily the latest)
// by passing a version `x.y.z-SNAPSHOT+<buildid>`. In order to test this, we look for a build for the current
// snapshot version other than the latest, downgrade to such version and verify that we get the correct
// git commit hash for the specified build (to detect that we didn't install the latest snapshot build by mistake)
func TestStandaloneDowngradeToSpecificSnapshotBuild(t *testing.T) {

define.Require(t, define.Requirements{
Local: false, // requires Agent installation
Sudo: true, // requires Agent installation
Expand All @@ -273,7 +273,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)

Expand All @@ -293,10 +292,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)
Expand Down