forked from goadesign/goa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add test to HTTP cookie expressions Fix related issues. * Fix comment of Cookie DSL
- Loading branch information
Showing
8 changed files
with
296 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package expr_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"goa.design/goa/v3/expr" | ||
"goa.design/goa/v3/expr/testdata" | ||
) | ||
|
||
func TestHTTPResponseCookie(t *testing.T) { | ||
type Props map[string]interface{} | ||
|
||
cases := []struct { | ||
Name string | ||
DSL func() | ||
Props Props | ||
}{ | ||
{"cookie", testdata.CookieObjectResultDSL, nil}, | ||
{"cookie", testdata.CookieStringResultDSL, nil}, | ||
{"max-age", testdata.CookieMaxAgeDSL, Props{"cookie:max-age": testdata.CookieMaxAgeValue}}, | ||
{"domain", testdata.CookieDomainDSL, Props{"cookie:domain": testdata.CookieDomainValue}}, | ||
{"path", testdata.CookiePathDSL, Props{"cookie:path": testdata.CookiePathValue}}, | ||
{"secure", testdata.CookieSecureDSL, Props{"cookie:secure": "Secure"}}, | ||
{"http-only", testdata.CookieHTTPOnlyDSL, Props{"cookie:http-only": "HttpOnly"}}, | ||
} | ||
for _, c := range cases { | ||
t.Run(c.Name, func(t *testing.T) { | ||
root := expr.RunDSL(t, c.DSL) | ||
e := root.API.HTTP.Services[len(root.API.HTTP.Services)-1].HTTPEndpoints[0] | ||
cookies := e.Responses[0].Cookies.AttributeExpr | ||
if len(*expr.AsObject(cookies.Type)) != 1 { | ||
t.Errorf("got %d cookie(s), expected exactly one", len(*expr.AsObject(cookies.Type))) | ||
} else { | ||
m := cookies.Meta | ||
for n, v := range c.Props { | ||
if len(m) != 1 { | ||
t.Errorf("got cookies metadata with length %d, expected 1", len(m)) | ||
} else if len(m[n]) != 1 { | ||
t.Errorf("got cookies metadata %q with length %d, expected 1", n, len(m[n])) | ||
} else if m[n][0] != fmt.Sprintf("%v", v) { | ||
t.Errorf("got value %q for cookies metadata %q, expected %q", m[n][0], n, fmt.Sprintf("%v", v)) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.