Added fix for pinging a remote service in tests

This commit is contained in:
Samuel Hawksby-Robinson 2022-08-09 16:04:28 +01:00
parent 1d5e19cf96
commit 399090a44b
5 changed files with 19 additions and 5 deletions

BIN
_assets/tests/1.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 B

BIN
_assets/tests/1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 B

BIN
_assets/tests/1.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 B

BIN
_assets/tests/2x1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 B

View File

@ -3,7 +3,10 @@ package images
import ( import (
"errors" "errors"
"image" "image"
"net/http"
"net/url"
"testing" "testing"
"time"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -85,13 +88,24 @@ func TestDecode(t *testing.T) {
} }
func TestDecodeFromURL(t *testing.T) { func TestDecodeFromURL(t *testing.T) {
u := url.URL{
Scheme: "http",
Host: "localhost:8089",
}
go func() {
err := http.ListenAndServe(u.Host, http.FileServer(http.Dir("../_assets/tests")))
require.NoError(t, err)
}()
time.Sleep(100 * time.Millisecond)
cs := []struct { cs := []struct {
Filepath string Filepath string
Nil bool Nil bool
Bounds image.Rectangle Bounds image.Rectangle
}{ }{
{ {
"https://via.placeholder.com/2x1.png", u.String() + "/2x1.png",
false, false,
image.Rectangle{ image.Rectangle{
Min: image.Point{X: 0, Y: 0}, Min: image.Point{X: 0, Y: 0},
@ -99,7 +113,7 @@ func TestDecodeFromURL(t *testing.T) {
}, },
}, },
{ {
"https://via.placeholder.com/1.jpg", u.String() + "/1.jpg",
false, false,
image.Rectangle{ image.Rectangle{
Min: image.Point{X: 0, Y: 0}, Min: image.Point{X: 0, Y: 0},
@ -107,7 +121,7 @@ func TestDecodeFromURL(t *testing.T) {
}, },
}, },
{ {
"https://via.placeholder.com/1.gif", u.String() + "/1.gif",
false, false,
image.Rectangle{ image.Rectangle{
Min: image.Point{X: 0, Y: 0}, Min: image.Point{X: 0, Y: 0},
@ -115,7 +129,7 @@ func TestDecodeFromURL(t *testing.T) {
}, },
}, },
{ {
"https://via.placeholder.com/1.webp", u.String() + "/1.webp",
false, false,
image.Rectangle{ image.Rectangle{
Min: image.Point{X: 0, Y: 0}, Min: image.Point{X: 0, Y: 0},
@ -123,7 +137,7 @@ func TestDecodeFromURL(t *testing.T) {
}, },
}, },
{ {
"https://via.placeholder.com/1.webp", u.String() + "/1.webp",
true, true,
image.Rectangle{ image.Rectangle{
Min: image.Point{X: 0, Y: 0}, Min: image.Point{X: 0, Y: 0},