forked from eggsampler/acme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem_test.go
68 lines (64 loc) · 1.61 KB
/
problem_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
63
64
65
66
67
68
package acme
import (
"net/http"
"strings"
"testing"
)
func TestCheckError(t *testing.T) {
errorTests := []struct {
Name string
URL string
ExpectedStatus []int
}{
{
Name: "test expecting http 202, but got 200",
URL: testClient.Directory().URL,
ExpectedStatus: []int{202},
},
{
Name: "test acme error expecting ok",
URL: testClient.Directory().NewAccount,
ExpectedStatus: []int{http.StatusOK},
},
{
Name: "test http error expecting ok",
URL: testClient.Directory().NewAccount + "/asdasdasdasdasd",
ExpectedStatus: []int{http.StatusOK},
},
}
for _, currentTest := range errorTests {
resp, err := http.Get(currentTest.URL)
if err != nil {
t.Fatalf("error %s: expected no error, got: %v", currentTest.Name, err)
}
if err := checkError(resp, currentTest.ExpectedStatus...); err == nil {
t.Fatalf("error %s: expected error, got none", currentTest.Name)
}
}
resp, err := http.Get(testClient.Directory().URL)
if err != nil {
t.Fatalf("expected no error, got: %v", err)
}
if err := checkError(resp, http.StatusOK); err != nil {
t.Fatalf("expected no error, got: %v", err)
}
}
func TestProblem_Error(t *testing.T) {
err := Problem{
Status: 123,
Type: "type",
Detail: "detail",
Instance: "instance",
SubProblems: []SubProblem{
{
Type: "type2",
Detail: "detail",
Identifier: Identifier{"DNS", "example.com"},
},
},
}
s := error(err).Error()
if !strings.HasPrefix(s, "acme: error code") {
t.Fatalf("unexpected acme error: %v", err)
}
}