mirror of
https://github.com/docker/docs.git
synced 2026-03-31 16:28:59 +07:00
- pulled out router setup into separate method for testing - unit test without cors - unit test for cors + OPTIONS - resolves #1442 Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
60 lines
1.0 KiB
Go
60 lines
1.0 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
func TestRequest(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
r := mux.NewRouter()
|
|
setupPrimaryRouter(r, nil, false)
|
|
w := httptest.NewRecorder()
|
|
|
|
req, e := http.NewRequest("GET", "/version", nil)
|
|
if nil != e {
|
|
t.Fatalf("couldn't set up test request")
|
|
}
|
|
|
|
r.ServeHTTP(w, req)
|
|
|
|
t.Logf("%d - %s", w.Code, w.Body.String())
|
|
t.Log("Expecting no extra Headers")
|
|
for k, v := range w.Header() {
|
|
t.Log(k, " : ", v)
|
|
}
|
|
|
|
if w.Code == 404 {
|
|
t.Fatalf("failed not found")
|
|
}
|
|
}
|
|
|
|
func TestCorsRequest(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
primary := mux.NewRouter()
|
|
setupPrimaryRouter(primary, nil, true)
|
|
w := httptest.NewRecorder()
|
|
|
|
r, e := http.NewRequest("OPTIONS", "/version", nil)
|
|
if nil != e {
|
|
t.Fatalf("couldn't set up test request")
|
|
}
|
|
|
|
primary.ServeHTTP(w, r)
|
|
|
|
t.Logf("%d - %s", w.Code, w.Body.String())
|
|
t.Log("Expecting extra cors Headers")
|
|
for k, v := range w.Header() {
|
|
t.Log(k, " : ", v)
|
|
}
|
|
|
|
if w.Code == 404 {
|
|
t.Fatalf("failed not found")
|
|
}
|
|
}
|