32 lines
679 B
Go
32 lines
679 B
Go
|
package coindesk_test
|
||
|
|
||
|
import (
|
||
|
_ "embed"
|
||
|
"encoding/json"
|
||
|
"testing"
|
||
|
|
||
|
"code.humancabbage.net/sam/moonmath/coindesk"
|
||
|
)
|
||
|
|
||
|
func TestUnmarshalPriceValues(t *testing.T) {
|
||
|
testUnmarshalResponse[coindesk.PriceValues](t, priceValuesJson)
|
||
|
}
|
||
|
|
||
|
func TestUnmarshalAssetTickers(t *testing.T) {
|
||
|
testUnmarshalResponse[coindesk.AssetTickers](t, assetTickersJson)
|
||
|
}
|
||
|
|
||
|
func testUnmarshalResponse[T any](t *testing.T, jsonBytes []byte) {
|
||
|
var resp coindesk.Response[T]
|
||
|
err := json.Unmarshal(jsonBytes, &resp)
|
||
|
if err != nil {
|
||
|
t.Errorf("failed to unmarshal JSON: %v", err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//go:embed price_values.json
|
||
|
var priceValuesJson []byte
|
||
|
|
||
|
//go:embed asset_tickers.json
|
||
|
var assetTickersJson []byte
|