Improves unit tests
This commit is contained in:
parent
e39b91a5da
commit
43967fed89
2 changed files with 22 additions and 0 deletions
|
|
@ -59,6 +59,7 @@ func main() {
|
|||
###Default() allows all origins
|
||||
|
||||
```go
|
||||
func main() {
|
||||
router := gin.Default()
|
||||
// same as
|
||||
// config := cors.DefaultConfig()
|
||||
|
|
@ -66,6 +67,7 @@ func main() {
|
|||
// router.Use(cors.Default())
|
||||
router.Use(cors.Default())
|
||||
router.Run()
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
|
|
|||
20
cors_test.go
20
cors_test.go
|
|
@ -39,6 +39,26 @@ func performRequest(r http.Handler, method, origin string) *httptest.ResponseRec
|
|||
return w
|
||||
}
|
||||
|
||||
func TestConfigAddAllow(t *testing.T) {
|
||||
config := Config{}
|
||||
config.AddAllowMethods("POST")
|
||||
config.AddAllowMethods("GET", "PUT")
|
||||
config.AddExposeHeaders()
|
||||
|
||||
config.AddAllowHeaders("Some", " cool")
|
||||
config.AddAllowHeaders("header")
|
||||
config.AddExposeHeaders()
|
||||
|
||||
config.AddExposeHeaders()
|
||||
config.AddExposeHeaders("exposed", "header")
|
||||
config.AddExposeHeaders("hey")
|
||||
|
||||
assert.Equal(t, config.AllowMethods, []string{"POST", "GET", "PUT"})
|
||||
assert.Equal(t, config.AllowHeaders, []string{"Some", " cool", "header"})
|
||||
assert.Equal(t, config.ExposeHeaders, []string{"exposed", "header", "hey"})
|
||||
|
||||
}
|
||||
|
||||
func TestBadConfig(t *testing.T) {
|
||||
assert.Panics(t, func() { New(Config{}) })
|
||||
assert.Panics(t, func() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue