示例#1
0
func TestLogin(t *testing.T) {
	// Raw
	good_result := string(cloud.Get("authorize?login=important&password=7890"))
	bad_result := string(cloud.Get("authorize?login=important&password=789"))
	Must(t, good_result == "OK", "Correct user")
	Must(t, bad_result == "FAIL", "Wrong password")
	// Nicer
	Must(t, good_guy.Authorize() == "OK", "Correct user")
	Must(t, strings.Contains(bad_guy.Authorize(), "FAIL"), "Wrong user")
}
示例#2
0
func TestSimplePostGet(t *testing.T) {
	post_resp := string(cloud.Post("info", []byte("ABC123")))
	get_resp := string(cloud.Get("info?a=1&a=2&b=3"))
	t.Log(post_resp)
	t.Log(get_resp)
	Must(t, strings.Contains(post_resp, "[ABC123]"), "Echo back posted file")
	Must(t, strings.Contains(get_resp, "b:3"), "Parse single parameters")
	Must(t, strings.Contains(get_resp, "a:1|2"), "Parse multiple parameters")
}
示例#3
0
func TestFileTransfer(t *testing.T) {
	// Raw
	uploaded := string(cloud.Post("upload?login=important&password=7890&file=numbers.txt", []byte("12345")))
	downloaded := string(cloud.Get("download?login=important&password=7890&file=numbers.txt"))
	t.Log(uploaded)
	t.Log(downloaded)
	Must(t, uploaded == "OK", "File upload")
	Must(t, downloaded == "12345", "File download")
	// Nicer
	Must(t, strings.Contains(bad_guy.Upload("scene.txt", []byte("Act I")), "FAIL"), "Upload by a bad guy")
	// Flow
	Must(t, good_guy.Upload("scene.txt", []byte("Act I")) == "OK", "Upload")
	Must(t, string(good_guy.Download("scene.txt")) == "Act I", "Download")
}