package falseknees import ( "context" "fmt" "net/http" "net/http/httptest" "os" "testing" ) var ( server *httptest.Server client *Client ) func TestMain(m *testing.M) { handler := func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/index.html" { _, _ = w.Write(indexHTML) return } if r.URL.Path == "/389.html" { _, _ = w.Write(currentHTML) return } if r.URL.Path == "/252.html" { _, _ = w.Write(bunnyHTML) return } w.WriteHeader(http.StatusNotFound) } server = httptest.NewServer(http.HandlerFunc(handler)) baseURL = server.URL + "/" currentComic.Img = fmt.Sprintf("%simgs/389.png", baseURL) bunnyComic.Img = fmt.Sprintf("%simgs/252.png", baseURL) client = New() os.Exit(m.Run()) } func TestCurrent(t *testing.T) { t.Parallel() comic, err := client.Current(context.Background()) if err != nil { t.Logf("could not get current comic: %v\n", err) t.FailNow() } if *comic != currentComic { t.Log("comic does not match test data") t.FailNow() } } func TestComic(t *testing.T) { t.Parallel() comic, err := client.Comic(context.Background(), 252) if err != nil { t.Logf("could not get comic 252: %v\n", err) t.FailNow() } if *comic != bunnyComic { t.Log("comic does not match test data") t.FailNow() } } var ( currentComic = Comic{ Num: 389, Title: "that's the good stuff", } bunnyComic = Comic{ Num: 252, Title: "Spring is the fucking greatest shit", } indexHTML = []byte(`
False Knees © 2013-whenever Joshua Barkman
False Knees © 2013-whenever Joshua Barkman
False Knees © 2013-whenever Joshua Barkman