-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_test.go
45 lines (36 loc) · 1.03 KB
/
check_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
// Copyright © 2019, 2023 The Swedish Internet Foundation
//
// Distributed under the MIT License. (See accompanying LICENSE file or copy at
// <https://opensource.org/licenses/MIT>.)
package health
import (
"encoding/json"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCheck(t *testing.T) {
t.Parallel()
var check Check
assert.True(t, check.Good())
check.Status = StatusWarn
assert.True(t, check.Good())
check.Status = StatusFail
assert.False(t, check.Good())
check.SetObservedTime(123*time.Microsecond + 456*time.Nanosecond)
check.AffectedEndpoints = []string{"https://example.test/1", "https://example.test/2"}
check.Output = "test output"
check.Links = []string{"https://example.test/about"}
j, err := json.Marshal(check)
assert.NoError(t, err)
assert.JSONEq(t, `
{
"affectedEndpoints": [ "https://example.test/1", "https://example.test/2" ],
"links": [ "https://example.test/about" ],
"observedUnit": "ns",
"observedValue": 123456,
"output": "test output",
"status": "fail"
}
`, string(j))
}