mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-06-16 04:44:55 +02:00
rename EosioContract to AtomicAsset.
This commit is contained in:
parent
1b1f601678
commit
2b0b32b5ab
4 changed files with 41 additions and 41 deletions
|
|
@ -8,18 +8,18 @@ import (
|
|||
"github.com/eosswedenorg/eosio-api-healthcheck/internal/utils"
|
||||
)
|
||||
|
||||
type EosioContract struct {
|
||||
type AtomicAsset struct {
|
||||
utils.Time
|
||||
client atomicasset.Client
|
||||
block_time float64
|
||||
}
|
||||
|
||||
func EosioContractFactory(args ApiArguments) ApiInterface {
|
||||
return NewEosioContract(args.Url, float64(args.NumBlocks/2))
|
||||
func AtomicAssetFactory(args ApiArguments) ApiInterface {
|
||||
return NewAtomicAsset(args.Url, float64(args.NumBlocks/2))
|
||||
}
|
||||
|
||||
func NewEosioContract(url string, block_time float64) EosioContract {
|
||||
return EosioContract{
|
||||
func NewAtomicAsset(url string, block_time float64) AtomicAsset {
|
||||
return AtomicAsset{
|
||||
client: atomicasset.Client{
|
||||
URL: url,
|
||||
},
|
||||
|
|
@ -27,15 +27,15 @@ func NewEosioContract(url string, block_time float64) EosioContract {
|
|||
}
|
||||
}
|
||||
|
||||
func (e EosioContract) LogInfo() LogParams {
|
||||
func (e AtomicAsset) LogInfo() LogParams {
|
||||
return LogParams{
|
||||
"type", "eosio-contract",
|
||||
"type", "atomicasset",
|
||||
"url", e.client.URL,
|
||||
"block_time", e.block_time,
|
||||
}
|
||||
}
|
||||
|
||||
func (e EosioContract) Call() (agentcheck.Response, string) {
|
||||
func (e AtomicAsset) Call() (agentcheck.Response, string) {
|
||||
h, err := e.client.GetHealth()
|
||||
if err != nil {
|
||||
resp := agentcheck.NewStatusMessageResponse(agentcheck.Failed, "")
|
||||
|
|
@ -10,32 +10,32 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEosioContractFactory(t *testing.T) {
|
||||
api := EosioContractFactory(ApiArguments{
|
||||
func TestAtomicAssetFactory(t *testing.T) {
|
||||
api := AtomicAssetFactory(ApiArguments{
|
||||
Url: "https://atomic.example.com",
|
||||
NumBlocks: 120,
|
||||
})
|
||||
|
||||
expected := NewEosioContract("https://atomic.example.com", 60)
|
||||
expected := NewAtomicAsset("https://atomic.example.com", 60)
|
||||
|
||||
assert.IsType(t, expected, api)
|
||||
assert.Equal(t, expected.client.URL, api.(EosioContract).client.URL)
|
||||
assert.Equal(t, expected.client.Host, api.(EosioContract).client.Host)
|
||||
assert.Equal(t, expected.block_time, api.(EosioContract).block_time)
|
||||
assert.Equal(t, expected.client.URL, api.(AtomicAsset).client.URL)
|
||||
assert.Equal(t, expected.client.Host, api.(AtomicAsset).client.Host)
|
||||
assert.Equal(t, expected.block_time, api.(AtomicAsset).block_time)
|
||||
}
|
||||
|
||||
func TestEosioContractLogInfo(t *testing.T) {
|
||||
api := NewEosioContract("https://atomic.example.com", 120)
|
||||
func TestAtomicAssetLogInfo(t *testing.T) {
|
||||
api := NewAtomicAsset("https://atomic.example.com", 120)
|
||||
|
||||
expected := LogParams{"type", "eosio-contract", "url", "https://atomic.example.com", "block_time", float64(120)}
|
||||
expected := LogParams{"type", "atomicasset", "url", "https://atomic.example.com", "block_time", float64(120)}
|
||||
|
||||
assert.Equal(t, expected, api.LogInfo())
|
||||
}
|
||||
|
||||
func TestEosioContractSetTime(t *testing.T) {
|
||||
func TestAtomicAssetSetTime(t *testing.T) {
|
||||
expected := time.Date(2019, 3, 18, 20, 29, 32, 0, time.UTC)
|
||||
|
||||
api := NewEosioContract("", 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))
|
||||
|
||||
|
|
@ -43,26 +43,26 @@ func TestEosioContractSetTime(t *testing.T) {
|
|||
assert.Equal(t, expected, api.GetTime())
|
||||
}
|
||||
|
||||
func TestEosioContractJsonFailure(t *testing.T) {
|
||||
func TestAtomicAssetJsonFailure(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
res.Write([]byte(`!//{invalid-json}!##`))
|
||||
}))
|
||||
|
||||
api := NewEosioContract(srv.URL, 120)
|
||||
api := NewAtomicAsset(srv.URL, 120)
|
||||
check, _ := api.Call()
|
||||
|
||||
expected := agentcheck.NewStatusMessageResponse(agentcheck.Failed, "")
|
||||
assert.Equal(t, expected, check)
|
||||
}
|
||||
|
||||
func TestEosioContractHTTP500Down(t *testing.T) {
|
||||
func TestAtomicAssetHTTP500Down(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
res.Header().Add("Content-type", "application/json; charset=utf-8")
|
||||
res.WriteHeader(500)
|
||||
res.Write([]byte(`{}`))
|
||||
}))
|
||||
|
||||
api := NewEosioContract(srv.URL, 120)
|
||||
api := NewAtomicAsset(srv.URL, 120)
|
||||
check, status := api.Call()
|
||||
|
||||
assert.Equal(t, "Taking offline because 500 was received from backend", status)
|
||||
|
|
@ -71,7 +71,7 @@ func TestEosioContractHTTP500Down(t *testing.T) {
|
|||
assert.Equal(t, expected, check)
|
||||
}
|
||||
|
||||
func TestEosioContractLaggingUp(t *testing.T) {
|
||||
func TestAtomicAssetLaggingUp(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
if req.URL.String() == "/health" {
|
||||
payload := `{
|
||||
|
|
@ -98,7 +98,7 @@ func TestEosioContractLaggingUp(t *testing.T) {
|
|||
}
|
||||
}))
|
||||
|
||||
api := NewEosioContract(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()
|
||||
|
|
@ -109,7 +109,7 @@ func TestEosioContractLaggingUp(t *testing.T) {
|
|||
assert.Equal(t, expected, check)
|
||||
}
|
||||
|
||||
func TestEosioContractLaggingDown(t *testing.T) {
|
||||
func TestAtomicAssetLaggingDown(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
if req.URL.String() == "/health" {
|
||||
payload := `{
|
||||
|
|
@ -136,7 +136,7 @@ func TestEosioContractLaggingDown(t *testing.T) {
|
|||
}
|
||||
}))
|
||||
|
||||
api := NewEosioContract(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()
|
||||
|
|
@ -147,7 +147,7 @@ func TestEosioContractLaggingDown(t *testing.T) {
|
|||
assert.Equal(t, expected, check)
|
||||
}
|
||||
|
||||
func TestEosioContractInFutureUp(t *testing.T) {
|
||||
func TestAtomicAssetInFutureUp(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
if req.URL.String() == "/health" {
|
||||
payload := `{
|
||||
|
|
@ -174,7 +174,7 @@ func TestEosioContractInFutureUp(t *testing.T) {
|
|||
}
|
||||
}))
|
||||
|
||||
api := NewEosioContract(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()
|
||||
|
|
@ -185,7 +185,7 @@ func TestEosioContractInFutureUp(t *testing.T) {
|
|||
assert.Equal(t, expected, check)
|
||||
}
|
||||
|
||||
func TestEosioContractInFutureDown(t *testing.T) {
|
||||
func TestAtomicAssetInFutureDown(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
if req.URL.String() == "/health" {
|
||||
payload := `{
|
||||
|
|
@ -212,7 +212,7 @@ func TestEosioContractInFutureDown(t *testing.T) {
|
|||
}
|
||||
}))
|
||||
|
||||
api := NewEosioContract(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()
|
||||
|
|
@ -223,7 +223,7 @@ func TestEosioContractInFutureDown(t *testing.T) {
|
|||
assert.Equal(t, expected, check)
|
||||
}
|
||||
|
||||
func TestEosioContractRedisDown(t *testing.T) {
|
||||
func TestAtomicAssetRedisDown(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
if req.URL.String() == "/health" {
|
||||
payload := `{
|
||||
|
|
@ -250,7 +250,7 @@ func TestEosioContractRedisDown(t *testing.T) {
|
|||
}
|
||||
}))
|
||||
|
||||
api := NewEosioContract(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()
|
||||
|
|
@ -261,7 +261,7 @@ func TestEosioContractRedisDown(t *testing.T) {
|
|||
assert.Equal(t, expected, check)
|
||||
}
|
||||
|
||||
func TestEosioContractPostgresDown(t *testing.T) {
|
||||
func TestAtomicAssetPostgresDown(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
if req.URL.String() == "/health" {
|
||||
payload := `{
|
||||
|
|
@ -288,7 +288,7 @@ func TestEosioContractPostgresDown(t *testing.T) {
|
|||
}
|
||||
}))
|
||||
|
||||
api := NewEosioContract(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()
|
||||
|
|
@ -36,7 +36,7 @@ func ParseRequest(request string) (api.ApiInterface, error) {
|
|||
factories := map[string]api.Factory{
|
||||
"v1": api.EosioV1Factory,
|
||||
"v2": api.EosioV2Factory,
|
||||
"contract": api.EosioContractFactory,
|
||||
"contract": api.AtomicAssetFactory,
|
||||
"debug": api.DebugApiFactory,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,19 +76,19 @@ func TestParseEosioV2Full(t *testing.T) {
|
|||
assert.Equal(t, expected.LogInfo(), api.LogInfo())
|
||||
}
|
||||
|
||||
// EosioContract
|
||||
// AtomicAsset
|
||||
// --------------------------------
|
||||
|
||||
func TestParseEosioContract(t *testing.T) {
|
||||
expected := api.NewEosioContract("http://api.contract.example.com", 5)
|
||||
func TestParseAtomicAsset(t *testing.T) {
|
||||
expected := api.NewAtomicAsset("http://api.contract.example.com", 5)
|
||||
|
||||
api, err := ParseRequest("contract|http://api.contract.example.com")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expected.LogInfo(), api.LogInfo())
|
||||
}
|
||||
|
||||
func TestParseEosioContractWithBlockTime(t *testing.T) {
|
||||
expected := api.NewEosioContract("http://api.contract.example.com", 256)
|
||||
func TestParseAtomicAssetWithBlockTime(t *testing.T) {
|
||||
expected := api.NewAtomicAsset("http://api.contract.example.com", 256)
|
||||
|
||||
api, err := ParseRequest("contract|http://api.contract.example.com|512")
|
||||
assert.NoError(t, err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue