so mamy things...
This commit is contained in:
1 parent
f7a8d416c1
commit
78d50d9a6d
24 files changed
+516
-173
No files matched your search
@@ -16,8 +16,8 @@ func init() {
|
||||
|
||||
func TestGetAllDoormen(t *testing.T) {
|
||||
conn = inmemoryconnector.NewInMemoryDBConnector()
|
||||
conn.Save(doormen.QuickNewDoormanDefinition("foo", 0.25, 0.75))
|
||||
conn.Save(doormen.QuickNewDoormanDefinition("bar", 0.5, 0.5))
|
||||
conn.Save(doormen.QuickNewDoormanDefinition("foo", "0.25", "0.75"))
|
||||
conn.Save(doormen.QuickNewDoormanDefinition("bar", "0.5", "0.5"))
|
||||
|
||||
req, err := http.NewRequest("GET", "http://bigtits.com/api/doormen", nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -44,11 +44,19 @@ func Create(root string) http.Handler {
|
||||
UpdateDoorman,
|
||||
}
|
||||
|
||||
getDoormanStatus := &simpleapi.Endpoint{
|
||||
"/doormen/{id}/status",
|
||||
`Returns the status of the doorman as a doorman client expect it.`,
|
||||
"GET",
|
||||
GetDoormanStatus,
|
||||
}
|
||||
|
||||
api := simpleapi.New(
|
||||
root,
|
||||
serverSpecification,
|
||||
createDoorman,
|
||||
allDoorman,
|
||||
getDoormanStatus,
|
||||
doorman,
|
||||
updateDoorman,
|
||||
)
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestCreateDoorman(t *testing.T) {
|
||||
conn = inmemoryconnector.NewInMemoryDBConnector()
|
||||
payload := `
|
||||
{"name":"name",
|
||||
"values":[{"name":"red","probability":0.2},{"name":"blue","probability":0.8}],
|
||||
"values":[{"name":"red","probability":"1/5"},{"name":"blue","probability": "4/5"}],
|
||||
"emails": ["alice"]
|
||||
}`
|
||||
req, err := http.NewRequest(
|
||||
@@ -34,7 +34,7 @@ func TestCreateDoorman(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
CreateDoorman(w, req)
|
||||
if w.Code != 201 {
|
||||
t.Error("bad status code", w.Code)
|
||||
t.Error("bad status code", w.Code, "\n", w.Body)
|
||||
} else if location := w.Header().Get("location"); location == "" {
|
||||
t.Error("missing location header", location)
|
||||
} else if dor, _ := conn.GetDoorman(GetIdFromLocation(location)); dor == nil {
|
||||
|
||||
@@ -21,3 +21,24 @@ func GetDoorman(w http.ResponseWriter, r *http.Request) {
|
||||
encoder.Encode(doorman)
|
||||
}
|
||||
}
|
||||
|
||||
func GetDoormanStatus(w http.ResponseWriter, r *http.Request) {
|
||||
id := getDoormanIdFromRequest(w, r)
|
||||
if id == "" {
|
||||
Write404Error(w)
|
||||
return
|
||||
}
|
||||
doorman, err := conn.GetDoorman(id)
|
||||
if err != nil {
|
||||
Write500Error(w, err)
|
||||
} else if doorman == nil {
|
||||
Write404Error(w)
|
||||
}
|
||||
|
||||
if payload, err := doorman.AsDoormanUpdatePayload(); err != nil {
|
||||
Write500Error(w, err)
|
||||
} else {
|
||||
w.Write(payload)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user