You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
667 B
43 lines
667 B
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
"testing/fstest"
|
|
)
|
|
|
|
var fs = http.FileServer(http.Dir("./testdata"))
|
|
|
|
var srv = httptest.NewServer(fs)
|
|
|
|
func TestReadAndDownload(t *testing.T) {
|
|
lines := []string{
|
|
"text",
|
|
srv.URL + "/sometext.txt",
|
|
srv.URL + "/moretext.txt",
|
|
"",
|
|
"image",
|
|
srv.URL + "/tiny-fuji",
|
|
}
|
|
input := strings.Join(lines, "\n")
|
|
|
|
dir := t.TempDir()
|
|
t.Logf("root directory: %s", dir)
|
|
t.Logf("\ninput:\n%s\n", input)
|
|
|
|
ReadAndDownload(dir, strings.NewReader(input))
|
|
|
|
err := fstest.TestFS(
|
|
os.DirFS(dir),
|
|
"text0.txt",
|
|
"text1.txt",
|
|
"image0.webp",
|
|
)
|
|
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|