Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.9](backport #2955) Introduce upgrade tests from released versions #3173

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pkg/testing/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type Fixture struct {
allowErrs bool
connectTimout time.Duration

workDir string
srcPackage string
workDir string

installed bool
installOpts *InstallOpts
Expand Down Expand Up @@ -153,6 +154,7 @@ func (f *Fixture) Prepare(ctx context.Context, components ...UsableComponent) er
if err != nil {
return err
}
f.srcPackage = src
filename := filepath.Base(src)
name, _, err := splitFileType(filename)
if err != nil {
Expand Down Expand Up @@ -191,6 +193,15 @@ func (f *Fixture) WorkDir() string {
return f.workDir
}

// SrcPackage returns the location on disk of the elastic agent package used by this fixture.
func (f *Fixture) SrcPackage(ctx context.Context) (string, error) {
err := f.ensurePrepared(ctx)
if err != nil {
return "", err
}
return f.srcPackage, nil
}

func ExtractArtifact(l Logger, artifactFile, outputDir string) error {
filename := filepath.Base(artifactFile)
_, ext, err := splitFileType(filename)
Expand Down
10 changes: 1 addition & 9 deletions pkg/testing/tools/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ import (
)

// InstallAgent force install the Elastic Agent through agentFixture.
func InstallAgent(fleetUrl string, enrollmentToken string, agentFixture *atesting.Fixture) ([]byte, error) {
installOpts := atesting.InstallOpts{
NonInteractive: true,
Force: true,
EnrollOpts: atesting.EnrollOpts{
URL: fleetUrl,
EnrollmentToken: enrollmentToken,
},
}
func InstallAgent(installOpts atesting.InstallOpts, agentFixture *atesting.Fixture) ([]byte, error) {
return agentFixture.Install(context.Background(), &installOpts)
}

Expand Down
13 changes: 12 additions & 1 deletion pkg/testing/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/elastic/elastic-agent-libs/kibana"

atesting "github.com/elastic/elastic-agent/pkg/testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -79,7 +80,17 @@ func InstallAgentWithPolicy(t *testing.T, agentFixture *atesting.Fixture, kibCli

// Enroll agent
t.Logf("Unpacking and installing Elastic Agent")
output, err := InstallAgent(fleetServerURL, enrollmentToken.APIKey, agentFixture)
// this is a partial backport of https://github.com/elastic/elastic-agent/pull/3114
// normally the installOpts are passed as parameter, and we just add URL and Enrollment Token
installOpts := atesting.InstallOpts{
NonInteractive: true,
Force: true,
}
installOpts.EnrollOpts = atesting.EnrollOpts{
URL: fleetServerURL,
EnrollmentToken: enrollmentToken.APIKey,
}
output, err := InstallAgent(installOpts, agentFixture)
if err != nil {
t.Log(string(output))
return nil, fmt.Errorf("unable to enroll Elastic Agent: %w", err)
Expand Down
Loading