Skip to content

Commit 7ff0626

Browse files
committed
add test
1 parent de41b81 commit 7ff0626

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

internal/pkg/agent/cmd/enroll_cmd_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,28 @@ func TestDaemonReloadWithBackoff(t *testing.T) {
577577
}
578578
}
579579

580+
func TestWaitForFleetServer_timeout(t *testing.T) {
581+
log, _ := logger.NewTesting("TestWaitForFleetServer_timeout")
582+
timeout := 5 * time.Second
583+
testTimeout := 2 * timeout
584+
585+
ctx, cancel := context.WithTimeout(context.Background(), timeout)
586+
defer cancel()
587+
var got string
588+
var err error
589+
require.Eventuallyf(t,
590+
func() bool {
591+
got, err = waitForFleetServer(ctx, make(chan *os.ProcessState, 1), log, timeout)
592+
return true
593+
},
594+
testTimeout,
595+
500*time.Millisecond,
596+
"waitForFleetServer never returned")
597+
598+
assert.Empty(t, got, "waitForFleetServer should have returned and empty enrollmentToken")
599+
assert.Error(t, err, "waitForFleetServer should have returned an error")
600+
}
601+
580602
func withServer(
581603
m func(t *testing.T) *http.ServeMux,
582604
test func(t *testing.T, host string),

0 commit comments

Comments
 (0)