Skip to content

Commit

Permalink
Import WithSourceURI logic. Fix fleet test to not skip if the version…
Browse files Browse the repository at this point in the history
…s are different and the commits are the same.
  • Loading branch information
blakerouse authored and ycombinator committed Sep 28, 2023
1 parent 68933f8 commit 800e598
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions testing/integration/upgrade_fleet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func TestFleetManagedUpgrade(t *testing.T) {
require.NoError(t, err)
endVersionInfo, err := endFixture.ExecVersion(ctx)
require.NoError(t, err)
if startVersionInfo.Binary.Commit == endVersionInfo.Binary.Commit {
t.Skipf("Build under test is the same as the build from the artifacts repository (commit: %s)", startVersionInfo.Binary.Commit)
if startVersionInfo.Binary.String() == endVersionInfo.Binary.String() && startVersionInfo.Binary.Commit == endVersionInfo.Binary.Commit {
t.Skipf("Build under test is the same as the build from the artifacts repository (version: %s) [commit: %s]", startVersionInfo.Binary.String(), startVersionInfo.Binary.Commit)
}

t.Logf("Testing Elastic Agent upgrade from %s to %s with Fleet...", define.Version(), endVersionInfo.Binary.String())
Expand Down
2 changes: 2 additions & 0 deletions testing/integration/upgrade_gpg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func TestStandaloneUpgradeWithGPGFallback(t *testing.T) {

err = upgradetest.PerformUpgrade(
ctx, startFixture, endFixture, t,
upgradetest.WithSourceURI(""),
upgradetest.WithCustomPGP(customPGP),
upgradetest.WithSkipVerify(false))
assert.NoError(t, err)
Expand Down Expand Up @@ -125,6 +126,7 @@ func TestStandaloneUpgradeWithGPGFallbackOneRemoteFailing(t *testing.T) {

err = upgradetest.PerformUpgrade(
ctx, startFixture, endFixture, t,
upgradetest.WithSourceURI(""),
upgradetest.WithCustomPGP(customPGP),
upgradetest.WithSkipVerify(false))
}
33 changes: 14 additions & 19 deletions testing/upgradetest/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type CustomPGP struct {
}

type upgradeOpts struct {
sourceURI string
sourceURI *string

skipVerify bool
skipDefaultPgp bool
Expand All @@ -45,7 +45,7 @@ type upgradeOpt func(opts *upgradeOpts)
// in the endFixture variable.
func WithSourceURI(sourceURI string) upgradeOpt {
return func(opts *upgradeOpts) {
opts.sourceURI = sourceURI
opts.sourceURI = &sourceURI
}
}

Expand Down Expand Up @@ -190,25 +190,20 @@ func PerformUpgrade(
logger.Logf("Upgrading from version %q to version %q", startParsedVersion, endVersionInfo.Binary.String())

upgradeCmdArgs := []string{"upgrade", endVersionInfo.Binary.String()}
if upgradeOpts.customPgp == nil {
// unless a custom PGP configuration is provided, upgrade is always using --source-uri
if upgradeOpts.sourceURI != "" {
// specific ---source-uri
upgradeCmdArgs = append(upgradeCmdArgs, "--source-uri", upgradeOpts.sourceURI)
} else {
// --source-uri from the endFixture
srcPkg, err := endFixture.SrcPackage(ctx)
if err != nil {
return fmt.Errorf("failed to get end agent source package path: %w", err)
}
sourceURI := "file://" + filepath.Dir(srcPkg)
upgradeCmdArgs = append(upgradeCmdArgs, "--source-uri", sourceURI)
}
} else {
if upgradeOpts.sourceURI != "" {
upgradeCmdArgs = append(upgradeCmdArgs, "--source-uri", upgradeOpts.sourceURI)
if upgradeOpts.sourceURI == nil {
// no --source-uri set so it comes from the endFixture
srcPkg, err := endFixture.SrcPackage(ctx)
if err != nil {
return fmt.Errorf("failed to get end agent source package path: %w", err)
}
sourceURI := "file://" + filepath.Dir(srcPkg)
upgradeCmdArgs = append(upgradeCmdArgs, "--source-uri", sourceURI)
} else if *upgradeOpts.sourceURI != "" {
// specific ---source-uri
upgradeCmdArgs = append(upgradeCmdArgs, "--source-uri", *upgradeOpts.sourceURI)
}

if upgradeOpts.customPgp != nil {
if len(upgradeOpts.customPgp.PGP) > 0 {
upgradeCmdArgs = append(upgradeCmdArgs, "--pgp", upgradeOpts.customPgp.PGP)
}
Expand Down

0 comments on commit 800e598

Please sign in to comment.