mirror of https://github.com/docker/docs.git
adding server tests
This commit is contained in:
parent
fa38bc7ba9
commit
2ec64fcec6
|
@ -14,6 +14,8 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// TODO: This is just for PoC. The real DB should be injected as part of
|
||||
// the context for a final version.
|
||||
var db = util.GetSqliteDB()
|
||||
|
||||
// MainHandler is the default handler for the server
|
||||
|
@ -24,7 +26,7 @@ func MainHandler(ctx utils.IContext, w http.ResponseWriter, r *http.Request) *er
|
|||
w.Write([]byte("{server_error: 'Could not parse error message'}"))
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
//w.WriteHeader(http.StatusNotFound)
|
||||
return &errors.HTTPError{
|
||||
HTTPStatus: http.StatusNotFound,
|
||||
Code: 9999,
|
||||
|
|
|
@ -1 +1,38 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/endophage/go-tuf/signed"
|
||||
|
||||
"github.com/docker/vetinari/utils"
|
||||
)
|
||||
|
||||
func TestMainHandlerGet(t *testing.T) {
|
||||
hand := utils.RootHandlerFactory(&utils.InsecureAuthorizer{}, utils.ContextFactory, &signed.Ed25519{})
|
||||
handler := hand(MainHandler)
|
||||
ts := httptest.NewServer(handler)
|
||||
defer ts.Close()
|
||||
|
||||
_, err := http.Get(ts.URL)
|
||||
if err != nil {
|
||||
t.Fatalf("Received error on GET /: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMainHandlerNotGet(t *testing.T) {
|
||||
hand := utils.RootHandlerFactory(&utils.InsecureAuthorizer{}, utils.ContextFactory, &signed.Ed25519{})
|
||||
handler := hand(MainHandler)
|
||||
ts := httptest.NewServer(handler)
|
||||
defer ts.Close()
|
||||
|
||||
res, err := http.Head(ts.URL)
|
||||
if err != nil {
|
||||
t.Fatalf("Received error on GET /: %s", err.Error())
|
||||
}
|
||||
if res.StatusCode != http.StatusNotFound {
|
||||
t.Fatalf("Expected 404, received %d", res.StatusCode)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ func TestRunGoodCancel(t *testing.T) {
|
|||
err := Run(ctx, config)
|
||||
|
||||
if _, ok := err.(*net.OpError); !ok {
|
||||
t.Fatal("Received unexpected err: %s", err.Error())
|
||||
t.Fatalf("Received unexpected err: %s", err.Error())
|
||||
}
|
||||
if !strings.Contains(err.Error(), "use of closed network connection") {
|
||||
t.Fatalf("Received unexpected err: %s", err.Error())
|
||||
|
|
|
@ -8,8 +8,9 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/vetinari/errors"
|
||||
"github.com/endophage/go-tuf/signed"
|
||||
|
||||
"github.com/docker/vetinari/errors"
|
||||
)
|
||||
|
||||
func MockBetterHandler(ctx IContext, w http.ResponseWriter, r *http.Request) *errors.HTTPError {
|
||||
|
|
Loading…
Reference in New Issue