2009-06-09 11:58:58 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Tests for client.go
|
|
|
|
|
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
2009-12-02 23:02:14 -07:00
|
|
|
"io/ioutil";
|
2009-06-09 11:58:58 -06:00
|
|
|
"strings";
|
|
|
|
"testing";
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestClient(t *testing.T) {
|
|
|
|
// TODO: add a proper test suite. Current test merely verifies that
|
2009-06-11 16:55:03 -06:00
|
|
|
// we can retrieve the Google robots.txt file.
|
|
|
|
|
2009-09-15 10:41:59 -06:00
|
|
|
r, _, err := Get("http://www.google.com/robots.txt");
|
2009-06-09 11:58:58 -06:00
|
|
|
var b []byte;
|
|
|
|
if err == nil {
|
2009-12-02 23:02:14 -07:00
|
|
|
b, err = ioutil.ReadAll(r.Body);
|
2009-06-09 11:58:58 -06:00
|
|
|
r.Body.Close();
|
|
|
|
}
|
2009-06-22 14:26:13 -06:00
|
|
|
if err != nil {
|
2009-11-09 13:07:39 -07:00
|
|
|
t.Error(err)
|
2009-06-24 21:12:50 -06:00
|
|
|
} else if s := string(b); !strings.HasPrefix(s, "User-agent:") {
|
2009-11-09 13:07:39 -07:00
|
|
|
t.Errorf("Incorrect page body (did not begin with User-agent): %q", s)
|
2009-06-09 11:58:58 -06:00
|
|
|
}
|
|
|
|
}
|