Skip to content

Commit

Permalink
fix when fixture.Install logs 'ignoring AGENT_KEEP_INSTALLED...' (#3380)
Browse files Browse the repository at this point in the history
(cherry picked from commit 3372e6f)
  • Loading branch information
AndersonQ committed Sep 13, 2023
1 parent 0728828 commit ef84c44
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions pkg/testing/fixture_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
"time"

"github.com/stretchr/testify/require"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/elastic-agent/pkg/control/v2/client"
"github.com/elastic/elastic-agent/pkg/core/process"
Expand Down Expand Up @@ -128,22 +125,14 @@ func (f *Fixture) Install(ctx context.Context, installOpts *InstallOpts, opts ..

// environment variable AGENT_KEEP_INSTALLED=true will skip the uninstall
// useful to debug the issue with the Elastic Agent
if f.t.Failed() && keepInstalled() {
f.t.Logf("skipping uninstall; test failed and AGENT_KEEP_INSTALLED=true")
return
}

if keepInstalled() {
f.t.Logf("skipping uninstall; AGENT_KEEP_INSTALLED=true")
} else {
out, err := f.Uninstall(ctx, &UninstallOpts{Force: true, UninstallToken: f.uninstallToken})
f.setClient(nil)
if err != nil &&
(errors.Is(err, ErrNotInstalled) ||
strings.Contains(
err.Error(),
"elastic-agent: no such file or directory")) {
// Agent fixture has already been uninstalled, perhaps by
// an explicit call to fixture.Uninstall, so nothing needs
// to be done here.
return
}
require.NoErrorf(f.t, err, "uninstalling agent failed. Output: %q", out)
f.t.Logf("ignoring AGENT_KEEP_INSTALLED=true as test succeeded, " +
"keeping the agent installed will jeopardise other tests")
}
})

Expand Down

0 comments on commit ef84c44

Please sign in to comment.