28 lines
437 B
Go
28 lines
437 B
Go
|
package hmm
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
"net/http/httptest"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
type dummy struct{}
|
||
|
|
||
|
func (d *dummy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||
|
for i := 0; i < 10; i++ {
|
||
|
fmt.Fprintf(w, "here is a line: %d\n", i)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestFetch(t *testing.T) {
|
||
|
ts := httptest.NewServer(&dummy{})
|
||
|
i := 0
|
||
|
for range Lines(ts.URL) {
|
||
|
i++
|
||
|
}
|
||
|
if got, want := i, 10; got != want {
|
||
|
t.Fatalf("got %d, want %d", got, want)
|
||
|
}
|
||
|
}
|