Skip to content

Commit 16fd7be

Browse files
committed
Use the remove function from install
Remove the custom removeAll function in favour of the install.RemovePath that already exists.
1 parent 76cbf33 commit 16fd7be

File tree

3 files changed

+2
-80
lines changed

3 files changed

+2
-80
lines changed

pkg/testing/fixture.go

+2-32
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
2828
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details"
29+
"github.com/elastic/elastic-agent/internal/pkg/agent/install"
2930
"github.com/elastic/elastic-agent/pkg/component"
3031
"github.com/elastic/elastic-agent/pkg/control"
3132
"github.com/elastic/elastic-agent/pkg/control/v2/client"
@@ -1209,7 +1210,7 @@ func createTempDir(t *testing.T) string {
12091210

12101211
cleanup := func() {
12111212
if !t.Failed() {
1212-
if err := removeAll(tempDir); err != nil {
1213+
if err := install.RemovePath(tempDir); err != nil {
12131214
t.Errorf("could not remove temp dir '%s': %s", tempDir, err)
12141215
}
12151216
} else {
@@ -1221,37 +1222,6 @@ func createTempDir(t *testing.T) string {
12211222
return tempDir
12221223
}
12231224

1224-
// removeAll tries to remove path, if it fails and the error
1225-
// is retry able (only on Windows), it will keep retrying with an exponential
1226-
// backoff up to 3 seconds.
1227-
func removeAll(path string) error {
1228-
maxBackoffTime := 3 * time.Second
1229-
myyBackoff := backoff.NewExponentialBackOff(
1230-
backoff.WithMaxElapsedTime(maxBackoffTime),
1231-
backoff.WithInitialInterval(time.Millisecond))
1232-
1233-
myyBackoff.Reset()
1234-
for {
1235-
err := os.RemoveAll(path)
1236-
if err == nil {
1237-
break
1238-
}
1239-
1240-
if !isWindowsRetryable(err) {
1241-
return fmt.Errorf("could not remove temp dir '%s': %s", path, err)
1242-
}
1243-
1244-
interval := myyBackoff.NextBackOff()
1245-
if interval == backoff.Stop {
1246-
return fmt.Errorf("could not remove '%s' after waiting for %s: %w", path, maxBackoffTime, err)
1247-
}
1248-
1249-
time.Sleep(interval)
1250-
}
1251-
1252-
return nil
1253-
}
1254-
12551225
type AgentStatusOutput struct {
12561226
Info struct {
12571227
ID string `json:"id"`

pkg/testing/fixture_other.go

-14
This file was deleted.

pkg/testing/fixture_windows.go

-34
This file was deleted.

0 commit comments

Comments
 (0)