@@ -8,6 +8,7 @@ package integration
8
8
9
9
import (
10
10
"context"
11
+ "errors"
11
12
"strings"
12
13
"testing"
13
14
"time"
@@ -23,10 +24,6 @@ import (
23
24
"github.com/elastic/elastic-agent/testing/upgradetest"
24
25
)
25
26
26
- const (
27
- artifactElasticAgentProject = "elastic-agent-package"
28
- )
29
-
30
27
func TestStandaloneDowngradeToSpecificSnapshotBuild (t * testing.T ) {
31
28
define .Require (t , define.Requirements {
32
29
Group : Upgrade ,
@@ -61,54 +58,24 @@ func TestStandaloneDowngradeToSpecificSnapshotBuild(t *testing.T) {
61
58
// as the currently running binary (so, we don't have a file system collision).
62
59
// Multiple builds can have different IDs but the same commit hash.
63
60
preReleaseVersion := latestSnapshotVersion .VersionWithPrerelease ()
64
- resp , err := aac .GetBuildsForVersion (ctx , preReleaseVersion )
65
- require .NoError (t , err )
66
-
67
- if len (resp .Builds ) < 2 {
68
- t .Skipf ("need at least 2 builds in the version %s" , latestSnapshotVersion .VersionWithPrerelease ())
69
- return
70
- }
71
-
72
- t .Logf ("found %d builds for version %q" , len (resp .Builds ), preReleaseVersion )
73
-
74
- t .Logf ("looking for a build that does not match the current commit hash %q" , startVersion .Binary .Commit )
75
- var upgradeVersionString string
76
- for _ , buildID := range resp .Builds [1 :] {
77
- details , err := aac .GetBuildDetails (ctx , preReleaseVersion , buildID )
78
- require .NoError (t , err )
79
- if details .Build .Projects [artifactElasticAgentProject ].CommitHash != startVersion .Binary .Commit {
80
- upgradeVersionString = buildID
81
- break
82
- }
83
- t .Logf ("build %q matches the current commit hash %q, skipping..." , buildID , startVersion .Binary .Commit )
84
- }
85
-
86
- if upgradeVersionString == "" {
61
+ buildInfo , err := aac .FindBuild (ctx , preReleaseVersion , startVersion .Binary .Commit , 1 )
62
+ if errors .Is (err , tools .ErrBuildNotFound ) {
87
63
t .Skipf ("there is no other build with a non-matching commit hash in the given version %s" , latestSnapshotVersion .VersionWithPrerelease ())
88
64
return
89
65
}
90
-
91
- t .Logf ("found build %q available for testing" , upgradeVersionString )
92
-
93
- buildFragments := strings .Split (upgradeVersionString , "-" )
94
- require .Lenf (t , buildFragments , 2 , "version %q returned by artifact api is not in format <version>-<buildID>" , upgradeVersionString )
95
- endParsedVersion := version .NewParsedSemVer (
96
- latestSnapshotVersion .Major (),
97
- latestSnapshotVersion .Minor (),
98
- latestSnapshotVersion .Patch (),
99
- latestSnapshotVersion .Prerelease (),
100
- buildFragments [1 ],
101
- )
66
+ require .NoError (t , err )
102
67
103
68
// Upgrade to the specific build.
69
+ t .Logf ("found build %q available for testing" , buildInfo .Build .BuildID )
70
+ endVersion := versionWithBuildID (t , latestSnapshotVersion , buildInfo .Build .BuildID )
104
71
endFixture , err := atesting .NewFixture (
105
72
t ,
106
- endParsedVersion . String () ,
73
+ endVersion ,
107
74
atesting .WithFetcher (atesting .ArtifactFetcher ()),
108
75
)
109
76
require .NoError (t , err )
110
77
111
- t .Logf ("Testing Elastic Agent upgrade from %s to %s..." , define .Version (), endParsedVersion . String () )
78
+ t .Logf ("Testing Elastic Agent upgrade from %s to %s..." , define .Version (), endVersion )
112
79
113
80
// We pass the upgradetest.WithDisableUpgradeWatcherUpgradeDetailsCheck option here because the endFixture
114
81
// is fetched from the artifacts API and it may not contain changes in the Upgrade Watcher whose effects are
@@ -117,3 +84,19 @@ func TestStandaloneDowngradeToSpecificSnapshotBuild(t *testing.T) {
117
84
err = upgradetest .PerformUpgrade (ctx , startFixture , endFixture , t , upgradetest .WithDisableUpgradeWatcherUpgradeDetailsCheck ())
118
85
assert .NoError (t , err )
119
86
}
87
+
88
+ // versionWithBuildID creates a new parsed version created from the given `initialVersion` with the given `buildID` as build metadata.
89
+ func versionWithBuildID (t * testing.T , initialVersion * version.ParsedSemVer , buildID string ) string {
90
+ buildFragments := strings .Split (buildID , "-" )
91
+ require .Lenf (t , buildFragments , 2 , "version %q returned by artifact api is not in format <version>-<buildID>" , buildID )
92
+ result := version .NewParsedSemVer (
93
+ initialVersion .Major (),
94
+ initialVersion .Minor (),
95
+ initialVersion .Patch (),
96
+ initialVersion .Prerelease (),
97
+ buildFragments [1 ],
98
+ )
99
+
100
+ return result .String ()
101
+
102
+ }
0 commit comments