예제 #1
0
func TestHelloWorldRoundTrip(t *testing.T) {
	defer stream.Reset()

	ts := httptest.NewServer(serverHandler())
	defer ts.Close()

	client, err := testClient(ts.URL)
	if err != nil {
		t.Error(err)
	}

	pr, pw := io.Pipe()

	go func() {
		pw.Write([]byte("Hello, World!"))
		pw.Close()
	}()

	cntRes, err := client.PostStream(pr)
	if err != nil {
		t.Error(err)
	}

	owner, name := readNWO(cntRes)
	if owner != client.Login {
		t.Errorf("stream owner is %s, want %s", owner, client.Login)
	}

	res, err := client.GetStream(client.Login, name)
	if err != nil {
		t.Error(err)
	}

	rb, err := ioutil.ReadAll(res.Body)
	res.Body.Close()
	if err != nil {
		t.Error(err)
	}

	if string(rb) != "Hello, World!" {
		t.Errorf("response body is '%s', want 'Hello, World!'", rb)
	}
}
예제 #2
0
func delTestData() {
	if err := stream.Reset(); err != nil {
		panic(err)
	}
}