Skip to content

Commit

Permalink
Avoid using the artifact API for test-cases where it's not needed (#4468
Browse files Browse the repository at this point in the history
)

`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.
  • Loading branch information
rdner authored Mar 23, 2024
1 parent 8b31b95 commit d558694
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
24 changes: 5 additions & 19 deletions testing/integration/upgrade_standalone_retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package integration

import (
"context"
"errors"
"fmt"
"net"
"net/http"
Expand All @@ -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"
)

Expand All @@ -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)
Expand Down
17 changes: 3 additions & 14 deletions testing/integration/upgrade_uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -41,29 +40,19 @@ 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)
require.NoError(t, err, "failed to get end agent build version info")

// 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)
Expand Down

0 comments on commit d558694

Please sign in to comment.