Example #1
0
func TestGetPool(t *testing.T) {

	pool := testPool()
	poolData := testPoolData()

	if err := zk.SetPool(pool); err != nil {
		t.Fatalf("couldn't set pool for get")
	}
	if err := zk.AddHosts(pool.Name, pool.Hosts); err != nil {
		t.Fatalf("couldn't set pool for get")
	}

	defer func() {
		if err := zk.DeletePool(pool.Name); err != nil {
			t.Fatalf("couldn't clean up")
		}
	}()

	statusCode, data, err := client.BuildAndSendRequest("GET", "/pools/"+pool.Name, "")
	if err != nil {
		t.Fatalf("could not get pool: %s", err)
	}

	if statusCode != 200 {

		t.Fatalf("incorrect status code returned, should be 200")
	}

	if data != poolData {
		t.Fatalf("Value from get not as expected \n %s \b %s", data, poolData)
	}
}
Example #2
0
func TestSetPool(t *testing.T) {

	pool := testPool()
	poolData := testPoolData()

	statusCode, data, err := client.BuildAndSendRequest("PUT", "/pools/"+pool.Name, poolData)
	if err != nil {
		t.Fatalf("Failed to send request")
	}

	if statusCode != 200 {

		t.Fatalf("Incorrect status code for response")
	}

	defer func() {
		if err := zk.DeletePool(pool.Name); err != nil {
			t.Fatalf("Couldn't clean up pool")
		}
	}()

	statusCode, data, err = client.BuildAndSendRequest("GET", "/pools/"+pool.Name, "")
	if err != nil {
		t.Fatalf("failed to send get request for set verification")
	}

	if statusCode != 200 {
		t.Fatalf("Incorrect status code for get response")
	}

	if data != poolData {
		t.Fatalf("Set pool failed")
	}
}
Example #3
0
func TestGetHosts(t *testing.T) {

	pool := testPool()

	host := testHost()
	hostData := testHostData()

	if err := zk.SetPool(pool); err != nil {
		t.Fatalf("failed to put pool to test add host")
	}

	defer func() {
		if err := zk.DeletePool(pool.Name); err != nil {
			t.Fatalf("could not clean up")
		}
	}()

	if err := zk.AddHosts(pool.Name, host); err != nil {
		t.Fatalf("couldn't add hosts to attempt get")
	}

	statusCode, data, err := client.BuildAndSendRequest("GET", "/pools/"+pool.Name+"/hosts", "")
	if err != nil {
		t.Fatalf("couldn't get hosts")
	}

	if statusCode != 200 {
		t.Fatalf("incorrect status code")
	}

	if data != hostData {
		t.Fatalf("data from get doesn't match the put data")
	}

}
Example #4
0
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")
	}

}
Example #5
0
func DeletePool(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	err := GetUserSecretAndAuth(r)
	if err != nil {
		WriteResponse(w, NotAuthorizedStatusCode, GetErrorStatusJson(NotAuthenticatedStatus, err))
		return
	}

	err = zk.DeletePool(vars["PoolName"])

	if err != nil {
		WriteResponse(w, ServerErrorCode, GetErrorStatusJson(CouldNotCompleteOperationStatus, err))
		return
	}

	WriteResponse(w, OkStatusCode, GetStatusJson(RequestSuccesfulStatus))
}
Example #6
0
func TestAddHosts(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")
	}

	status, data, err := client.BuildAndSendRequest("GET", "/pools/"+pool.Name+"/hosts", "")
	if err != nil {
		t.Fatalf("could not get hosts")
	}

	if status != 200 {
		t.Fatalf("incorrect status code from get hosts req")
	}

	if data != hostData {
		t.Fatalf("host data not added properly")
	}
}