Improve coindesk package tests.

This commit is contained in:
Sam Fredrickson 2024-03-19 18:35:22 -07:00
parent 83fd89446d
commit 15a7052389
4 changed files with 33 additions and 29 deletions

View File

@ -0,0 +1 @@
{"statusCode":200,"message":"OK","data":{"BTC":{"iso":"BTC","name":"Bitcoin","slug":"bitcoin","change":{"percent":-6.3,"value":-4187.634882541},"ohlc":{"o":66436.26558132548,"h":66436.26558132548,"l":61526.78744328402,"c":62248.630698784444},"circulatingSupply":19658987,"marketCap":1223745021675.2043,"ts":1710898259000,"src":"tb"}}}

View File

@ -1,29 +0,0 @@
package coindesk_test
import (
"context"
"fmt"
"testing"
"time"
"code.humancabbage.net/sam/moonmath/coindesk"
)
func TestXxx(t *testing.T) {
now := time.Now()
then := now.Add(time.Duration(-24) * time.Hour)
values, err := coindesk.GetPriceValues(context.Background(), coindesk.BTC, then, now)
if err != nil {
t.Errorf("test failure: %v", err)
}
_ = values
fmt.Println()
tickers, err := coindesk.GetAssetTickers(context.Background(), coindesk.BTC, coindesk.ETH)
if err != nil {
t.Errorf("test failure: %v", err)
}
_ = tickers
fmt.Println()
}

31
coindesk/model_test.go Normal file
View File

@ -0,0 +1,31 @@
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

View File

@ -0,0 +1 @@
{"statusCode":200,"message":"OK","data":{"iso":"BTC","name":"Bitcoin","slug":"bitcoin","ingestionStart":"2014-11-03","interval":"15m","src":"tb","entries":[[1710548099000,69784.6599201257],[1710548999000,69907.6435505413],[1710549899000,69735.0244223474],[1710550799000,69608.3777481736],[1710551699000,69643.5872644923],[1710552599000,69389.4883714119],[1710553499000,69350.2996335944],[1710554399000,69241.2719800575],[1710555299000,69110.5930246779],[1710556199000,69046.5706710773],[1710557099000,69209.8770692447],[1710557999000,69069.0204183649],[1710558899000,69317.6327892521],[1710559799000,69175.2057532632],[1710560699000,69237.706076427],[1710561599000,69206.0448006493],[1710562499000,69077.8264056849],[1710563399000,69161.0784263752],[1710564299000,68903.1424009851],[1710565199000,68994.5234182921],[1710566099000,68754.9875193438],[1710566999000,68784.6200740683],[1710567899000,69002.1375650817],[1710568799000,68975.0878307215],[1710569699000,69045.2310776643],[1710570599000,69025.7239355934],[1710571499000,69068.3988090268],[1710572399000,69185.2444741912],[1710573299000,69246.5439171529],[1710574199000,69278.2574941136],[1710575099000,69407.4780576693],[1710575999000,69406.4527711537],[1710576899000,69296.4923727422],[1710577799000,69165.948416751],[1710578699000,69258.7912250956],[1710579599000,69017.1102984366],[1710580499000,69014.4480481396],[1710581399000,69099.3096696255],[1710582299000,69011.246072562],[1710583199000,68942.5343294262],[1710584099000,68697.8235476743],[1710584999000,68597.1119491188],[1710585899000,68532.2931864276],[1710586799000,68420.1712986066],[1710587699000,68354.8847177761],[1710588599000,67949.5219527423],[1710589499000,68327.2101380853],[1710590399000,68260.6576285653],[1710591299000,68192.7968537126],[1710592199000,68302.103987459],[1710593099000,68096.4362930929],[1710593999000,67906.8863092216],[1710594899000,67982.183818933],[1710595799000,68073.3862259585],[1710596699000,67891.8144823227],[1710597599000,67706.923652975],[1710598499000,67942.4174766702],[1710599399000,67848.3672161555],[1710600299000,67975.9404080798],[1710601199000,68177.0804610881],[1710602099000,67994.5903423281],[1710602999000,68024.8507494152],[1710603899000,68201.8594048759],[1710604799000,68358.4188016011],[1710605699000,68239.5960888028],[1710606599000,68224.3438496054],[1710607499000,68293.736596961],[1710608399000,68158.4057208716],[1710609299000,68114.4234280406],[1710610199000,67829.2127954109],[1710611099000,67630.8190396486],[1710611999000,67220.3085172518],[1710612899000,67043.4786652409],[1710613799000,66906.1713676385],[1710614699000,66871.2079622553],[1710615599000,67015.8311895788],[1710616499000,67458.766887969],[1710617399000,67493.9852796663],[1710618299000,67354.2332686561],[1710619199000,66916.4704143146],[1710620099000,66995.7196236024],[1710620999000,67046.4965828003],[1710621899000,67402.0503271179],[1710622799000,67087.3064846683],[1710623699000,66943.270112864],[1710624599000,66268.8656111216],[1710625499000,66290.9133774055],[1710626399000,66189.3483322972],[1710627299000,66073.8513767399],[1710628199000,66433.8329094007],[1710629099000,66549.3543050487],[1710629999000,66331.1108451565],[1710630899000,65376.9600942977],[1710631799000,65280.3933464042],[1710632699000,65598.1187015513],[1710633599000,65261.5180497119],[1710634499000,65780.8283123471]]}}