forked from goadesign/goa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_redirect_test.go
44 lines (41 loc) · 1.26 KB
/
http_redirect_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
package expr_test
import (
"net/http"
"testing"
"goa.design/goa/v3/eval"
"goa.design/goa/v3/expr"
)
func TestHTTPRedirectExprEvalName(t *testing.T) {
cases := map[string]struct {
url string
statusCode int
parent eval.Expression
expected string
}{
"without parent": {
url: "/redirect/dest",
statusCode: http.StatusMovedPermanently,
expected: "redirect to /redirect/dest with status code 301",
},
"parent is HTTPEndpointExpr": {
url: "/redirect/dest",
statusCode: http.StatusMovedPermanently,
parent: &expr.HTTPEndpointExpr{MethodExpr: &expr.MethodExpr{Name: "method"}},
expected: `HTTP endpoint "method" redirect to /redirect/dest with status code 301`,
},
"parent is HTTPFileServerExpr": {
url: "/redirect/dest",
statusCode: http.StatusMovedPermanently,
parent: &expr.HTTPFileServerExpr{FilePath: "/file.json"},
expected: `file server /file.json redirect to /redirect/dest with status code 301`,
},
}
for k, tc := range cases {
t.Run(k, func(t *testing.T) {
r := expr.HTTPRedirectExpr{URL: tc.url, StatusCode: tc.statusCode, Parent: tc.parent}
if actual := r.EvalName(); actual != tc.expected {
t.Errorf("got %#v, expected %#v", actual, tc.expected)
}
})
}
}