Added httptest.NewServer to DecodeFromURL and CryptoOnRamp tests
This commit is contained in:
parent
399090a44b
commit
41cb9d7bea
|
@ -0,0 +1,47 @@
|
|||
[
|
||||
{
|
||||
"name": "Wyre",
|
||||
"description": "A secure bridge for fiat and crypto",
|
||||
"fees": "from 2.9%",
|
||||
"region": "US & Europe",
|
||||
"logoUrl":"https://www.sendwyre.com/favicon.ico",
|
||||
"siteUrl": "https://pay.sendwyre.com/purchase",
|
||||
"hostname": "sendwyre.com"
|
||||
},
|
||||
{
|
||||
"name": "MoonPay",
|
||||
"description": "The new standard for fiat to crypto",
|
||||
"fees": "1%-4.5%",
|
||||
"region": "US & Europe",
|
||||
"logoUrl":"https://buy.moonpay.com/favicon-32x32.png",
|
||||
"siteUrl": "https://buy.moonpay.com",
|
||||
"hostname": "moonpay.com"
|
||||
},
|
||||
{
|
||||
"name": "Transak",
|
||||
"description": "Global fiat <-> crypto payment gateway",
|
||||
"fees": "1%-4.5%",
|
||||
"region": "Global",
|
||||
"logoUrl":"https://global.transak.com/favicon.png",
|
||||
"siteUrl": "https://global.transak.com",
|
||||
"hostname": "transak.com"
|
||||
},
|
||||
{
|
||||
"name": "Ramp",
|
||||
"description": "Global crypto to fiat flow",
|
||||
"fees": "1.5%",
|
||||
"region": "Global",
|
||||
"logoUrl":"https://ramp.network/assets/favicons/favicon-32x32.png",
|
||||
"siteUrl": "https://ramp.network/buy/",
|
||||
"hostname": "ramp.network"
|
||||
},
|
||||
{
|
||||
"name": "LocalCryptos",
|
||||
"description": "Non-custodial crypto marketplace",
|
||||
"fees": "1.5%",
|
||||
"region": "Global",
|
||||
"logoUrl":"https://localcryptos.com/images/favicon.png",
|
||||
"siteUrl": "https://localcryptos.com",
|
||||
"hostname": "localcryptos.com"
|
||||
}
|
||||
]
|
|
@ -4,9 +4,8 @@ import (
|
|||
"errors"
|
||||
"image"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -88,16 +87,8 @@ func TestDecode(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)
|
||||
s := httptest.NewServer(http.FileServer(http.Dir(path)))
|
||||
defer s.Close()
|
||||
|
||||
cs := []struct {
|
||||
Filepath string
|
||||
|
@ -105,7 +96,7 @@ func TestDecodeFromURL(t *testing.T) {
|
|||
Bounds image.Rectangle
|
||||
}{
|
||||
{
|
||||
u.String() + "/2x1.png",
|
||||
s.URL + "/2x1.png",
|
||||
false,
|
||||
image.Rectangle{
|
||||
Min: image.Point{X: 0, Y: 0},
|
||||
|
@ -113,7 +104,7 @@ func TestDecodeFromURL(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
u.String() + "/1.jpg",
|
||||
s.URL + "/1.jpg",
|
||||
false,
|
||||
image.Rectangle{
|
||||
Min: image.Point{X: 0, Y: 0},
|
||||
|
@ -121,7 +112,7 @@ func TestDecodeFromURL(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
u.String() + "/1.gif",
|
||||
s.URL + "/1.gif",
|
||||
false,
|
||||
image.Rectangle{
|
||||
Min: image.Point{X: 0, Y: 0},
|
||||
|
@ -129,7 +120,7 @@ func TestDecodeFromURL(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
u.String() + "/1.webp",
|
||||
s.URL + "/1.webp",
|
||||
false,
|
||||
image.Rectangle{
|
||||
Min: image.Point{X: 0, Y: 0},
|
||||
|
@ -137,7 +128,7 @@ func TestDecodeFromURL(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
u.String() + "/1.webp",
|
||||
s.URL + "/1.webp",
|
||||
true,
|
||||
image.Rectangle{
|
||||
Min: image.Point{X: 0, Y: 0},
|
||||
|
|
|
@ -119,7 +119,6 @@ func LinkPreviewWhitelist() []Site {
|
|||
}
|
||||
|
||||
func GetURLContent(url string) (data []byte, err error) {
|
||||
// nolint: gosec
|
||||
response, err := httpClient.Get(url)
|
||||
if err != nil {
|
||||
return data, fmt.Errorf("can't get content from link %s", url)
|
||||
|
|
|
@ -10,8 +10,6 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
cryptoOnRampsData = "https://raw.githubusercontent.com/status-im/crypto-on-ramps/master/ramps.json"
|
||||
|
||||
DataSourceHTTP DataSourceType = iota + 1
|
||||
DataSourceStatic
|
||||
)
|
||||
|
|
|
@ -1,18 +1,27 @@
|
|||
package wallet
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
path = "../../_assets/tests/"
|
||||
)
|
||||
|
||||
func TestCryptoOnRamps_Get(t *testing.T) {
|
||||
s := httptest.NewServer(http.FileServer(http.Dir(path)))
|
||||
defer s.Close()
|
||||
|
||||
cs := []*CryptoOnRampManager{
|
||||
{options: &CryptoOnRampOptions{dataSourceType: DataSourceStatic}},
|
||||
{options: &CryptoOnRampOptions{
|
||||
dataSourceType: DataSourceHTTP,
|
||||
dataSource: cryptoOnRampsData,
|
||||
dataSource: s.URL + "/ramps.json",
|
||||
}},
|
||||
}
|
||||
|
||||
|
@ -26,9 +35,12 @@ func TestCryptoOnRamps_Get(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCryptoOnRampManager_hasCacheExpired(t *testing.T) {
|
||||
s := httptest.NewServer(http.FileServer(http.Dir(path)))
|
||||
defer s.Close()
|
||||
|
||||
corm := NewCryptoOnRampManager(&CryptoOnRampOptions{
|
||||
dataSourceType: DataSourceHTTP,
|
||||
dataSource: cryptoOnRampsData,
|
||||
dataSource: s.URL + "/ramps.json",
|
||||
})
|
||||
nt := time.Time{}.Add(30 * time.Minute)
|
||||
|
||||
|
|
Loading…
Reference in New Issue