From 63b6f427cf904ddc9a54e1fd8d5f33c8a6bf410d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Tue, 4 Jan 2022 09:05:18 +0100 Subject: [PATCH] feat: export Fetch&Download methods in the /pkg directory (#1943) * 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 --- Makefile | 2 +- e2e/_suites/fleet/fleet.go | 8 ++++---- e2e/_suites/fleet/stand-alone.go | 6 +++--- .../kubernetes-autodiscover/autodiscover_test.go | 12 ++++++------ internal/common/defaults.go | 12 ++++++------ internal/deploy/docker.go | 6 +++--- internal/deploy/docker_test.go | 7 +++---- internal/installer/elasticagent_deb.go | 4 ++-- internal/installer/elasticagent_docker.go | 10 +++++----- internal/installer/elasticagent_rpm.go | 4 ++-- internal/installer/elasticagent_tar.go | 6 +++--- internal/installer/elasticagent_tar_macos.go | 6 +++--- internal/installer/elasticagent_zip.go | 6 +++--- .../elastic-agent-BEATS_VERSION-aarch64.rpm | 0 .../elastic-agent-BEATS_VERSION-amd64.deb | 0 .../elastic-agent-BEATS_VERSION-arm64.deb | 0 ...tic-agent-BEATS_VERSION-linux-amd64.docker.tar.gz | 0 .../elastic-agent-BEATS_VERSION-linux-amd64.tar.gz | 0 ...tic-agent-BEATS_VERSION-linux-arm64.docker.tar.gz | 0 .../elastic-agent-BEATS_VERSION-linux-arm64.tar.gz | 0 .../elastic-agent-BEATS_VERSION-linux-x86_64.tar.gz | 0 .../elastic-agent-BEATS_VERSION-x86_64.rpm | 0 ...gent-ubi8-BEATS_VERSION-linux-amd64.docker.tar.gz | 0 ...gent-ubi8-BEATS_VERSION-linux-arm64.docker.tar.gz | 0 {internal => pkg}/_testresources/gcp/commits.json | 0 .../_testresources/gcp/nextPageParam.json | 0 {internal => pkg}/_testresources/gcp/snapshots.json | 0 {internal => pkg/downloads}/versions.go | 2 +- {internal => pkg/downloads}/versions_test.go | 12 +++++++----- 29 files changed, 52 insertions(+), 51 deletions(-) rename {internal => pkg}/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-aarch64.rpm (100%) rename {internal => pkg}/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-amd64.deb (100%) rename {internal => pkg}/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-arm64.deb (100%) rename {internal => pkg}/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-amd64.docker.tar.gz (100%) rename {internal => pkg}/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-amd64.tar.gz (100%) rename {internal => pkg}/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-arm64.docker.tar.gz (100%) rename {internal => pkg}/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-arm64.tar.gz (100%) rename {internal => pkg}/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-x86_64.tar.gz (100%) rename {internal => pkg}/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-x86_64.rpm (100%) rename {internal => pkg}/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-ubi8-BEATS_VERSION-linux-amd64.docker.tar.gz (100%) rename {internal => pkg}/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-ubi8-BEATS_VERSION-linux-arm64.docker.tar.gz (100%) rename {internal => pkg}/_testresources/gcp/commits.json (100%) rename {internal => pkg}/_testresources/gcp/nextPageParam.json (100%) rename {internal => pkg}/_testresources/gcp/snapshots.json (100%) rename {internal => pkg/downloads}/versions.go (99%) rename {internal => pkg/downloads}/versions_test.go (98%) diff --git a/Makefile b/Makefile index 6bb5ccfbb6..8080147bd0 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ notice: -depsOut "" .PHONY: unit-test -unit-test: test-report-setup unit-test-dir-cli unit-test-dir-internal +unit-test: test-report-setup unit-test-dir-cli unit-test-dir-internal unit-test-dir-pkg # See https://pkg.go.dev/gotest.tools/gotestsum/#readme-junit-xml-output .PHONY: unit-test-suite-% diff --git a/e2e/_suites/fleet/fleet.go b/e2e/_suites/fleet/fleet.go index 7d4fc0884e..fca9acbae7 100644 --- a/e2e/_suites/fleet/fleet.go +++ b/e2e/_suites/fleet/fleet.go @@ -20,7 +20,6 @@ import ( "github.com/cenkalti/backoff/v4" "github.com/cucumber/godog" - elasticversion "github.com/elastic/e2e-testing/internal" "github.com/elastic/e2e-testing/internal/common" "github.com/elastic/e2e-testing/internal/deploy" "github.com/elastic/e2e-testing/internal/elasticsearch" @@ -28,6 +27,7 @@ import ( "github.com/elastic/e2e-testing/internal/kibana" "github.com/elastic/e2e-testing/internal/shell" "github.com/elastic/e2e-testing/internal/utils" + "github.com/elastic/e2e-testing/pkg/downloads" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -331,7 +331,7 @@ func (fts *FleetTestSuite) anStaleAgentIsDeployedToFleetWithInstaller(version, i common.AgentStaleVersion = shell.GetEnv("ELASTIC_AGENT_STALE_VERSION", common.AgentStaleVersion) // check if stale version is an alias - v, err := elasticversion.GetElasticArtifactVersion(common.AgentStaleVersion) + v, err := downloads.GetElasticArtifactVersion(common.AgentStaleVersion) if err != nil { log.WithFields(log.Fields{ "error": err, @@ -341,7 +341,7 @@ func (fts *FleetTestSuite) anStaleAgentIsDeployedToFleetWithInstaller(version, i } common.AgentStaleVersion = v - useCISnapshots := elasticversion.GithubCommitSha1 != "" + useCISnapshots := downloads.GithubCommitSha1 != "" if useCISnapshots && !strings.HasSuffix(common.AgentStaleVersion, "-SNAPSHOT") { common.AgentStaleVersion += "-SNAPSHOT" } @@ -399,7 +399,7 @@ func (fts *FleetTestSuite) agentInVersion(version string) error { case "stale": version = common.AgentStaleVersion case "latest": - version = elasticversion.GetSnapshotVersion(common.BeatVersion) + version = downloads.GetSnapshotVersion(common.BeatVersion) } agentInVersionFn := func() error { diff --git a/e2e/_suites/fleet/stand-alone.go b/e2e/_suites/fleet/stand-alone.go index f58528a3fa..d4ea843a64 100644 --- a/e2e/_suites/fleet/stand-alone.go +++ b/e2e/_suites/fleet/stand-alone.go @@ -10,12 +10,12 @@ import ( "time" "github.com/cenkalti/backoff/v4" - elasticversion "github.com/elastic/e2e-testing/internal" "github.com/elastic/e2e-testing/internal/common" "github.com/elastic/e2e-testing/internal/deploy" "github.com/elastic/e2e-testing/internal/installer" "github.com/elastic/e2e-testing/internal/kibana" "github.com/elastic/e2e-testing/internal/utils" + "github.com/elastic/e2e-testing/pkg/downloads" "github.com/elastic/e2e-testing/internal/elasticsearch" log "github.com/sirupsen/logrus" @@ -90,9 +90,9 @@ func (fts *FleetTestSuite) startStandAloneAgent(image string, flavour string, en common.ProfileEnv["elasticAgentDockerImageSuffix"] = "-" + image } - useCISnapshots := elasticversion.GithubCommitSha1 != "" + useCISnapshots := downloads.GithubCommitSha1 != "" - if useCISnapshots || elasticversion.BeatsLocalPath != "" { + if useCISnapshots || downloads.BeatsLocalPath != "" { // load the docker images that were already: // a. downloaded from the GCP bucket // b. fetched from the local beats binaries diff --git a/e2e/_suites/kubernetes-autodiscover/autodiscover_test.go b/e2e/_suites/kubernetes-autodiscover/autodiscover_test.go index 097e85a3d7..c59583a689 100644 --- a/e2e/_suites/kubernetes-autodiscover/autodiscover_test.go +++ b/e2e/_suites/kubernetes-autodiscover/autodiscover_test.go @@ -28,12 +28,12 @@ import ( "go.elastic.co/apm" "github.com/elastic/e2e-testing/cli/config" - elasticversion "github.com/elastic/e2e-testing/internal" "github.com/elastic/e2e-testing/internal/common" "github.com/elastic/e2e-testing/internal/deploy" "github.com/elastic/e2e-testing/internal/kubernetes" "github.com/elastic/e2e-testing/internal/shell" "github.com/elastic/e2e-testing/internal/utils" + "github.com/elastic/e2e-testing/pkg/downloads" ) var beatVersions = map[string]string{} @@ -133,13 +133,13 @@ func (m *podsManager) configureDockerImage(podName string) error { return nil } - beatVersion := elasticversion.GetSnapshotVersion(common.BeatVersion) + "-amd64" + beatVersion := downloads.GetSnapshotVersion(common.BeatVersion) + "-amd64" - useCISnapshots := elasticversion.GithubCommitSha1 != "" - if useCISnapshots || elasticversion.BeatsLocalPath != "" { + useCISnapshots := downloads.GithubCommitSha1 != "" + if useCISnapshots || downloads.BeatsLocalPath != "" { log.Debugf("Configuring Docker image for %s", podName) - _, imagePath, err := elasticversion.FetchElasticArtifact(m.ctx, podName, common.BeatVersion, "linux", "amd64", "tar.gz", true, true) + _, imagePath, err := downloads.FetchElasticArtifact(m.ctx, podName, common.BeatVersion, "linux", "amd64", "tar.gz", true, true) if err != nil { return err } @@ -152,7 +152,7 @@ func (m *podsManager) configureDockerImage(podName string) error { // tag the image with the proper docker tag, including platform err = deploy.TagImage( - "docker.elastic.co/beats/"+podName+":"+elasticversion.GetSnapshotVersion(common.BeatVersionBase), + "docker.elastic.co/beats/"+podName+":"+downloads.GetSnapshotVersion(common.BeatVersionBase), "docker.elastic.co/observability-ci/"+podName+":"+beatVersion, ) if err != nil { diff --git a/internal/common/defaults.go b/internal/common/defaults.go index a8c711b281..fd32561b98 100644 --- a/internal/common/defaults.go +++ b/internal/common/defaults.go @@ -5,8 +5,8 @@ package common import ( - elasticversion "github.com/elastic/e2e-testing/internal" "github.com/elastic/e2e-testing/internal/shell" + "github.com/elastic/e2e-testing/pkg/downloads" log "github.com/sirupsen/logrus" ) @@ -81,7 +81,7 @@ func init() { // supporting lazy-loading the versions when needed. Basically, the CLI part does not // need to load them func InitVersions() { - v, err := elasticversion.GetElasticArtifactVersion(BeatVersionBase) + v, err := downloads.GetElasticArtifactVersion(BeatVersionBase) if err != nil { log.WithFields(log.Fields{ "error": err, @@ -93,7 +93,7 @@ func InitVersions() { BeatVersion = shell.GetEnv("BEAT_VERSION", BeatVersionBase) // check if version is an alias - v, err = elasticversion.GetElasticArtifactVersion(BeatVersion) + v, err = downloads.GetElasticArtifactVersion(BeatVersion) if err != nil { log.WithFields(log.Fields{ "error": err, @@ -111,10 +111,10 @@ func InitVersions() { }).Trace("Beat Version provided: will be used as fallback") fallbackVersion = BeatVersion } - BeatVersion = elasticversion.CheckPRVersion(BeatVersion, fallbackVersion) + BeatVersion = downloads.CheckPRVersion(BeatVersion, fallbackVersion) StackVersion = shell.GetEnv("STACK_VERSION", BeatVersionBase) - v, err = elasticversion.GetElasticArtifactVersion(StackVersion) + v, err = downloads.GetElasticArtifactVersion(StackVersion) if err != nil { log.WithFields(log.Fields{ "error": err, @@ -127,7 +127,7 @@ func InitVersions() { if KibanaVersion == "" { // we want to deploy a released version for Kibana // if not set, let's use StackVersion - KibanaVersion, err = elasticversion.GetElasticArtifactVersion(StackVersion) + KibanaVersion, err = downloads.GetElasticArtifactVersion(StackVersion) if err != nil { log.WithFields(log.Fields{ "error": err, diff --git a/internal/deploy/docker.go b/internal/deploy/docker.go index 91e97cd37f..d77cb7588c 100644 --- a/internal/deploy/docker.go +++ b/internal/deploy/docker.go @@ -10,8 +10,8 @@ import ( "path/filepath" "strings" - elasticversion "github.com/elastic/e2e-testing/internal" "github.com/elastic/e2e-testing/internal/shell" + "github.com/elastic/e2e-testing/pkg/downloads" log "github.com/sirupsen/logrus" "go.elastic.co/apm" ) @@ -278,8 +278,8 @@ func (c *dockerDeploymentManifest) Stop(ctx context.Context, service ServiceRequ // the images produced by local Beats build, or not. // If an error occurred reading the environment, will return the passed namespace as fallback func GetDockerNamespaceEnvVar(fallback string) string { - useCISnapshots := elasticversion.GithubCommitSha1 != "" - if useCISnapshots || elasticversion.BeatsLocalPath != "" { + useCISnapshots := downloads.GithubCommitSha1 != "" + if useCISnapshots || downloads.BeatsLocalPath != "" { return "observability-ci" } return fallback diff --git a/internal/deploy/docker_test.go b/internal/deploy/docker_test.go index 1626596507..8ee9e0aeb5 100644 --- a/internal/deploy/docker_test.go +++ b/internal/deploy/docker_test.go @@ -7,8 +7,7 @@ package deploy import ( "testing" - elasticversion "github.com/elastic/e2e-testing/internal" - + "github.com/elastic/e2e-testing/pkg/downloads" "github.com/stretchr/testify/assert" ) @@ -19,8 +18,8 @@ func TestGetDockerNamespaceEnvVar(t *testing.T) { }) t.Run("Returns Observability CI when environment variable is set", func(t *testing.T) { - elasticversion.GithubCommitSha1 = "0123456789" - defer func() { elasticversion.GithubCommitSha1 = "" }() + downloads.GithubCommitSha1 = "0123456789" + defer func() { downloads.GithubCommitSha1 = "" }() namespace := GetDockerNamespaceEnvVar("beats") assert.True(t, namespace == "observability-ci") diff --git a/internal/installer/elasticagent_deb.go b/internal/installer/elasticagent_deb.go index e8c9be4149..f26e58814e 100644 --- a/internal/installer/elasticagent_deb.go +++ b/internal/installer/elasticagent_deb.go @@ -9,11 +9,11 @@ import ( "fmt" "strings" - elasticversion "github.com/elastic/e2e-testing/internal" "github.com/elastic/e2e-testing/internal/common" "github.com/elastic/e2e-testing/internal/deploy" "github.com/elastic/e2e-testing/internal/kibana" "github.com/elastic/e2e-testing/internal/utils" + "github.com/elastic/e2e-testing/pkg/downloads" log "github.com/sirupsen/logrus" "go.elastic.co/apm" ) @@ -142,7 +142,7 @@ func (i *elasticAgentDEBPackage) Preinstall(ctx context.Context) error { arch := utils.GetArchitecture() extension := "deb" - binaryName, binaryPath, err := elasticversion.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, false, true) + binaryName, binaryPath, err := downloads.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, false, true) if err != nil { log.WithFields(log.Fields{ "artifact": artifact, diff --git a/internal/installer/elasticagent_docker.go b/internal/installer/elasticagent_docker.go index a767ffd9e4..5b7dbd9040 100644 --- a/internal/installer/elasticagent_docker.go +++ b/internal/installer/elasticagent_docker.go @@ -8,10 +8,10 @@ import ( "context" "fmt" - elasticversion "github.com/elastic/e2e-testing/internal" "github.com/elastic/e2e-testing/internal/common" "github.com/elastic/e2e-testing/internal/deploy" "github.com/elastic/e2e-testing/internal/utils" + "github.com/elastic/e2e-testing/pkg/downloads" log "github.com/sirupsen/logrus" "go.elastic.co/apm" ) @@ -99,7 +99,7 @@ func (i *elasticAgentDockerPackage) Preinstall(ctx context.Context) error { arch := utils.GetArchitecture() extension := "tar.gz" - _, binaryPath, err := elasticversion.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, true, true) + _, binaryPath, err := downloads.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, true, true) if err != nil { log.WithFields(log.Fields{ "artifact": artifact, @@ -119,10 +119,10 @@ func (i *elasticAgentDockerPackage) Preinstall(ctx context.Context) error { // we need to tag the loaded image because its tag relates to the target branch return deploy.TagImage( - fmt.Sprintf("docker.elastic.co/beats/%s:%s", artifact, elasticversion.GetSnapshotVersion(common.BeatVersionBase)), - fmt.Sprintf("docker.elastic.co/observability-ci/%s:%s-%s", artifact, elasticversion.GetSnapshotVersion(common.BeatVersion), arch), + fmt.Sprintf("docker.elastic.co/beats/%s:%s", artifact, downloads.GetSnapshotVersion(common.BeatVersionBase)), + fmt.Sprintf("docker.elastic.co/observability-ci/%s:%s-%s", artifact, downloads.GetSnapshotVersion(common.BeatVersion), arch), // tagging including git commit and snapshot - fmt.Sprintf("docker.elastic.co/observability-ci/%s:%s-%s", artifact, elasticversion.GetFullVersion(common.BeatVersion), arch), + fmt.Sprintf("docker.elastic.co/observability-ci/%s:%s-%s", artifact, downloads.GetFullVersion(common.BeatVersion), arch), ) } diff --git a/internal/installer/elasticagent_rpm.go b/internal/installer/elasticagent_rpm.go index 320f25a48c..8c69e09c79 100644 --- a/internal/installer/elasticagent_rpm.go +++ b/internal/installer/elasticagent_rpm.go @@ -9,11 +9,11 @@ import ( "fmt" "strings" - elasticversion "github.com/elastic/e2e-testing/internal" "github.com/elastic/e2e-testing/internal/common" "github.com/elastic/e2e-testing/internal/deploy" "github.com/elastic/e2e-testing/internal/kibana" "github.com/elastic/e2e-testing/internal/utils" + "github.com/elastic/e2e-testing/pkg/downloads" log "github.com/sirupsen/logrus" "go.elastic.co/apm" ) @@ -146,7 +146,7 @@ func (i *elasticAgentRPMPackage) Preinstall(ctx context.Context) error { } extension := "rpm" - binaryName, binaryPath, err := elasticversion.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, false, true) + binaryName, binaryPath, err := downloads.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, false, true) if err != nil { log.WithFields(log.Fields{ "artifact": artifact, diff --git a/internal/installer/elasticagent_tar.go b/internal/installer/elasticagent_tar.go index bf294c222d..28c435bba7 100644 --- a/internal/installer/elasticagent_tar.go +++ b/internal/installer/elasticagent_tar.go @@ -10,12 +10,12 @@ import ( "os" "strings" - elasticversion "github.com/elastic/e2e-testing/internal" "github.com/elastic/e2e-testing/internal/common" "github.com/elastic/e2e-testing/internal/deploy" "github.com/elastic/e2e-testing/internal/io" "github.com/elastic/e2e-testing/internal/kibana" "github.com/elastic/e2e-testing/internal/utils" + "github.com/elastic/e2e-testing/pkg/downloads" log "github.com/sirupsen/logrus" "go.elastic.co/apm" ) @@ -129,7 +129,7 @@ func (i *elasticAgentTARPackage) Preinstall(ctx context.Context) error { } log.Trace("Cleared previously downloaded artifacts") } - _, binaryPath, err := elasticversion.FetchElasticArtifact(ctx, artifact, common.BeatVersion, runningOS, arch, extension, false, true) + _, binaryPath, err := downloads.FetchElasticArtifact(ctx, artifact, common.BeatVersion, runningOS, arch, extension, false, true) if err != nil { log.WithFields(log.Fields{ "artifact": artifact, @@ -147,7 +147,7 @@ func (i *elasticAgentTARPackage) Preinstall(ctx context.Context) error { return err } - output, _ := i.Exec(ctx, []string{"mv", fmt.Sprintf("%s-%s-%s-%s", artifact, elasticversion.GetSnapshotVersion(common.BeatVersion), runningOS, arch), artifact}) + output, _ := i.Exec(ctx, []string{"mv", fmt.Sprintf("%s-%s-%s-%s", artifact, downloads.GetSnapshotVersion(common.BeatVersion), runningOS, arch), artifact}) log.WithFields(log.Fields{ "output": output, "artifact": artifact, diff --git a/internal/installer/elasticagent_tar_macos.go b/internal/installer/elasticagent_tar_macos.go index f31d9cd7f7..e3b1ec3761 100644 --- a/internal/installer/elasticagent_tar_macos.go +++ b/internal/installer/elasticagent_tar_macos.go @@ -9,11 +9,11 @@ import ( "fmt" "runtime" - elasticversion "github.com/elastic/e2e-testing/internal" "github.com/elastic/e2e-testing/internal/common" "github.com/elastic/e2e-testing/internal/deploy" "github.com/elastic/e2e-testing/internal/kibana" "github.com/elastic/e2e-testing/internal/utils" + "github.com/elastic/e2e-testing/pkg/downloads" log "github.com/sirupsen/logrus" "go.elastic.co/apm" ) @@ -117,7 +117,7 @@ func (i *elasticAgentTARDarwinPackage) Preinstall(ctx context.Context) error { } extension := "tar.gz" - _, binaryPath, err := elasticversion.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, false, true) + _, binaryPath, err := downloads.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, false, true) if err != nil { log.WithFields(log.Fields{ "artifact": artifact, @@ -135,7 +135,7 @@ func (i *elasticAgentTARDarwinPackage) Preinstall(ctx context.Context) error { return err } - output, _ := i.Exec(ctx, []string{"mv", fmt.Sprintf("/%s-%s-%s-%s", artifact, elasticversion.GetSnapshotVersion(common.BeatVersion), os, arch), "/elastic-agent"}) + output, _ := i.Exec(ctx, []string{"mv", fmt.Sprintf("/%s-%s-%s-%s", artifact, downloads.GetSnapshotVersion(common.BeatVersion), os, arch), "/elastic-agent"}) log.WithField("output", output).Trace("Moved elastic-agent") return nil } diff --git a/internal/installer/elasticagent_zip.go b/internal/installer/elasticagent_zip.go index 7f9398c8c9..06ebddf191 100644 --- a/internal/installer/elasticagent_zip.go +++ b/internal/installer/elasticagent_zip.go @@ -9,10 +9,10 @@ import ( "fmt" "strings" - elasticversion "github.com/elastic/e2e-testing/internal" "github.com/elastic/e2e-testing/internal/common" "github.com/elastic/e2e-testing/internal/deploy" "github.com/elastic/e2e-testing/internal/kibana" + "github.com/elastic/e2e-testing/pkg/downloads" log "github.com/sirupsen/logrus" "go.elastic.co/apm" ) @@ -110,7 +110,7 @@ func (i *elasticAgentZIPPackage) Preinstall(ctx context.Context) error { arch := "x86_64" extension := "zip" - _, binaryPath, err := elasticversion.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, false, true) + _, binaryPath, err := downloads.FetchElasticArtifact(ctx, artifact, common.BeatVersion, os, arch, extension, false, true) if err != nil { log.WithFields(log.Fields{ "artifact": artifact, @@ -135,7 +135,7 @@ func (i *elasticAgentZIPPackage) Preinstall(ctx context.Context) error { return err } - output, _ := i.Exec(ctx, []string{"powershell.exe", "Move-Item", "-Force", "-Path", fmt.Sprintf("C:\\%s-%s-%s-%s", artifact, elasticversion.GetSnapshotVersion(common.BeatVersion), os, arch), "-Destination", "C:\\elastic-agent"}) + output, _ := i.Exec(ctx, []string{"powershell.exe", "Move-Item", "-Force", "-Path", fmt.Sprintf("C:\\%s-%s-%s-%s", artifact, downloads.GetSnapshotVersion(common.BeatVersion), os, arch), "-Destination", "C:\\elastic-agent"}) log.WithField("output", output).Trace("Moved elastic-agent") return nil } diff --git a/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-aarch64.rpm b/pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-aarch64.rpm similarity index 100% rename from internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-aarch64.rpm rename to pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-aarch64.rpm diff --git a/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-amd64.deb b/pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-amd64.deb similarity index 100% rename from internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-amd64.deb rename to pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-amd64.deb diff --git a/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-arm64.deb b/pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-arm64.deb similarity index 100% rename from internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-arm64.deb rename to pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-arm64.deb diff --git a/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-amd64.docker.tar.gz b/pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-amd64.docker.tar.gz similarity index 100% rename from internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-amd64.docker.tar.gz rename to pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-amd64.docker.tar.gz diff --git a/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-amd64.tar.gz b/pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-amd64.tar.gz similarity index 100% rename from internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-amd64.tar.gz rename to pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-amd64.tar.gz diff --git a/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-arm64.docker.tar.gz b/pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-arm64.docker.tar.gz similarity index 100% rename from internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-arm64.docker.tar.gz rename to pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-arm64.docker.tar.gz diff --git a/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-arm64.tar.gz b/pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-arm64.tar.gz similarity index 100% rename from internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-arm64.tar.gz rename to pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-arm64.tar.gz diff --git a/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-x86_64.tar.gz b/pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-x86_64.tar.gz similarity index 100% rename from internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-x86_64.tar.gz rename to pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-linux-x86_64.tar.gz diff --git a/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-x86_64.rpm b/pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-x86_64.rpm similarity index 100% rename from internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-x86_64.rpm rename to pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-BEATS_VERSION-x86_64.rpm diff --git a/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-ubi8-BEATS_VERSION-linux-amd64.docker.tar.gz b/pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-ubi8-BEATS_VERSION-linux-amd64.docker.tar.gz similarity index 100% rename from internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-ubi8-BEATS_VERSION-linux-amd64.docker.tar.gz rename to pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-ubi8-BEATS_VERSION-linux-amd64.docker.tar.gz diff --git a/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-ubi8-BEATS_VERSION-linux-arm64.docker.tar.gz b/pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-ubi8-BEATS_VERSION-linux-arm64.docker.tar.gz similarity index 100% rename from internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-ubi8-BEATS_VERSION-linux-arm64.docker.tar.gz rename to pkg/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-ubi8-BEATS_VERSION-linux-arm64.docker.tar.gz diff --git a/internal/_testresources/gcp/commits.json b/pkg/_testresources/gcp/commits.json similarity index 100% rename from internal/_testresources/gcp/commits.json rename to pkg/_testresources/gcp/commits.json diff --git a/internal/_testresources/gcp/nextPageParam.json b/pkg/_testresources/gcp/nextPageParam.json similarity index 100% rename from internal/_testresources/gcp/nextPageParam.json rename to pkg/_testresources/gcp/nextPageParam.json diff --git a/internal/_testresources/gcp/snapshots.json b/pkg/_testresources/gcp/snapshots.json similarity index 100% rename from internal/_testresources/gcp/snapshots.json rename to pkg/_testresources/gcp/snapshots.json diff --git a/internal/versions.go b/pkg/downloads/versions.go similarity index 99% rename from internal/versions.go rename to pkg/downloads/versions.go index 5611dea0f8..e58fe837b7 100644 --- a/internal/versions.go +++ b/pkg/downloads/versions.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package internal +package downloads import ( "context" diff --git a/internal/versions_test.go b/pkg/downloads/versions_test.go similarity index 98% rename from internal/versions_test.go rename to pkg/downloads/versions_test.go index 52146b0d85..b7f0c41339 100644 --- a/internal/versions_test.go +++ b/pkg/downloads/versions_test.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package internal +package downloads import ( "context" @@ -22,6 +22,8 @@ var testVersion = "BEATS_VERSION" var ubi8VersionPrefix = artifact + "-ubi8-" + testVersion var versionPrefix = artifact + "-" + testVersion +var testResourcesBasePath = path.Join("..", "_testresources") + const bucket = "beats-ci-artifacts" const commits = "commits" const snapshots = "snapshots" @@ -31,19 +33,19 @@ var commitsJSON *gabs.Container var snapshotsJSON *gabs.Container func init() { - nextTokenParamContent, err := ioutil.ReadFile(path.Join("_testresources", "gcp", "nextPageParam.json")) + nextTokenParamContent, err := ioutil.ReadFile(path.Join(testResourcesBasePath, "gcp", "nextPageParam.json")) if err != nil { os.Exit(1) } nextTokenParamJSON, _ = gabs.ParseJSON([]byte(nextTokenParamContent)) - commitsContent, err := ioutil.ReadFile(path.Join("_testresources", "gcp", "commits.json")) + commitsContent, err := ioutil.ReadFile(path.Join(testResourcesBasePath, "gcp", "commits.json")) if err != nil { os.Exit(1) } commitsJSON, _ = gabs.ParseJSON([]byte(commitsContent)) - snapshotsContent, err := ioutil.ReadFile(path.Join("_testresources", "gcp", "snapshots.json")) + snapshotsContent, err := ioutil.ReadFile(path.Join(testResourcesBasePath, "gcp", "snapshots.json")) if err != nil { os.Exit(1) } @@ -375,7 +377,7 @@ func TestCheckPRVersion(t *testing.T) { func TestFetchBeatsBinaryFromLocalPath(t *testing.T) { artifact := "elastic-agent" - beatsDir := path.Join("_testresources", "beats") + beatsDir := path.Join(testResourcesBasePath, "beats") distributionsDir, _ := filepath.Abs(path.Join(beatsDir, "x-pack", "elastic-agent", "build", "distributions")) version := testVersion