2024-05-28 13:16:15 +00:00
|
|
|
package onramp
|
2021-01-26 13:00:32 +00:00
|
|
|
|
|
|
|
import (
|
2022-08-09 22:54:44 +00:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
2021-01-26 13:00:32 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-08-09 22:54:44 +00:00
|
|
|
const (
|
2024-05-28 13:16:15 +00:00
|
|
|
path = "../../../_assets/tests/"
|
2022-08-09 22:54:44 +00:00
|
|
|
)
|
|
|
|
|
2021-01-26 13:00:32 +00:00
|
|
|
func TestCryptoOnRamps_Get(t *testing.T) {
|
2022-08-09 22:54:44 +00:00
|
|
|
s := httptest.NewServer(http.FileServer(http.Dir(path)))
|
|
|
|
defer s.Close()
|
|
|
|
|
2024-05-28 13:16:15 +00:00
|
|
|
cs := []*Manager{
|
|
|
|
{options: &Options{DataSourceType: DataSourceStatic}},
|
|
|
|
{options: &Options{
|
|
|
|
DataSourceType: DataSourceHTTP,
|
|
|
|
DataSource: s.URL + "/ramps.json",
|
2021-01-26 13:00:32 +00:00
|
|
|
}},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, corm := range cs {
|
|
|
|
require.Equal(t, 0, len(corm.ramps))
|
|
|
|
|
|
|
|
rs, err := corm.Get()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Greater(t, len(rs), 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCryptoOnRampManager_hasCacheExpired(t *testing.T) {
|
2022-08-09 22:54:44 +00:00
|
|
|
s := httptest.NewServer(http.FileServer(http.Dir(path)))
|
|
|
|
defer s.Close()
|
|
|
|
|
2024-05-28 13:16:15 +00:00
|
|
|
corm := NewManager(&Options{
|
|
|
|
DataSourceType: DataSourceHTTP,
|
|
|
|
DataSource: s.URL + "/ramps.json",
|
2021-01-26 13:00:32 +00:00
|
|
|
})
|
|
|
|
nt := time.Time{}.Add(30 * time.Minute)
|
|
|
|
|
|
|
|
require.False(t, corm.hasCacheExpired(nt))
|
|
|
|
require.True(t, corm.hasCacheExpired(time.Now()))
|
|
|
|
|
|
|
|
_, err := corm.Get()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, corm.hasCacheExpired(time.Now()))
|
|
|
|
require.True(t, corm.hasCacheExpired(time.Now().Add(2*time.Hour)))
|
|
|
|
}
|