コード例 #1
0
ファイル: lotsa_spec.go プロジェクト: verdverm/pomopomo
func main() {
	UUID = os.Getenv("UUID")
	TOKEN = os.Getenv("TOKEN")
	frisby.Global.SetHeader("Authorization", "Bearer "+TOKEN)

	new_todo := map[string]string{
		"name":        "lotsatodo #",
		"description": "this is my first todo posted from frisby!",
	}
	var todo_ids []string

	POST := frisby.Create("POST lotsa todo collector")
	DELETE := frisby.Create("DELETE lotsa todo collector")

	for i := 0; i < NUM_TODOS; i++ {
		new_todo["name"] = "lotsatodo " + fmt.Sprint(i)
		todo_id_int := 0
		frisby.Create("POST lotsa todo: "+fmt.Sprint(i)).
			Post(URL+"todo").
			SetHeader("Authorization", "Bearer "+TOKEN).
			SetJson(new_todo).
			Send().
			ExpectStatus(200).
			ExpectJson("result", "success!").
			AfterJson(func(F *frisby.Frisby, json *simplejson.Json, err error) {

				todo_id_json := json.GetPath("todo", "id")
				var cerr error
				todo_id_int, cerr = todo_id_json.Int()
				if cerr != nil {
					POST.AddError(cerr.Error())
				}
				tid := fmt.Sprint(todo_id_int)
				todo_ids = append(todo_ids, tid)

			})
	}

	for i := 0; i < NUM_TODOS; i++ {
		todo_id := todo_ids[i]
		errs := frisby.Create("DELETE lotsa todo: "+todo_id).
			Delete(URL+"todo/"+todo_id).
			SetHeader("Authorization", "Bearer "+TOKEN).
			Send().
			ExpectStatus(200).
			ExpectJson("result", "success!").
			Errors()

		for _, e := range errs {
			DELETE.AddError(e.Error())
		}
	}

	frisby.Global.PrintReport()
}
コード例 #2
0
ファイル: doc_test.go プロジェクト: verdverm/frisby
func ExampleFrisby_ExpectJsonType() {
	frisby.Create("Test ExpectJsonType").
		Post("http://httpbin.org/post").
		Send().
		ExpectStatus(200).
		ExpectJsonType("url", reflect.String).
		PrintReport()

	// Output: Pass  [Test ExpectJsonType]
}
コード例 #3
0
ファイル: doc_test.go プロジェクト: verdverm/frisby
func ExampleFrisby_Post() {
	frisby.Create("Test POST").
		Post("http://httpbin.org/post").
		SetData("test_key", "test_value").
		Send().
		ExpectStatus(200).
		PrintReport()

	// Output: Pass  [Test POST]
}
コード例 #4
0
ファイル: doc_test.go プロジェクト: verdverm/frisby
func ExampleFrisby_Get() {
	frisby.Create("Test GET Go homepage").
		Get("http://golang.org").
		Send().
		ExpectStatus(200).
		ExpectContent("The Go Programming Language").
		PrintReport()

	// Output: Pass  [Test GET Go homepage]
}
コード例 #5
0
ファイル: doc_test.go プロジェクト: verdverm/frisby
func ExampleFrisby_ExpectJson() {
	frisby.Create("Test ExpectJson").
		Post("http://httpbin.org/post").
		Send().
		ExpectStatus(200).
		ExpectJson("url", "http://httpbin.org/post").
		ExpectJson("headers.Accept", "*/*").
		PrintReport()

	// Output: Pass  [Test ExpectJson]
}
コード例 #6
0
ファイル: doc_test.go プロジェクト: verdverm/frisby
func ExampleFrisby_AfterJson() {
	frisby.Create("Test AfterJson").
		Post("http://httpbin.org/post").
		Send().
		ExpectStatus(200).
		AfterJson(func(F *frisby.Frisby, json *simplejson.Json, err error) {
			val, _ := json.Get("url").String()
			fmt.Println("url =", val)
		})

	// Output: url = http://httpbin.org/post
}
コード例 #7
0
ファイル: doc_test.go プロジェクト: verdverm/frisby
func ExampleFrisby_PrintReport() {
	frisby.Create("Test GET Go homepage").
		Get("http://golang.org").
		Send().
		ExpectStatus(400).
		ExpectContent("A string which won't be found").
		AddError("Manually Added Error").
		PrintReport()

	// Output: FAIL  [Test GET Go homepage]
	//         -  Expected Status 400, but got 200: "200 OK"
	//         -  Expected Body to contain "A string which won't be found", but it was missing
	//         -  Manually Added Error
}
コード例 #8
0
ファイル: main.go プロジェクト: leobcn/frisby
func main() {
	fmt.Println("Frisby!\n")

	frisby.Create("Test GET Go homepage").
		Get("http://golang.org").
		Send().
		ExpectStatus(200).
		ExpectContent("The Go Programming Language")

	frisby.Create("Test GET Go homepage (which fails)").
		Get("http://golang.org").
		Send().
		ExpectStatus(400).
		ExpectContent("A string which won't be found")

	frisby.Create("Test POST").
		Post("http://httpbin.org/post").
		SetData("test_key", "test_value").
		Send().
		ExpectStatus(200)

	frisby.Create("Test ExpectJsonType").
		Post("http://httpbin.org/post").
		Send().
		ExpectStatus(200).
		ExpectJsonType("url", reflect.String)

	frisby.Create("Test ExpectJson").
		Post("http://httpbin.org/post").
		Send().
		ExpectStatus(200).
		ExpectJson("url", "http://httpbin.org/post").
		ExpectJson("headers.Accept", "*/*")

	frisby.Create("Test ExpectJsonLength").
		Post("http://httpbin.org/post").
		SetJson([]string{"item1", "item2", "item3"}).
		Send().
		ExpectStatus(200).
		ExpectJsonLength("json", 3)

	frisby.Create("Test AfterJson").
		Post("http://httpbin.org/post").
		Send().
		ExpectStatus(200).
		AfterJson(func(F *frisby.Frisby, json *simplejson.Json, err error) {
			val, _ := json.Get("url").String()
			frisby.Global.SetProxy(val)
		})

	frisby.Global.PrintReport()
}
コード例 #9
0
ファイル: main_test.go プロジェクト: getdiskette/diskette
func TestPing(t *testing.T) {
	errs := frisby.Create("Test ping").
		Get("http://localhost:5025/ping").
		Send().
		ExpectStatus(http.StatusOK).
		ExpectContent("pong").
		AfterText(
			func(F *frisby.Frisby, text string, err error) {
				assert.Nil(t, err)
				assert.Equal(t, "pong", text)
			}).
		Errors()

	for _, err := range errs {
		assert.Nil(t, err)
	}
}
コード例 #10
0
ファイル: first_spec.go プロジェクト: verdverm/pomopomo
func main() {
	UUID = os.Getenv("UUID")
	TOKEN = os.Getenv("TOKEN")
	frisby.Global.SetHeader("Authorization", "Bearer "+TOKEN)

	frisby.Create("Test token login").
		Get(URL+"auth_test").
		Send().
		ExpectStatus(200).
		ExpectJsonType("authed", reflect.String).
		ExpectJson("authed", UUID)

	frisby.Create("GET all todos").
		Get(URL + "todo").
		// SetHeader("Authorization", "Bearer "+TOKEN).
		Send().
		ExpectStatus(200).
		AfterJson(func(F *frisby.Frisby, json *simplejson.Json, err error) {

			todos, _ := json.Array()
			for _, t := range todos {
				todo := t.(map[string]interface{})
				todo_id := todo["id"].(gojson.Number).String()
				f := frisby.Create("Delete todo " + todo_id).
					Delete(URL + "todo/" + todo_id).
					// SetHeader("Authorization", "Bearer "+TOKEN).
					Send().
					ExpectStatus(200)

				for _, e := range f.Errors() {
					F.AddError("Deleting Todo " + todo_id + " " + e.Error())
				}
			}
		})

	frisby.Create("GET non-existant todo").
		Get(URL+"todo/0").
		Send().
		ExpectStatus(400).
		ExpectJson("Error", "todo not found")

	frisby.Create("GET all todos (empty)").
		Get(URL+"todo").
		// SetHeader("Authorization", "Bearer "+TOKEN).
		Send().
		ExpectStatus(200).
		ExpectJson("", []interface{}{})

	new_todo := map[string]string{
		"name":        "test todo",
		"description": "this is my first todo posted from frisby!",
	}
	todo_id := ""
	todo_id_int := 0
	frisby.Create("POST new todo").
		Post(URL+"todo").
		SetJson(new_todo).
		Send().
		ExpectStatus(200).
		ExpectJson("result", "success!").
		AfterJson(func(F *frisby.Frisby, json *simplejson.Json, err error) {

			todo_id_json := json.GetPath("todo", "id")
			var cerr error
			todo_id_int, cerr = todo_id_json.Int()
			if cerr != nil {
				F.AddError(cerr.Error())
			}
			todo_id = fmt.Sprint(todo_id_int)

		})

	frisby.Create("GET existing todo by id").
		Get(URL+"todo/"+todo_id).
		Send().
		ExpectStatus(200).
		ExpectJson("id", todo_id_int).
		ExpectJson("Uuid", UUID).
		ExpectJson("Name", "test todo")

	frisby.Create("DELETE existing todo by id").
		Delete(URL+"todo/"+todo_id).
		Send().
		ExpectStatus(200).
		ExpectJson("result", "success!").
		ExpectJson("tid", todo_id_int)

	frisby.Global.PrintReport()

}
コード例 #11
0
ファイル: auth_spec.go プロジェクト: verdverm/pomopomo
func main() {
	TRAVIS = os.Getenv("TRAVIS")

	if TRAVIS == "true" {
		regi := map[string]string{
			"username": "******",
			"email":    "*****@*****.**",
			"password": "******",
			"confirm":  "test",
		}
		frisby.Create("Test successful registration").
			Post(URL + "register").
			SetJson(regi).
			Send().
			ExpectStatus(200).
			AfterJson(func(F *frisby.Frisby, json *simplejson.Json, err error) {
				UUID, _ = json.Get("uid").String()
				TOKEN, _ = json.Get("token").String()
			})
	}

	creds := map[string]string{
		"username": "******",
		"password": "******",
	}
	frisby.Create("Test successful user login").
		Post(URL+"login").
		SetJson(creds).
		Send().
		ExpectStatus(200).
		ExpectJsonType("uid", reflect.String).
		ExpectJson("uid", UUID)

	bad_username := map[string]string{
		"username": "******",
		"password": "******",
	}
	frisby.Create("Test bad username login").
		Post(URL+"login").
		SetJson(bad_username).
		Send().
		ExpectStatus(400).
		ExpectJson("Error", "login failure")

	bad_password := map[string]string{
		"username": "******",
		"password": "******",
	}
	frisby.Create("Test bad password login").
		Post(URL+"login").
		SetJson(bad_password).
		Send().
		ExpectStatus(400).
		ExpectJson("Error", "login failure")

	regi := map[string]string{
		"username": "******",
		"email":    "*****@*****.**",
		"password": "******",
		"confirm":  "test",
	}
	frisby.Create("Test username conflict at registration").
		Post(URL+"register").
		SetJson(regi).
		Send().
		ExpectStatus(400).
		ExpectJson("Error", "Username taken")

	regi["username"] = "******"
	frisby.Create("Test email conflict at registration").
		Post(URL+"register").
		SetJson(regi).
		Send().
		ExpectStatus(400).
		ExpectJson("Error", "Email taken")

	regi["email"] = "*****@*****.**"
	regi["confirm"] = "confirm"
	frisby.Create("Test password mismatch at registration").
		Post(URL+"register").
		SetJson(regi).
		Send().
		ExpectStatus(400).
		ExpectJson("Error", "Password mismatch")

	regi["username"] = ""
	regi["confirm"] = "password"
	frisby.Create("Test empty username at registration").
		Post(URL+"register").
		SetJson(regi).
		Send().
		ExpectStatus(400).
		ExpectJson("Error", "Empty Username")

	regi["email"] = ""
	regi["username"] = "******"
	frisby.Create("Test empty email at registration").
		Post(URL+"register").
		SetJson(regi).
		Send().
		ExpectStatus(400).
		ExpectJson("Error", "Empty Email")

	regi["email"] = "*****@*****.**"
	regi["password"] = ""
	regi["confirm"] = ""
	frisby.Create("Test empty password and confirm at registration").
		Post(URL+"register").
		SetJson(regi).
		Send().
		ExpectStatus(400).
		ExpectJson("Error", "Empty Password")

	frisby.Global.PrintReport()
}