Example #1
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 #2
0
func TestDeletePool(t *testing.T) {

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

	statusCode, _, err := client.BuildAndSendRequest("PUT", "/pools/"+pool.Name, poolData)
	if err != nil {
		t.Fatalf("problem setting pool for delete")
	}

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

	statusCode, _, err = client.BuildAndSendRequest("DELETE", "/pools/"+pool.Name, "")
	if err != nil {
		t.Fatalf("Problem sending delete request")
	}

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

	statusCode, _, err = client.BuildAndSendRequest("GET", "/pools/"+pool.Name, "")
	if err != nil {
		t.Fatalf("couldn't issue get request to check if pool deleted")
	}

	if statusCode != 404 {
		t.Fatalf("pool not properly deleted: %d", statusCode)
	}
}
Example #3
0
func TestDeleteTrie(t *testing.T) {

	trie := testTrie()
	trieData := testTrieData()

	statusCode, _, err := client.BuildAndSendRequest("PUT", "/tries/"+trie.Name, trieData)
	if err != nil {
		t.Fatalf("problem setting trie for delete")
	}

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

	statusCode, _, err = client.BuildAndSendRequest("DELETE", "/tries/"+trie.Name, "")
	if err != nil {
		t.Fatalf("Problem sending delete request")
	}

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

	statusCode, _, err = client.BuildAndSendRequest("GET", "/tries/"+trie.Name, "")
	if err != nil {
		t.Fatalf("couldn't issue get request to check if trie deleted")
	}

	if statusCode != 404 {
		t.Fatalf("trie not properly deleted: %d", statusCode)
	}
}
Example #4
0
func TestSetPort(t *testing.T) {

	port := testPort()
	portData := testPortData()

	statusCode, data, err := client.BuildAndSendRequest("PUT", "/ports/"+fmt.Sprintf("%d", port.Port), portData)
	if err != nil {
		t.Fatalf("Failed to send request")
	}

	if statusCode != 200 {

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

	defer func() {
		if err := zk.DeletePort(fmt.Sprintf("%d", port.Port)); err != nil {
			t.Fatalf("Couldn't clean up port")
		}
	}()

	statusCode, data, err = client.BuildAndSendRequest("GET", "/ports/"+fmt.Sprintf("%d", port.Port), "")
	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 != portData {
		t.Fatalf("Set port failed")
	}
}
Example #5
0
func TestSetTrie(t *testing.T) {

	trie := testTrie()
	trieData := testTrieData()

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

	if statusCode != 200 {

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

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

	statusCode, data, err = client.BuildAndSendRequest("GET", "/tries/"+trie.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 != trieData {
		t.Fatalf("Set trie failed")
	}
}
Example #6
0
func TestDeletePort(t *testing.T) {

	port := testPort()
	portData := testPortData()

	statusCode, _, err := client.BuildAndSendRequest("PUT", "/ports/"+fmt.Sprintf("%d", port.Port), portData)
	if err != nil {
		t.Fatalf("problem setting port for delete")
	}

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

	statusCode, _, err = client.BuildAndSendRequest("DELETE", "/ports/"+fmt.Sprintf("%d", port.Port), "")
	if err != nil {
		t.Fatalf("Problem sending delete request")
	}

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

	statusCode, _, err = client.BuildAndSendRequest("GET", "/ports/"+fmt.Sprintf("%d", port.Port), "")
	if err != nil {
		t.Fatalf("couldn't issue get request to check if port deleted")
	}

	if statusCode != 404 {
		t.Fatalf("port not properly deleted: %d", statusCode)
	}
}
Example #7
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 #8
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 #9
0
func TestGetTrie(t *testing.T) {

	trie := testTrie()
	trieData := testTrieData()

	if err := zk.SetTrie(trie); err != nil {
		t.Fatalf("couldn't set trie for get")
	}

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

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

	if statusCode != 200 {

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

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

	port := testPort()
	portData := testPortData()

	if err := zk.SetPort(port); err != nil {
		t.Fatalf("couldn't set port for get")
	}

	defer func() {
		if err := zk.DeletePort(fmt.Sprintf("%d", port.Port)); err != nil {
			t.Fatalf("couldn't clean up")
		}
	}()

	statusCode, data, err := client.BuildAndSendRequest("GET", "/ports/"+fmt.Sprintf("%d", port.Port), "")
	if err != nil {
		t.Fatalf("could not get port: %s", err)
	}

	if statusCode != 200 {

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

	if data != portData {
		t.Fatalf("Value from get not as expected \n %s \b %s", data, portData)
	}
}
Example #11
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 #12
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")
	}
}