-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatusformat_test.go
50 lines (40 loc) · 1.31 KB
/
statusformat_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
48
49
50
package main
import (
"errors"
"net/http"
"testing"
)
func TestStatusFormatSuccess(t *testing.T) {
testSet := []struct {
status int
label string
state string
}{
{http.StatusOK, "Systemd state", "running"},
{http.StatusInternalServerError, "Systemd state", "maintenance"},
}
for _, set := range testSet {
status, stateFormat := getStatusAndFormat(makeState(set.state), nil)
if status != set.status {
t.Errorf("Expected status for \"%s\" to be \"%d\" but got \"%d\"", set.state, set.status, status)
}
if stateFormat.Label != set.label {
t.Errorf("Expected state label to be \"%s\" but got \"%s\"", set.label, stateFormat.Label)
}
if stateFormat.State != set.state {
t.Errorf("Expected systemd state \"%s\" but got \"%s\"", set.state, stateFormat.State)
}
}
}
func TestStatusFormatError(t *testing.T) {
errorStatus, errorStateFormat := getStatusAndFormat(SystemdState{}, errors.New("some error"))
if errorStatus != http.StatusServiceUnavailable {
t.Errorf("Expected status for maintenance to be \"%d\" but got \"%d\"", http.StatusServiceUnavailable, errorStatus)
}
if errorStateFormat.Label != "Error getting state" {
t.Errorf("Expected \"%s\"", errorStateFormat.Label)
}
if errorStateFormat.State != "some error" {
t.Errorf("Expected \"%s\"", errorStateFormat.State)
}
}