From d55869484332108b060ebe31bbca779706e77fc4 Mon Sep 17 00:00:00 2001 From: Denis Date: Sat, 23 Mar 2024 17:42:39 +0100 Subject: [PATCH] Avoid using the artifact API for test-cases where it's not needed (#4468) `TestStandaloneUpgradeRetryDownload` and `TestStandaloneUpgradeUninstallKillWatcher` don't require to have a build version for the actual test. These test cases should be fine with any version that does not match the current commit hash. The previous minor version is guaranteed to not match the hash. --- .../upgrade_standalone_retry_test.go | 24 ++++--------------- testing/integration/upgrade_uninstall_test.go | 17 +++---------- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/testing/integration/upgrade_standalone_retry_test.go b/testing/integration/upgrade_standalone_retry_test.go index fcd12be2214..a062dd14d24 100644 --- a/testing/integration/upgrade_standalone_retry_test.go +++ b/testing/integration/upgrade_standalone_retry_test.go @@ -8,7 +8,6 @@ package integration import ( "context" - "errors" "fmt" "net" "net/http" @@ -23,9 +22,7 @@ import ( atesting "github.com/elastic/elastic-agent/pkg/testing" "github.com/elastic/elastic-agent/pkg/testing/define" - "github.com/elastic/elastic-agent/pkg/testing/tools" "github.com/elastic/elastic-agent/pkg/testing/tools/testcontext" - "github.com/elastic/elastic-agent/pkg/version" "github.com/elastic/elastic-agent/testing/upgradetest" ) @@ -41,27 +38,16 @@ func TestStandaloneUpgradeRetryDownload(t *testing.T) { // Start at the build version as we want to test the retry // logic that is in the build. - startVersion, err := version.ParseVersion(define.Version()) - require.NoError(t, err) startFixture, err := define.NewFixture(t, define.Version()) require.NoError(t, err) - startVersionInfo, err := startFixture.ExecVersion(ctx) - require.NoError(t, err, "failed to get end agent build version info") - - // Upgrade to an older snapshot build of same version but with a different commit hash - aac := tools.NewArtifactAPIClient(tools.WithLogFunc(t.Logf)) - buildInfo, err := aac.FindBuild(ctx, startVersion.VersionWithPrerelease(), startVersionInfo.Binary.Commit, 0) - if errors.Is(err, tools.ErrBuildNotFound) { - t.Skipf("there is no other build with a non-matching commit hash in the given version %s", define.Version()) - return - } - require.NoError(t, err) - t.Logf("found build %q available for testing", buildInfo.Build.BuildID) - endVersion := versionWithBuildID(t, startVersion, buildInfo.Build.BuildID) + // The end version does not matter much but it must not match + // the commit hash of the current build. + endVersion, err := upgradetest.PreviousMinor() + require.NoError(t, err) endFixture, err := atesting.NewFixture( t, - endVersion, + endVersion.String(), atesting.WithFetcher(atesting.ArtifactFetcher()), ) require.NoError(t, err) diff --git a/testing/integration/upgrade_uninstall_test.go b/testing/integration/upgrade_uninstall_test.go index 9f26c49bc47..d7ad0964d4f 100644 --- a/testing/integration/upgrade_uninstall_test.go +++ b/testing/integration/upgrade_uninstall_test.go @@ -20,7 +20,6 @@ import ( atesting "github.com/elastic/elastic-agent/pkg/testing" "github.com/elastic/elastic-agent/pkg/testing/define" - "github.com/elastic/elastic-agent/pkg/testing/tools" "github.com/elastic/elastic-agent/testing/upgradetest" ) @@ -41,8 +40,6 @@ func TestStandaloneUpgradeUninstallKillWatcher(t *testing.T) { defer cancel() // Upgrades to build under test. - endVersion, err := version.ParseVersion(define.Version()) - require.NoError(t, err) endFixture, err := define.NewFixture(t, define.Version()) require.NoError(t, err) endVersionInfo, err := endFixture.ExecVersion(ctx) @@ -50,20 +47,12 @@ func TestStandaloneUpgradeUninstallKillWatcher(t *testing.T) { // Start on a snapshot build, we want this test to upgrade to our // build to ensure that the uninstall will kill the watcher. - // We need a snapshot with a non-matching commit hash to perform the upgrade - aac := tools.NewArtifactAPIClient(tools.WithLogFunc(t.Logf)) - buildInfo, err := aac.FindBuild(ctx, endVersion.VersionWithPrerelease(), endVersionInfo.Binary.Commit, 0) - if errors.Is(err, tools.ErrBuildNotFound) { - t.Skipf("there is no other build with a non-matching commit hash in the given version %s", endVersion.VersionWithPrerelease()) - return - } + // We need a version with a non-matching commit hash to perform the upgrade + startVersion, err := upgradetest.PreviousMinor() require.NoError(t, err) - - t.Logf("found build %q available for testing", buildInfo.Build.BuildID) - startVersion := versionWithBuildID(t, endVersion, buildInfo.Build.BuildID) startFixture, err := atesting.NewFixture( t, - startVersion, + startVersion.String(), atesting.WithFetcher(atesting.ArtifactFetcher()), ) require.NoError(t, err)