예제 #1
0
func TestSetRule(t *testing.T) {

	rule := testRule()
	ruleData := testRuleData()

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

	if statusCode != 200 {

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

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

	statusCode, data, err = client.BuildAndSendRequest("GET", "/rules/"+rule.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 != ruleData {
		t.Fatalf("Set rule failed")
	}
}
예제 #2
0
func TestGetRule(t *testing.T) {

	rule := testRule()
	ruleData := testRuleData()

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

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

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

	if statusCode != 200 {

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

	if data != ruleData {
		t.Fatalf("Value from get not as expected \n %s \b %s", data, ruleData)
	}
}
예제 #3
0
func DeleteRule(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.DeleteRule(vars["RuleName"])

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

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