You've already forked top-wallpaper
Simplify httpGet function in client_test.go for cleaner code
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package reddit
|
package reddit
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -50,12 +49,9 @@ func TestGetLatestImage(t *testing.T) {
|
|||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
// Custom httpGet function for testing
|
// Custom httpGet function for testing
|
||||||
httpGet := func(url string) (*http.Response, error) {
|
httpGet := func() (*http.Response, error) {
|
||||||
if strings.Contains(url, "/r/wallpaper/.json") {
|
|
||||||
return http.Get(server.URL + "/r/wallpaper/.json")
|
return http.Get(server.URL + "/r/wallpaper/.json")
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("unexpected URL: %s", url)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test the function
|
// Test the function
|
||||||
imageURL, err := GetLatestImage(httpGet)
|
imageURL, err := GetLatestImage(httpGet)
|
||||||
|
|||||||
Reference in New Issue
Block a user