-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
47 lines (42 loc) · 997 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"context"
"os"
"testing"
"time"
"github.com/tillkuhn/billy-idle/pkg/tracker"
"github.com/stretchr/testify/assert"
)
func Test_Tracker(t *testing.T) {
ctx, ctxCancel := context.WithCancel(context.Background())
dir, err := os.MkdirTemp("", "test-")
if err != nil {
t.Fatal(err.Error())
}
defer func(path string) {
t.Log("Removing " + path)
err := os.RemoveAll(path)
if err != nil {
t.Log(err.Error())
}
}(dir)
opts := &tracker.Options{
CheckInterval: 100 * time.Millisecond,
IdleTolerance: 150 * time.Millisecond, // fixed mock value is 125ms
AppRoot: dir, // overwrite with tempdir
Cmd: "testdata/ioreg_mock.sh",
Debug: true,
DropCreate: true,
}
tr := tracker.New(opts)
assert.NoError(t, err)
go func() { tr.Track(ctx) }()
time.Sleep(1 * time.Second)
ctxCancel()
tr.WaitClose()
t.Log("Test finished")
}
func Test_Help(_ *testing.T) {
os.Args = []string{"app", "help"}
main()
}