Beispiel #1
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")
	}
}
Beispiel #2
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)
	}
}
Beispiel #3
0
func DeleteTrie(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.DeleteTrie(vars["TrieName"])
	if err != nil {
		WriteResponse(w, ServerErrorCode, GetErrorStatusJson(CouldNotCompleteOperationStatus, err))
		return
	}

	WriteResponse(w, OkStatusCode, GetStatusJson(RequestSuccesfulStatus))
}