mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 18:00:24 +08:00
28 lines
685 B
Go
28 lines
685 B
Go
package rest
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCorsHandler(t *testing.T) {
|
|
w := httptest.NewRecorder()
|
|
handler := CorsHandler()
|
|
handler.ServeHTTP(w, nil)
|
|
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
|
|
assert.Equal(t, allOrigin, w.Header().Get(allowOrigin))
|
|
}
|
|
|
|
func TestCorsHandlerWithOrigins(t *testing.T) {
|
|
origins := []string{"local", "remote"}
|
|
w := httptest.NewRecorder()
|
|
handler := CorsHandler(origins...)
|
|
handler.ServeHTTP(w, nil)
|
|
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
|
|
assert.Equal(t, strings.Join(origins, separator), w.Header().Get(allowOrigin))
|
|
}
|