-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmonitor_test.go
More file actions
39 lines (32 loc) · 892 Bytes
/
monitor_test.go
File metadata and controls
39 lines (32 loc) · 892 Bytes
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
package libhealth
import (
"context"
"sync"
"testing"
"github.com/stretchr/testify/require"
)
func TestMonitor_Check(t *testing.T) {
monitor := NewMonitor("test", "", "", REQUIRED, func(ctx context.Context) Health {
return NewHealth(OK, "okay")
}, nil)
health := monitor.Check(context.Background())
require.Equal(t, health.Status, OK)
}
func TestMonitor_Check_Channel(t *testing.T) {
statusChan := make(chan HealthStatus)
monitor := NewMonitor("test", "", "", REQUIRED, func(ctx context.Context) Health {
return NewHealth(OUTAGE, "outage")
}, statusChan)
var wg sync.WaitGroup
wg.Add(1)
go func() {
health := monitor.Check(context.Background())
require.Equal(t, health.Status, OUTAGE)
wg.Done()
}()
status := <-statusChan
require.Equal(t, status.Monitor, monitor)
require.Equal(t, status.Prev, OK)
require.Equal(t, status.Next.Status, OUTAGE)
wg.Wait()
}