Skip to content

Commit 625abbb

Browse files
committed
Adding unit test
1 parent c70fd39 commit 625abbb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

internal/pkg/agent/application/upgrade/rollback_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"path/filepath"
1212
"runtime"
1313
"testing"
14+
"time"
1415

1516
"github.com/stretchr/testify/assert"
1617
"github.com/stretchr/testify/mock"
@@ -328,6 +329,24 @@ func TestRollback(t *testing.T) {
328329
}
329330
}
330331

332+
func TestInvokeCmd(t *testing.T) {
333+
agentExecutable := "elastic-agent"
334+
rollbackWindow := 2*time.Hour + 15*time.Minute
335+
cmd := invokeCmd(agentExecutable, rollbackWindow)
336+
337+
// Expected command:
338+
// elastic-agent watch --path.config /some/path --path.home /some/path --rollback.window 8100s
339+
require.Len(t, cmd.Args, 8)
340+
require.Equal(t, agentExecutable, cmd.Args[0])
341+
require.Equal(t, "watch", cmd.Args[1])
342+
require.Equal(t, "--path.config", cmd.Args[2])
343+
require.NotEmpty(t, cmd.Args[3])
344+
require.Equal(t, "--path.home", cmd.Args[4])
345+
require.NotEmpty(t, cmd.Args[5])
346+
require.Equal(t, "--rollback.window", cmd.Args[6])
347+
require.Equal(t, "8100s", cmd.Args[7])
348+
}
349+
331350
// checkFilesAfterCleanup is a convenience function to check the file structure within topDir.
332351
// *AgentHome paths must be the expected old and new agent paths relative to topDir (typically in the form of "data/elastic-agent-*")
333352
func checkFilesAfterCleanup(t *testing.T, topDir, newAgentHome string, oldAgentHomes ...string) {

0 commit comments

Comments
 (0)