-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors_test.go
58 lines (55 loc) · 1.14 KB
/
errors_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
// Copyright 2018 The Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package nuki
import "testing"
func TestErrorFromStatus(t *testing.T) {
tt := []struct {
name string
status int
expected error
}{
{
name: "status OK",
status: 200,
expected: nil,
},
{
name: "given url is invalid or to long",
status: 400,
expected: ErrInvalidURL,
},
{
name: "token is invalid",
status: 401,
expected: ErrInvalidToken,
},
{
name: "authentication disabled",
status: 403,
expected: ErrAuthDisabled,
},
{
name: "given smart lock is unknown",
status: 404,
expected: ErrSmartLockUnknown,
},
{
name: "given smart lock is offline",
status: 503,
expected: ErrSmartLockOffline,
},
{
name: "unknown code",
status: 42,
expected: ErrUnknown,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
if err := ErrorFromStatus(tc.status); err != tc.expected {
t.Errorf("ErrorFromStatus() error = %v, expected %v", err, tc.expected)
}
})
}
}