1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-06-16 04:44:55 +02:00

internal/api/atomicasset.go: Support host parameter.

This commit is contained in:
Henrik Hautakoski 2023-02-07 08:38:21 +01:00
parent f0ab79ef06
commit 59399c7cf4
No known key found for this signature in database
GPG key ID: 217490840C18A5D9
3 changed files with 18 additions and 15 deletions

View file

@ -13,16 +13,18 @@ type AtomicAsset struct {
utils.Time
url string
host string
block_time float64
}
func AtomicAssetFactory(args ApiArguments) ApiInterface {
return NewAtomicAsset(args.Url, float64(args.NumBlocks/2))
return NewAtomicAsset(args.Url, args.Host, float64(args.NumBlocks/2))
}
func NewAtomicAsset(url string, block_time float64) AtomicAsset {
func NewAtomicAsset(url string, host string, block_time float64) AtomicAsset {
return AtomicAsset{
url: url,
host: host,
block_time: block_time,
}
}
@ -37,6 +39,7 @@ func (e AtomicAsset) LogInfo() LogParams {
func (e AtomicAsset) Call(ctx context.Context) (agentcheck.Response, string) {
client := atomicasset.NewWithContext(e.url, ctx)
client.Host = e.host
h, err := client.GetHealth()
if err != nil {

View file

@ -17,7 +17,7 @@ func TestAtomicAsset_Factory(t *testing.T) {
NumBlocks: 120,
})
expected := NewAtomicAsset("https://atomic.example.com", 60)
expected := NewAtomicAsset("https://atomic.example.com", "", 60)
assert.IsType(t, expected, api)
assert.Equal(t, expected.url, api.(AtomicAsset).url)
@ -25,7 +25,7 @@ func TestAtomicAsset_Factory(t *testing.T) {
}
func TestAtomicAsset_LogInfo(t *testing.T) {
api := NewAtomicAsset("https://atomic.example.com", 120)
api := NewAtomicAsset("https://atomic.example.com", "", 120)
expected := LogParams{"type", "atomicasset", "url", "https://atomic.example.com", "block_time", float64(120)}
@ -35,7 +35,7 @@ func TestAtomicAsset_LogInfo(t *testing.T) {
func TestAtomicAsset_SetTime(t *testing.T) {
expected := time.Date(2019, 3, 18, 20, 29, 32, 0, time.UTC)
api := NewAtomicAsset("", 60)
api := NewAtomicAsset("", "", 60)
// Assert that time is NOW (+-10 seconds)
assert.InDelta(t, api.GetTime().Unix(), time.Now().In(time.UTC).Unix(), float64(10))
@ -49,7 +49,7 @@ func TestAtomicAsset_JsonFailure(t *testing.T) {
assert.NoError(t, err)
}))
api := NewAtomicAsset(srv.URL, 120)
api := NewAtomicAsset(srv.URL, "", 120)
check, _ := api.Call(context.Background())
expected := agentcheck.NewStatusMessageResponse(agentcheck.Fail, "")
@ -64,7 +64,7 @@ func TestAtomicAsset_HTTP500Down(t *testing.T) {
assert.NoError(t, err)
}))
api := NewAtomicAsset(srv.URL, 120)
api := NewAtomicAsset(srv.URL, "", 120)
check, status := api.Call(context.Background())
assert.Equal(t, "Taking offline because 500 was received from backend", status)
@ -101,7 +101,7 @@ func TestAtomicAsset_LaggingUp(t *testing.T) {
}
}))
api := NewAtomicAsset(srv.URL, 120)
api := NewAtomicAsset(srv.URL, "", 120)
api.SetTime(time.Date(2025, 10, 8, 20, 7, 27, 0, time.UTC))
check, status := api.Call(context.Background())
@ -140,7 +140,7 @@ func TestAtomicAsset_LaggingDown(t *testing.T) {
}
}))
api := NewAtomicAsset(srv.URL, 120)
api := NewAtomicAsset(srv.URL, "", 120)
api.SetTime(time.Date(2018, 8, 5, 6, 53, 35, 0, time.UTC))
check, status := api.Call(context.Background())
@ -179,7 +179,7 @@ func TestAtomicAsset_InFutureUp(t *testing.T) {
}
}))
api := NewAtomicAsset(srv.URL, 120)
api := NewAtomicAsset(srv.URL, "", 120)
api.SetTime(time.Date(2024, 10, 15, 1, 9, 16, 500, time.UTC))
check, status := api.Call(context.Background())
@ -218,7 +218,7 @@ func TestAtomicAsset_InFutureDown(t *testing.T) {
}
}))
api := NewAtomicAsset(srv.URL, 120)
api := NewAtomicAsset(srv.URL, "", 120)
api.SetTime(time.Date(2002, 12, 29, 0, 45, 0o3, 500, time.UTC))
check, status := api.Call(context.Background())
@ -257,7 +257,7 @@ func TestAtomicAsset_RedisDown(t *testing.T) {
}
}))
api := NewAtomicAsset(srv.URL, 120)
api := NewAtomicAsset(srv.URL, "", 120)
api.SetTime(time.Date(2015, 3, 11, 11, 19, 30, 500, time.UTC))
check, status := api.Call(context.Background())
@ -296,7 +296,7 @@ func TestAtomicAsset_PostgresDown(t *testing.T) {
}
}))
api := NewAtomicAsset(srv.URL, 120)
api := NewAtomicAsset(srv.URL, "", 120)
api.SetTime(time.Date(2019, 7, 11, 18, 6, 11, 500, time.UTC))
check, status := api.Call(context.Background())

View file

@ -80,7 +80,7 @@ func TestParseRequest_AntelopeV2Full(t *testing.T) {
// --------------------------------
func TestParseRequest_AtomicAsset(t *testing.T) {
expected := api.NewAtomicAsset("http://api.atomicassets.io", 5)
expected := api.NewAtomicAsset("http://api.atomicassets.io", "", 5)
api, err := ParseRequest("atomic|http://api.atomicassets.io")
assert.NoError(t, err)
@ -88,7 +88,7 @@ func TestParseRequest_AtomicAsset(t *testing.T) {
}
func TestParseRequest_AtomicAssetWithBlockTime(t *testing.T) {
expected := api.NewAtomicAsset("http://api.atomicassets.io", 256)
expected := api.NewAtomicAsset("http://api.atomicassets.io", "", 256)
api, err := ParseRequest("atomic|http://api.atomicassets.io|512")
assert.NoError(t, err)