Skip to content

Commit

Permalink
add test for desktop runner detect presence
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Pickett committed Dec 18, 2024
1 parent c1ed3bd commit 2330a2e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ee/desktop/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/kolide/launcher/ee/agent/flags/keys"
"github.com/kolide/launcher/ee/agent/types/mocks"
"github.com/kolide/launcher/ee/desktop/user/notify"
"github.com/kolide/launcher/ee/presencedetection"
"github.com/kolide/launcher/pkg/backoff"
"github.com/kolide/launcher/pkg/log/multislogger"
"github.com/kolide/launcher/pkg/threadsafebuffer"
Expand Down Expand Up @@ -493,3 +494,33 @@ func countFilesWithPrefix(folderPath, prefix string) (int, error) {

return count, nil
}

func TestDesktopUsersProcessesRunner_DetectPresence(t *testing.T) {
t.Parallel()

t.Run("no user procs", func(t *testing.T) {
t.Parallel()

runner := DesktopUsersProcessesRunner{}
d, err := runner.DetectPresence("whatevs", time.Second)
require.Error(t, err)
require.Equal(t, presencedetection.DetectionFailedDurationValue, d)
})

t.Run("cant connect to user server", func(t *testing.T) {
t.Parallel()

u, err := user.Current()
require.NoError(t, err)

runner := DesktopUsersProcessesRunner{}
runner.uidProcs = make(map[string]processRecord)
runner.uidProcs[u.Uid] = processRecord{
socketPath: "/tmp/doesntexist",
}

d, err := runner.DetectPresence("whatevs", time.Second)
require.Error(t, err)
require.Equal(t, presencedetection.DetectionFailedDurationValue, d)
})
}

0 comments on commit 2330a2e

Please sign in to comment.