func TestDeleteHosts(t *testing.T) { pool := testPool() hostData := testHostData() if err := zk.SetPool(pool); err != nil { t.Fatalf("could not add pool to add hosts") } defer func() { if err := zk.DeletePool(pool.Name); err != nil { t.Fatalf("could not clean up") } }() statusCode, _, err := client.BuildAndSendRequest("PUT", "/pools/"+pool.Name+"/hosts", hostData) if err != nil { t.Fatalf("could not add hosts") } if statusCode != 200 { t.Fatalf("incorrect response status from add host req") } hMap := make(map[string][]string, 1) hRay := []string{"myHost", "yourHost", "ourHost"} hMap["Hosts"] = hRay b, err := json.Marshal(hMap) if err != nil { t.Fatalf("could not marshal hmap") } delHData := string(b) statusCode, _, err = client.BuildAndSendRequest("DELETE", "/pools/"+pool.Name+"/hosts", delHData) if err != nil { t.Fatalf("could not delete hosts") } if statusCode != 200 { t.Fatalf("incorrect status code from delete") } hList, err := zk.GetHosts(pool.Name) if err != nil { t.Fatalf("couldnt get hosts") } if len(hList) > 0 { t.Fatalf("hosts not deleted properly") } }
func GetHosts(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) err := GetUserSecretAndAuth(r) if err != nil { WriteResponse(w, NotAuthorizedStatusCode, GetErrorStatusJson(NotAuthenticatedStatus, err)) return } hostsMap, err := zk.GetHosts(vars["PoolName"]) if err != nil { WriteResponse(w, ServerErrorCode, GetErrorStatusJson(CouldNotCompleteOperationStatus, err)) return } hMapJson, err := json.Marshal(hostsMap) if err != nil { WriteResponse(w, ServerErrorCode, GetErrorStatusJson(CouldNotCompleteOperationStatus, err)) return } WriteResponse(w, OkStatusCode, string(hMapJson)) }