generated from bootjp/go-docker-actions-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_test.go
62 lines (59 loc) · 819 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"errors"
"testing"
)
func TestParser(t *testing.T) {
tests := []struct {
in string
out Status
err error
}{
{
"CO2=1012,HUM=35.2,TMP=29.6",
Status{
co2: 1012,
hum: 35.2,
temp: 29.6,
},
nil,
},
{
"CO2=1012,HUM=35.2,TMP=29.6\r\n",
Status{
co2: 1012,
hum: 35.2,
temp: 29.6,
},
nil,
},
{
"CO2=90,HUM=1.0,TMP=1\r\n",
Status{
co2: 90,
hum: 1.0,
temp: 1,
},
nil,
},
{
"CO2=90",
Status{},
ErrInvalidFormat,
},
{
"",
Status{},
ErrInvalidFormat,
},
}
for _, tt := range tests {
stat, err := parser(tt.in)
if !errors.Is(err, tt.err) {
t.Errorf("expect error got %v, want %v", stat, tt.out)
}
if stat != tt.out {
t.Errorf("got %v, want %v", stat, tt.out)
}
}
}