Skip to content

Commit

Permalink
Directly download agent
Browse files Browse the repository at this point in the history
  • Loading branch information
michel-laterman committed Dec 2, 2024
1 parent bb97980 commit bb5ad56
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions testing/e2e/agent_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"bytes"
"compress/gzip"
"context"
"encoding/json"
"errors"
"fmt"
"html/template"
Expand Down Expand Up @@ -44,19 +43,6 @@ type AgentInstallSuite struct {

}

// SearchResp is the response body for the artifacts search API
type SearchResp struct {
Packages map[string]Artifact `json:"packages"`
}

// Artifact describes an elastic artifact available through the API.
type Artifact struct {
URL string `json:"url"`
//SHAURL string `json:"sha_url"` // Unused
//Type string `json:"type"` // Unused
//Architecture string `json:"architecture"` // Unused
}

func TestAgentInstallSuite(t *testing.T) {
suite.Run(t, new(AgentInstallSuite))
}
Expand Down Expand Up @@ -114,17 +100,6 @@ func (suite *AgentInstallSuite) SetupSuite() {
// downloadAgent will search the artifacts repo for the latest snapshot and return the stream to the download for the current OS + ARCH.
func (suite *AgentInstallSuite) downloadAgent(ctx context.Context) io.ReadCloser {
suite.T().Helper()
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://artifacts-api.elastic.co/v1/search/%s-SNAPSHOT", version.DefaultVersion), nil)
suite.Require().NoError(err)

resp, err := suite.Client.Do(req)
suite.Require().NoError(err)

var body SearchResp
err = json.NewDecoder(resp.Body).Decode(&body)
resp.Body.Close()
suite.Require().NoError(err)

fType := "tar.gz"
if runtime.GOOS == "windows" {
fType = "zip"
Expand All @@ -139,10 +114,7 @@ func (suite *AgentInstallSuite) downloadAgent(ctx context.Context) io.ReadCloser
}

fileName := fmt.Sprintf("elastic-agent-%s-SNAPSHOT-%s-%s.%s", version.DefaultVersion, runtime.GOOS, arch, fType)
pkg, ok := body.Packages[fileName]
suite.Require().Truef(ok, "unable to find package download for fileName = %s", fileName)

req, err = http.NewRequestWithContext(ctx, "GET", pkg.URL, nil)
req, err = http.NewRequestWithContext(ctx, "GET", "https://artifacts-api.elastic.co/v1/downloads/elastic-agent-package/"+fileName, nil)
suite.Require().NoError(err)
resp, err = suite.Client.Do(req)
suite.Require().NoError(err)
Expand Down

0 comments on commit bb5ad56

Please sign in to comment.