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-15 16:35:38 -07:00
|
|
|
"io/ioutil"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2009-06-09 11:58:58 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
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-12-15 16:35:38 -07:00
|
|
|
r, _, err := Get("http://www.google.com/robots.txt")
|
|
|
|
var b []byte
|
2009-06-09 11:58:58 -06:00
|
|
|
if err == nil {
|
2009-12-15 16:35:38 -07:00
|
|
|
b, err = ioutil.ReadAll(r.Body)
|
|
|
|
r.Body.Close()
|
2009-06-09 11:58:58 -06:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
2010-06-07 17:28:40 -06:00
|
|
|
|
|
|
|
func TestClientHead(t *testing.T) {
|
|
|
|
r, err := Head("http://www.google.com/robots.txt")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if _, ok := r.Header["Last-Modified"]; !ok {
|
|
|
|
t.Error("Last-Modified header not found.")
|
|
|
|
}
|
|
|
|
}
|