Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit aa8e9ad

Browse files
feat: export Fetch&Download methods in the /pkg directory (#1943) (#1971)
* chore: copy internal's version files into the exported pkg public package * chore: run unit tests from top-level goal * chore: use public package instead of the internal one * chore: remove old internal files for habdling downloads * fix: update missing references (cherry picked from commit 63b6f42) Co-authored-by: Manuel de la Peña <[email protected]>
1 parent 8230d8c commit aa8e9ad

29 files changed

+52
-51
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ notice:
3737
-depsOut ""
3838

3939
.PHONY: unit-test
40-
unit-test: test-report-setup unit-test-dir-cli unit-test-dir-internal
40+
unit-test: test-report-setup unit-test-dir-cli unit-test-dir-internal unit-test-dir-pkg
4141

4242
# See https://pkg.go.dev/gotest.tools/gotestsum/#readme-junit-xml-output
4343
.PHONY: unit-test-suite-%

e2e/_suites/fleet/fleet.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import (
2020

2121
"github.com/cenkalti/backoff/v4"
2222
"github.com/cucumber/godog"
23-
elasticversion "github.com/elastic/e2e-testing/internal"
2423
"github.com/elastic/e2e-testing/internal/common"
2524
"github.com/elastic/e2e-testing/internal/deploy"
2625
"github.com/elastic/e2e-testing/internal/elasticsearch"
2726
"github.com/elastic/e2e-testing/internal/installer"
2827
"github.com/elastic/e2e-testing/internal/kibana"
2928
"github.com/elastic/e2e-testing/internal/shell"
3029
"github.com/elastic/e2e-testing/internal/utils"
30+
"github.com/elastic/e2e-testing/pkg/downloads"
3131

3232
"github.com/pkg/errors"
3333
log "github.com/sirupsen/logrus"
@@ -331,7 +331,7 @@ func (fts *FleetTestSuite) anStaleAgentIsDeployedToFleetWithInstaller(version, i
331331

332332
common.AgentStaleVersion = shell.GetEnv("ELASTIC_AGENT_STALE_VERSION", common.AgentStaleVersion)
333333
// check if stale version is an alias
334-
v, err := elasticversion.GetElasticArtifactVersion(common.AgentStaleVersion)
334+
v, err := downloads.GetElasticArtifactVersion(common.AgentStaleVersion)
335335
if err != nil {
336336
log.WithFields(log.Fields{
337337
"error": err,
@@ -341,7 +341,7 @@ func (fts *FleetTestSuite) anStaleAgentIsDeployedToFleetWithInstaller(version, i
341341
}
342342
common.AgentStaleVersion = v
343343

344-
useCISnapshots := elasticversion.GithubCommitSha1 != ""
344+
useCISnapshots := downloads.GithubCommitSha1 != ""
345345
if useCISnapshots && !strings.HasSuffix(common.AgentStaleVersion, "-SNAPSHOT") {
346346
common.AgentStaleVersion += "-SNAPSHOT"
347347
}
@@ -399,7 +399,7 @@ func (fts *FleetTestSuite) agentInVersion(version string) error {
399399
case "stale":
400400
version = common.AgentStaleVersion
401401
case "latest":
402-
version = elasticversion.GetSnapshotVersion(common.BeatVersion)
402+
version = downloads.GetSnapshotVersion(common.BeatVersion)
403403
}
404404

405405
agentInVersionFn := func() error {

e2e/_suites/fleet/stand-alone.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
"time"
1111

1212
"github.com/cenkalti/backoff/v4"
13-
elasticversion "github.com/elastic/e2e-testing/internal"
1413
"github.com/elastic/e2e-testing/internal/common"
1514
"github.com/elastic/e2e-testing/internal/deploy"
1615
"github.com/elastic/e2e-testing/internal/installer"
1716
"github.com/elastic/e2e-testing/internal/kibana"
1817
"github.com/elastic/e2e-testing/internal/utils"
18+
"github.com/elastic/e2e-testing/pkg/downloads"
1919

2020
"github.com/elastic/e2e-testing/internal/elasticsearch"
2121
log "github.com/sirupsen/logrus"
@@ -90,9 +90,9 @@ func (fts *FleetTestSuite) startStandAloneAgent(image string, flavour string, en
9090
common.ProfileEnv["elasticAgentDockerImageSuffix"] = "-" + image
9191
}
9292

93-
useCISnapshots := elasticversion.GithubCommitSha1 != ""
93+
useCISnapshots := downloads.GithubCommitSha1 != ""
9494

95-
if useCISnapshots || elasticversion.BeatsLocalPath != "" {
95+
if useCISnapshots || downloads.BeatsLocalPath != "" {
9696
// load the docker images that were already:
9797
// a. downloaded from the GCP bucket
9898
// b. fetched from the local beats binaries

e2e/_suites/kubernetes-autodiscover/autodiscover_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ import (
2828
"go.elastic.co/apm"
2929

3030
"github.com/elastic/e2e-testing/cli/config"
31-
elasticversion "github.com/elastic/e2e-testing/internal"
3231
"github.com/elastic/e2e-testing/internal/common"
3332
"github.com/elastic/e2e-testing/internal/deploy"
3433
"github.com/elastic/e2e-testing/internal/kubernetes"
3534
"github.com/elastic/e2e-testing/internal/shell"
3635
"github.com/elastic/e2e-testing/internal/utils"
36+
"github.com/elastic/e2e-testing/pkg/downloads"
3737
)
3838

3939
var beatVersions = map[string]string{}
@@ -133,13 +133,13 @@ func (m *podsManager) configureDockerImage(podName string) error {
133133
return nil
134134
}
135135

136-
beatVersion := elasticversion.GetSnapshotVersion(common.BeatVersion) + "-amd64"
136+
beatVersion := downloads.GetSnapshotVersion(common.BeatVersion) + "-amd64"
137137

138-
useCISnapshots := elasticversion.GithubCommitSha1 != ""
139-
if useCISnapshots || elasticversion.BeatsLocalPath != "" {
138+
useCISnapshots := downloads.GithubCommitSha1 != ""
139+
if useCISnapshots || downloads.BeatsLocalPath != "" {
140140
log.Debugf("Configuring Docker image for %s", podName)
141141

142-
_, imagePath, err := elasticversion.FetchElasticArtifact(m.ctx, podName, common.BeatVersion, "linux", "amd64", "tar.gz", true, true)
142+
_, imagePath, err := downloads.FetchElasticArtifact(m.ctx, podName, common.BeatVersion, "linux", "amd64", "tar.gz", true, true)
143143
if err != nil {
144144
return err
145145
}
@@ -152,7 +152,7 @@ func (m *podsManager) configureDockerImage(podName string) error {
152152

153153
// tag the image with the proper docker tag, including platform
154154
err = deploy.TagImage(
155-
"docker.elastic.co/beats/"+podName+":"+elasticversion.GetSnapshotVersion(common.BeatVersionBase),
155+
"docker.elastic.co/beats/"+podName+":"+downloads.GetSnapshotVersion(common.BeatVersionBase),
156156
"docker.elastic.co/observability-ci/"+podName+":"+beatVersion,
157157
)
158158
if err != nil {

internal/common/defaults.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
package common
66

77
import (
8-
elasticversion "github.com/elastic/e2e-testing/internal"
98
"github.com/elastic/e2e-testing/internal/shell"
9+
"github.com/elastic/e2e-testing/pkg/downloads"
1010
log "github.com/sirupsen/logrus"
1111
)
1212

@@ -81,7 +81,7 @@ func init() {
8181
// supporting lazy-loading the versions when needed. Basically, the CLI part does not
8282
// need to load them
8383
func InitVersions() {
84-
v, err := elasticversion.GetElasticArtifactVersion(BeatVersionBase)
84+
v, err := downloads.GetElasticArtifactVersion(BeatVersionBase)
8585
if err != nil {
8686
log.WithFields(log.Fields{
8787
"error": err,
@@ -93,7 +93,7 @@ func InitVersions() {
9393
BeatVersion = shell.GetEnv("BEAT_VERSION", BeatVersionBase)
9494

9595
// check if version is an alias
96-
v, err = elasticversion.GetElasticArtifactVersion(BeatVersion)
96+
v, err = downloads.GetElasticArtifactVersion(BeatVersion)
9797
if err != nil {
9898
log.WithFields(log.Fields{
9999
"error": err,
@@ -111,10 +111,10 @@ func InitVersions() {
111111
}).Trace("Beat Version provided: will be used as fallback")
112112
fallbackVersion = BeatVersion
113113
}
114-
BeatVersion = elasticversion.CheckPRVersion(BeatVersion, fallbackVersion)
114+
BeatVersion = downloads.CheckPRVersion(BeatVersion, fallbackVersion)
115115

116116
StackVersion = shell.GetEnv("STACK_VERSION", BeatVersionBase)
117-
v, err = elasticversion.GetElasticArtifactVersion(StackVersion)
117+
v, err = downloads.GetElasticArtifactVersion(StackVersion)
118118
if err != nil {
119119
log.WithFields(log.Fields{
120120
"error": err,
@@ -127,7 +127,7 @@ func InitVersions() {
127127
if KibanaVersion == "" {
128128
// we want to deploy a released version for Kibana
129129
// if not set, let's use StackVersion
130-
KibanaVersion, err = elasticversion.GetElasticArtifactVersion(StackVersion)
130+
KibanaVersion, err = downloads.GetElasticArtifactVersion(StackVersion)
131131
if err != nil {
132132
log.WithFields(log.Fields{
133133
"error": err,

internal/deploy/docker.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"path/filepath"
1111
"strings"
1212

13-
elasticversion "github.com/elastic/e2e-testing/internal"
1413
"github.com/elastic/e2e-testing/internal/shell"
14+
"github.com/elastic/e2e-testing/pkg/downloads"
1515
log "github.com/sirupsen/logrus"
1616
"go.elastic.co/apm"
1717
)
@@ -278,8 +278,8 @@ func (c *dockerDeploymentManifest) Stop(ctx context.Context, service ServiceRequ
278278
// the images produced by local Beats build, or not.
279279
// If an error occurred reading the environment, will return the passed namespace as fallback
280280
func GetDockerNamespaceEnvVar(fallback string) string {
281-
useCISnapshots := elasticversion.GithubCommitSha1 != ""
282-
if useCISnapshots || elasticversion.BeatsLocalPath != "" {
281+
useCISnapshots := downloads.GithubCommitSha1 != ""
282+
if useCISnapshots || downloads.BeatsLocalPath != "" {
283283
return "observability-ci"
284284
}
285285
return fallback

internal/deploy/docker_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ package deploy
77
import (
88
"testing"
99

10-
elasticversion "github.com/elastic/e2e-testing/internal"
11-
10+
"github.com/elastic/e2e-testing/pkg/downloads"
1211
"github.com/stretchr/testify/assert"
1312
)
1413

@@ -19,8 +18,8 @@ func TestGetDockerNamespaceEnvVar(t *testing.T) {
1918
})
2019

2120
t.Run("Returns Observability CI when environment variable is set", func(t *testing.T) {
22-
elasticversion.GithubCommitSha1 = "0123456789"
23-
defer func() { elasticversion.GithubCommitSha1 = "" }()
21+
downloads.GithubCommitSha1 = "0123456789"
22+
defer func() { downloads.GithubCommitSha1 = "" }()
2423

2524
namespace := GetDockerNamespaceEnvVar("beats")
2625
assert.True(t, namespace == "observability-ci")

internal/installer/elasticagent_deb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
"fmt"
1010
"strings"
1111

12-
elasticversion "github.com/elastic/e2e-testing/internal"
1312
"github.com/elastic/e2e-testing/internal/common"
1413
"github.com/elastic/e2e-testing/internal/deploy"
1514
"github.com/elastic/e2e-testing/internal/kibana"
1615
"github.com/elastic/e2e-testing/internal/utils"
16+
"github.com/elastic/e2e-testing/pkg/downloads"
1717
log "github.com/sirupsen/logrus"
1818
"go.elastic.co/apm"
1919
)
@@ -142,7 +142,7 @@ func (i *elasticAgentDEBPackage) Preinstall(ctx context.Context) error {
142142
arch := utils.GetArchitecture()
143143
extension := "deb"
144144

145-
binaryName, binaryPath, err := elasticversion.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, false, true)
145+
binaryName, binaryPath, err := downloads.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, false, true)
146146
if err != nil {
147147
log.WithFields(log.Fields{
148148
"artifact": artifact,

internal/installer/elasticagent_docker.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"context"
99
"fmt"
1010

11-
elasticversion "github.com/elastic/e2e-testing/internal"
1211
"github.com/elastic/e2e-testing/internal/common"
1312
"github.com/elastic/e2e-testing/internal/deploy"
1413
"github.com/elastic/e2e-testing/internal/utils"
14+
"github.com/elastic/e2e-testing/pkg/downloads"
1515
log "github.com/sirupsen/logrus"
1616
"go.elastic.co/apm"
1717
)
@@ -99,7 +99,7 @@ func (i *elasticAgentDockerPackage) Preinstall(ctx context.Context) error {
9999
arch := utils.GetArchitecture()
100100
extension := "tar.gz"
101101

102-
_, binaryPath, err := elasticversion.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, true, true)
102+
_, binaryPath, err := downloads.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, true, true)
103103
if err != nil {
104104
log.WithFields(log.Fields{
105105
"artifact": artifact,
@@ -119,10 +119,10 @@ func (i *elasticAgentDockerPackage) Preinstall(ctx context.Context) error {
119119

120120
// we need to tag the loaded image because its tag relates to the target branch
121121
return deploy.TagImage(
122-
fmt.Sprintf("docker.elastic.co/beats/%s:%s", artifact, elasticversion.GetSnapshotVersion(common.BeatVersionBase)),
123-
fmt.Sprintf("docker.elastic.co/observability-ci/%s:%s-%s", artifact, elasticversion.GetSnapshotVersion(common.BeatVersion), arch),
122+
fmt.Sprintf("docker.elastic.co/beats/%s:%s", artifact, downloads.GetSnapshotVersion(common.BeatVersionBase)),
123+
fmt.Sprintf("docker.elastic.co/observability-ci/%s:%s-%s", artifact, downloads.GetSnapshotVersion(common.BeatVersion), arch),
124124
// tagging including git commit and snapshot
125-
fmt.Sprintf("docker.elastic.co/observability-ci/%s:%s-%s", artifact, elasticversion.GetFullVersion(common.BeatVersion), arch),
125+
fmt.Sprintf("docker.elastic.co/observability-ci/%s:%s-%s", artifact, downloads.GetFullVersion(common.BeatVersion), arch),
126126
)
127127
}
128128

internal/installer/elasticagent_rpm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
"fmt"
1010
"strings"
1111

12-
elasticversion "github.com/elastic/e2e-testing/internal"
1312
"github.com/elastic/e2e-testing/internal/common"
1413
"github.com/elastic/e2e-testing/internal/deploy"
1514
"github.com/elastic/e2e-testing/internal/kibana"
1615
"github.com/elastic/e2e-testing/internal/utils"
16+
"github.com/elastic/e2e-testing/pkg/downloads"
1717
log "github.com/sirupsen/logrus"
1818
"go.elastic.co/apm"
1919
)
@@ -146,7 +146,7 @@ func (i *elasticAgentRPMPackage) Preinstall(ctx context.Context) error {
146146
}
147147
extension := "rpm"
148148

149-
binaryName, binaryPath, err := elasticversion.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, false, true)
149+
binaryName, binaryPath, err := downloads.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, false, true)
150150
if err != nil {
151151
log.WithFields(log.Fields{
152152
"artifact": artifact,

0 commit comments

Comments
 (0)