Repository navigation
Expand file tree
/
Copy pathproblems_test.go
More file actions
51 lines (44 loc) · 1.81 KB
/
Copy pathproblems_test.go
File metadata and controls
51 lines (44 loc) · 1.81 KB
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
package nanoca_test
import (
"net/http"
"strings"
"testing"
"github.com/brandonweeks/nanoca"
)
func TestProblemConstructors(t *testing.T) {
t.Parallel()
tests := []struct {
name string
problem *nanoca.Problem
wantStatus int
}{
{"InternalServerError", nanoca.InternalServerError("boom"), http.StatusInternalServerError},
{"Malformed", nanoca.Malformed("boom"), http.StatusBadRequest},
{"BadNonce", nanoca.BadNonce("boom"), http.StatusBadRequest},
{"BadCSR", nanoca.BadCSR("boom"), http.StatusBadRequest},
{"BadSignatureAlgorithm", nanoca.BadSignatureAlgorithm("boom", []string{"ES256"}), http.StatusBadRequest},
{"InvalidContact", nanoca.InvalidContact("boom"), http.StatusBadRequest},
{"Unauthorized", nanoca.Unauthorized("boom"), http.StatusForbidden},
{"AccountDoesNotExist", nanoca.AccountDoesNotExist("boom"), http.StatusBadRequest},
{"MethodNotAllowed", nanoca.MethodNotAllowed("boom"), http.StatusMethodNotAllowed},
{"UnsupportedMediaTypeProblem", nanoca.UnsupportedMediaTypeProblem("boom"), http.StatusUnsupportedMediaType},
{"RequestTooLarge", nanoca.RequestTooLarge("boom"), http.StatusRequestEntityTooLarge},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := tt.problem.Status; got != tt.wantStatus {
t.Errorf("Status = %d, want %d", got, tt.wantStatus)
}
if !strings.HasPrefix(tt.problem.Type, nanoca.ACMEProblemTypePrefix) {
t.Errorf("Type = %q, want prefix %q", tt.problem.Type, nanoca.ACMEProblemTypePrefix)
}
if got := tt.problem.Error(); !strings.Contains(got, "boom") {
t.Errorf("Error() = %q, want it to contain the detail", got)
}
})
}
if algs := nanoca.BadSignatureAlgorithm("boom", []string{"ES256"}).Algorithms; len(algs) != 1 || algs[0] != "ES256" {
t.Errorf("Algorithms = %v, want [ES256]", algs)
}
}