package main import ( "bytes" "net/http" "net/http/httptest" "os" "strings" "testing" "testing/fstest" ) var fs = http.FileServer(http.Dir("./testdata")) var srv = httptest.NewServer(fs) func TestDownload(t *testing.T) { var ( b bytes.Buffer c = make(chan request) ) url := srv.URL + "/somefile" t.Logf("file URL: %s", url) go func() { c <- request{&b, url}; close(c) }() Download(c) want := "somefile inner data" if got := b.String(); got != want { t.Errorf("file buffer received unexpected value\nGot:\n%s\nWant:\n%s", got, want) } } func TestRead(t *testing.T) { input := `boston http://localhost/someboston.jpg http://localhost/anotherboston.mp4 orlando http://localhost/someorlando.jpg ` dir := t.TempDir() t.Logf("root directory: %s", dir) c := Read(dir, strings.NewReader(input)) for range c { } // drain the channel err := fstest.TestFS( os.DirFS(dir), "boston0.jpg", "boston1.mp4", "orlando0.jpg", ) if err != nil { t.Fatal(err) } }