本文整理汇总了Golang中github.com/stellar/go-horizon/test.LoadScenario函数的典型用法代码示例。如果您正苦于以下问题:Golang LoadScenario函数的具体用法?Golang LoadScenario怎么用?Golang LoadScenario使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LoadScenario函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestPaymentActions
func TestPaymentActions(t *testing.T) {
test.LoadScenario("base")
app := NewTestApp()
defer app.Close()
rh := NewRequestHelper(app)
Convey("Payment Actions:", t, func() {
Convey("GET /payments", func() {
w := rh.Get("/payments", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 4)
})
Convey("GET /ledgers/:ledger_id/payments", func() {
w := rh.Get("/ledgers/2/payments", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 0)
w = rh.Get("/ledgers/4/payments", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 1)
})
Convey("GET /accounts/:account_id/payments", func() {
w := rh.Get("/accounts/gT9jHoPKoErFwXavCrDYLkSVcVd9oyVv94ydrq6FnPMXpKHPTA/payments", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 1)
test.LoadScenario("pathed_payment")
w = rh.Get("/accounts/gsDu9aPmZy7uH5FzmfJKW7jWyXGHjSWbcb8k6UH743pYzaxWcWd/payments", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 3)
})
Convey("GET /transactions/:tx_id/payments", func() {
test.LoadScenario("pathed_payment")
w := rh.Get("/transactions/dffaa6b14246bb4cc3ab8ac414aec9cb93e86003cb22ff1297b3fe4623974d98/payments", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 0)
w = rh.Get("/transactions/ab38509dc9e16c08b084d7f7279fd45f5f4d348ab3b2ed9877c697beaa7e4108/payments", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 1)
})
})
}
开发者ID:jacksonh,项目名称:go-horizon,代码行数:49,代码来源:actions_payment_test.go
示例2: TestAccountActions
func TestAccountActions(t *testing.T) {
Convey("Account Actions:", t, func() {
test.LoadScenario("base")
app := NewTestApp()
defer app.Close()
rh := NewRequestHelper(app)
Convey("GET /accounts/GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ", func() {
w := rh.Get("/accounts/GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
var result AccountResource
err := json.Unmarshal(w.Body.Bytes(), &result)
So(err, ShouldBeNil)
So(result.Sequence, ShouldEqual, 3)
})
Convey("GET /accounts/100", func() {
w := rh.Get("/accounts/100", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 404)
})
Convey("GET /accounts", func() {
w := rh.Get("/accounts", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 3)
w = rh.Get("/accounts?limit=1", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 1)
})
})
}
开发者ID:FredericHeem,项目名称:go-horizon,代码行数:35,代码来源:actions_account_test.go
示例3: TestHistoryAccountByAddressQuery
func TestHistoryAccountByAddressQuery(t *testing.T) {
test.LoadScenario("base")
Convey("AccountByAddress", t, func() {
var account HistoryAccountRecord
Convey("Existing record behavior", func() {
address := "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ"
q := HistoryAccountByAddressQuery{
SqlQuery{history},
address,
}
err := Get(ctx, q, &account)
So(err, ShouldBeNil)
So(account.Id, ShouldEqual, 0)
So(account.Address, ShouldEqual, address)
})
Convey("Missing record behavior", func() {
address := "not real"
q := HistoryAccountByAddressQuery{
SqlQuery{history},
address,
}
err := Get(ctx, q, &account)
So(err, ShouldEqual, ErrNoResults)
})
})
}
开发者ID:FredericHeem,项目名称:go-horizon,代码行数:30,代码来源:query_history_account_by_address_test.go
示例4: TestOperationByIdQuery
func TestOperationByIdQuery(t *testing.T) {
test.LoadScenario("base")
Convey("OperationByIdQuery", t, func() {
var op OperationRecord
Convey("Existing record behavior", func() {
id := int64(8589938688)
q := OperationByIdQuery{
SqlQuery{history},
id,
}
err := Get(ctx, q, &op)
So(err, ShouldBeNil)
So(op.Id, ShouldEqual, id)
So(op.TransactionId, ShouldEqual, id)
})
Convey("Missing record behavior", func() {
id := int64(0)
q := OperationByIdQuery{
SqlQuery{history},
id,
}
err := Get(ctx, q, &op)
So(err, ShouldEqual, ErrNoResults)
})
})
}
开发者ID:FredericHeem,项目名称:go-horizon,代码行数:30,代码来源:query_operation_by_id_test.go
示例5: TestLedgerPageQuery
func TestLedgerPageQuery(t *testing.T) {
test.LoadScenario("base")
var records []LedgerRecord
Convey("LedgerPageQuery", t, func() {
pq, err := NewPageQuery("", "asc", 2)
So(err, ShouldBeNil)
q := LedgerPageQuery{SqlQuery{history}, pq}
err = Select(ctx, q, &records)
So(err, ShouldBeNil)
So(len(records), ShouldEqual, 2)
So(records, ShouldBeOrderedAscending, func(r interface{}) int64 {
return r.(LedgerRecord).Id
})
lastLedger := records[len(records)-1]
q.Cursor = lastLedger.PagingToken()
err = Select(ctx, q, &records)
So(err, ShouldBeNil)
t.Log(records)
So(len(records), ShouldEqual, 1)
})
}
开发者ID:FredericHeem,项目名称:go-horizon,代码行数:28,代码来源:query_ledger_page_test.go
示例6: TestAccountByAddressQuery
func TestAccountByAddressQuery(t *testing.T) {
test.LoadScenario("non_native_payment")
Convey("AccountByAddress", t, func() {
var account AccountRecord
notreal := "not_real"
withtl := "GBXGQJWVLWOYHFLVTKWV5FGHA3LNYY2JQKM7OAJAUEQFU6LPCSEFVXON"
notl := "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ"
q := AccountByAddressQuery{
Core: SqlQuery{core},
History: SqlQuery{history},
Address: withtl,
}
err := Get(ctx, q, &account)
So(err, ShouldBeNil)
So(account.Address, ShouldEqual, withtl)
So(account.Seqnum, ShouldEqual, 8589934593)
So(len(account.Trustlines), ShouldEqual, 1)
q.Address = notl
err = Get(ctx, q, &account)
So(err, ShouldBeNil)
So(len(account.Trustlines), ShouldEqual, 0)
q.Address = notreal
err = Get(ctx, q, &account)
So(err, ShouldEqual, ErrNoResults)
})
}
开发者ID:FredericHeem,项目名称:go-horizon,代码行数:33,代码来源:query_account_by_address_test.go
示例7: TestLedgerBySequenceQuery
func TestLedgerBySequenceQuery(t *testing.T) {
Convey("LedgerBySequenceQuery", t, func() {
test.LoadScenario("base")
var record LedgerRecord
Convey("Existing record behavior", func() {
sequence := int32(2)
q := LedgerBySequenceQuery{
SqlQuery{history},
sequence,
}
err := Get(ctx, q, &record)
So(err, ShouldBeNil)
So(record.Sequence, ShouldEqual, sequence)
})
Convey("Missing record behavior", func() {
sequence := int32(-1)
query := LedgerBySequenceQuery{
SqlQuery{history},
sequence,
}
err := Get(ctx, query, &record)
So(err, ShouldEqual, ErrNoResults)
})
})
}
开发者ID:jacksonh,项目名称:go-horizon,代码行数:28,代码来源:query_ledger_by_sequence_test.go
示例8: TestLedgerActions
func TestLedgerActions(t *testing.T) {
test.LoadScenario("base")
app := NewTestApp()
defer app.Close()
rh := NewRequestHelper(app)
Convey("Ledger Actions:", t, func() {
Convey("GET /ledgers/1", func() {
w := rh.Get("/ledgers/1", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
var result LedgerResource
err := json.Unmarshal(w.Body.Bytes(), &result)
So(err, ShouldBeNil)
So(result.Sequence, ShouldEqual, 1)
})
Convey("GET /ledgers/100", func() {
w := rh.Get("/ledgers/100", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 404)
})
Convey("GET /ledgers", func() {
Convey("With Default Params", func() {
w := rh.Get("/ledgers", test.RequestHelperNoop)
var result map[string]interface{}
err := json.Unmarshal(w.Body.Bytes(), &result)
So(err, ShouldBeNil)
So(w.Code, ShouldEqual, 200)
embedded := result["_embedded"].(map[string]interface{})
records := embedded["records"].([]interface{})
So(len(records), ShouldEqual, 4)
})
Convey("With A Limit", func() {
w := rh.Get("/ledgers?limit=1", test.RequestHelperNoop)
var result map[string]interface{}
err := json.Unmarshal(w.Body.Bytes(), &result)
So(err, ShouldBeNil)
So(w.Code, ShouldEqual, 200)
embedded := result["_embedded"].(map[string]interface{})
records := embedded["records"].([]interface{})
So(len(records), ShouldEqual, 1)
})
})
})
}
开发者ID:jacksonh,项目名称:go-horizon,代码行数:60,代码来源:actions_ledger_test.go
示例9: TestCoreAccountByAddressQuery
func TestCoreAccountByAddressQuery(t *testing.T) {
test.LoadScenario("base")
Convey("CoreAccountByAddress", t, func() {
var account CoreAccountRecord
Convey("Existing record behavior", func() {
address := "gspbxqXqEUZkiCCEFFCN9Vu4FLucdjLLdLcsV6E82Qc1T7ehsTC"
q := CoreAccountByAddressQuery{
SqlQuery{core},
address,
}
err := Get(ctx, q, &account)
So(err, ShouldBeNil)
So(account.Accountid, ShouldEqual, address)
So(account.Balance, ShouldEqual, 99999996999999970)
})
Convey("Missing record behavior", func() {
address := "not real"
q := CoreAccountByAddressQuery{
SqlQuery{core},
address,
}
err := Get(ctx, q, &account)
So(err, ShouldEqual, ErrNoResults)
})
})
}
开发者ID:jacksonh,项目名称:go-horizon,代码行数:32,代码来源:query_core_account_by_address_test.go
示例10: TestTransactionActions
func TestTransactionActions(t *testing.T) {
Convey("Transactions Actions:", t, func() {
test.LoadScenario("base")
app := NewTestApp()
defer app.Close()
rh := NewRequestHelper(app)
Convey("GET /transactions/99fd775e6eed3e331c7df84b540d955db4ece9f57d22980715918acb7ce5bbf4", func() {
w := rh.Get("/transactions/99fd775e6eed3e331c7df84b540d955db4ece9f57d22980715918acb7ce5bbf4", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
var result TransactionResource
err := json.Unmarshal(w.Body.Bytes(), &result)
So(err, ShouldBeNil)
So(result.Hash, ShouldEqual, "99fd775e6eed3e331c7df84b540d955db4ece9f57d22980715918acb7ce5bbf4")
})
Convey("GET /transactions/not_real", func() {
w := rh.Get("/transactions/not_real", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 404)
})
Convey("GET /transactions", func() {
w := rh.Get("/transactions", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 4)
})
Convey("GET /ledgers/:ledger_id/transactions", func() {
w := rh.Get("/ledgers/1/transactions", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 0)
w = rh.Get("/ledgers/2/transactions", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 3)
w = rh.Get("/ledgers/3/transactions", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 1)
})
Convey("GET /accounts/:account_od/transactions", func() {
w := rh.Get("/accounts/GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ/transactions", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 3)
w = rh.Get("/accounts/GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2/transactions", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 1)
w = rh.Get("/accounts/GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU/transactions", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 2)
})
})
}
开发者ID:FredericHeem,项目名称:go-horizon,代码行数:59,代码来源:actions_transaction_test.go
示例11: TestRootAction
func TestRootAction(t *testing.T) {
Convey("GET /", t, func() {
test.LoadScenario("base")
app := NewTestApp()
defer app.Close()
rh := NewRequestHelper(app)
w := rh.Get("/", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
})
}
开发者ID:jacksonh,项目名称:go-horizon,代码行数:13,代码来源:actions_root_test.go
示例12: TestLedgerState
func TestLedgerState(t *testing.T) {
test.LoadScenario("base")
horizon := OpenTestDatabase()
defer horizon.Close()
core := OpenStellarCoreTestDatabase()
defer core.Close()
Convey("db.UpdateLedgerState", t, func() {
So(horizonLedgerGauge.Value(), ShouldEqual, 0)
So(stellarCoreLedgerGauge.Value(), ShouldEqual, 0)
UpdateLedgerState(test.Context(), SqlQuery{horizon}, SqlQuery{core})
So(horizonLedgerGauge.Value(), ShouldEqual, 4)
So(stellarCoreLedgerGauge.Value(), ShouldEqual, 4)
})
}
开发者ID:jacksonh,项目名称:go-horizon,代码行数:17,代码来源:ledger_state_test.go
示例13: TestOfferActions
func TestOfferActions(t *testing.T) {
test.LoadScenario("trades")
app := NewTestApp()
defer app.Close()
rh := NewRequestHelper(app)
Convey("Offer Actions:", t, func() {
Convey("GET /accounts/GAJFK65MU3WQW4PZYJXBS7LXLXHHZB2RNVX7EC6DUZYU2NE4VMANPX2W/offers", func() {
w := rh.Get("/accounts/GAJFK65MU3WQW4PZYJXBS7LXLXHHZB2RNVX7EC6DUZYU2NE4VMANPX2W/offers", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.Body, ShouldBePageOf, 3)
})
})
}
开发者ID:FredericHeem,项目名称:go-horizon,代码行数:17,代码来源:actions_offer_test.go
示例14: TestLedgerStateQuery
func TestLedgerStateQuery(t *testing.T) {
test.LoadScenario("base")
Convey("LedgerStateQuery", t, func() {
var ls LedgerState
q := LedgerStateQuery{
SqlQuery{history},
SqlQuery{core},
}
err := Get(ctx, q, &ls)
So(err, ShouldBeNil)
So(ls.HorizonSequence, ShouldEqual, 4)
So(ls.StellarCoreSequence, ShouldEqual, 4)
})
}
开发者ID:jacksonh,项目名称:go-horizon,代码行数:17,代码来源:query_ledger_state_test.go
示例15: TestTransactionByHashQuery
func TestTransactionByHashQuery(t *testing.T) {
Convey("TransactionByHashQuery", t, func() {
test.LoadScenario("base")
var record TransactionRecord
Convey("Existing record behavior", func() {
hash := "99fd775e6eed3e331c7df84b540d955db4ece9f57d22980715918acb7ce5bbf4"
q := TransactionByHashQuery{SqlQuery{history}, hash}
err := Get(ctx, q, &record)
So(err, ShouldBeNil)
So(record.TransactionHash, ShouldEqual, hash)
})
Convey("Missing record behavior", func() {
hash := "not_real"
q := TransactionByHashQuery{SqlQuery{history}, hash}
err := Get(ctx, q, &record)
So(err, ShouldEqual, ErrNoResults)
})
})
}
开发者ID:FredericHeem,项目名称:go-horizon,代码行数:23,代码来源:query_transaction_by_hash_test.go
示例16: TestCoreTrustlinesByAddressQuery
func TestCoreTrustlinesByAddressQuery(t *testing.T) {
test.LoadScenario("non_native_payment")
Convey("CoreTrustlinesByAddress", t, func() {
var tls []CoreTrustlineRecord
withtl := "GBXGQJWVLWOYHFLVTKWV5FGHA3LNYY2JQKM7OAJAUEQFU6LPCSEFVXON"
notl := "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ"
q := CoreTrustlinesByAddressQuery{
SqlQuery{core},
withtl,
}
err := Select(ctx, q, &tls)
So(err, ShouldBeNil)
So(len(tls), ShouldEqual, 1)
tl := tls[0]
So(tl.Accountid, ShouldEqual, withtl)
So(tl.Issuer, ShouldEqual, "GC23QF2HUE52AMXUFUH3AYJAXXGXXV2VHXYYR6EYXETPKDXZSAW67XO4")
So(tl.Balance, ShouldEqual, 500000000)
So(tl.Tlimit, ShouldEqual, 9223372036854775807)
So(tl.Assetcode, ShouldEqual, "USD")
q = CoreTrustlinesByAddressQuery{
SqlQuery{core},
notl,
}
err = Select(ctx, q, &tls)
So(err, ShouldBeNil)
t.Log(tls)
So(len(tls), ShouldEqual, 0)
})
}
开发者ID:FredericHeem,项目名称:go-horizon,代码行数:37,代码来源:query_core_trustlines_by_address_test.go
示例17: TestCoreTrustlinesByAddressQuery
func TestCoreTrustlinesByAddressQuery(t *testing.T) {
test.LoadScenario("non_native_payment")
Convey("CoreTrustlinesByAddress", t, func() {
var tls []CoreTrustlineRecord
withtl := "gqdUHrgHUp8uMb74HiQvYztze2ffLhVXpPwj7gEZiJRa4jhCXQ"
notl := "gspbxqXqEUZkiCCEFFCN9Vu4FLucdjLLdLcsV6E82Qc1T7ehsTC"
q := CoreTrustlinesByAddressQuery{
SqlQuery{core},
withtl,
}
err := Select(ctx, q, &tls)
So(err, ShouldBeNil)
So(len(tls), ShouldEqual, 1)
tl := tls[0]
So(tl.Accountid, ShouldEqual, withtl)
So(tl.Issuer, ShouldEqual, "gsPsm67nNK8HtwMedJZFki3jAEKgg1s4nRKrHREFqTzT6ErzBiq")
So(tl.Balance, ShouldEqual, 500000000)
So(tl.Tlimit, ShouldEqual, 9223372036854775807)
So(tl.Alphanumcurrency, ShouldEqual, "USD")
q = CoreTrustlinesByAddressQuery{
SqlQuery{core},
notl,
}
err = Select(ctx, q, &tls)
So(err, ShouldBeNil)
t.Log(tls)
So(len(tls), ShouldEqual, 0)
})
}
开发者ID:jacksonh,项目名称:go-horizon,代码行数:37,代码来源:query_core_trustlines_by_address_test.go
示例18: TestApp
//.........这里部分代码省略.........
})
Convey("NewApp adds a sentry hook when the provided config's SentryDSN is valid", t, func() {
config := NewTestConfig()
config.SentryDSN = "https://3848836eb8b040c5b7cabb7b52a7108f:[email protected]/44303"
app, _ := NewApp(config)
defer app.Close()
// we have to use reflection to see if the hook is added :(
r := reflect.ValueOf(app.log.Logger.Hooks)
So(r.Kind(), ShouldEqual, reflect.Map)
expectations := []struct {
Level logrus.Level
Assertion func(actual interface{}, options ...interface{}) string
}{
{logrus.DebugLevel, shouldNotHaveASentryHook},
{logrus.InfoLevel, shouldNotHaveASentryHook},
{logrus.WarnLevel, shouldNotHaveASentryHook},
{logrus.ErrorLevel, shouldHaveASentryHook},
{logrus.PanicLevel, shouldHaveASentryHook},
{logrus.FatalLevel, shouldHaveASentryHook},
}
for _, expectation := range expectations {
hooks := r.MapIndex(reflect.ValueOf(expectation.Level)).Interface()
So(hooks, expectation.Assertion)
}
})
Convey("NewApp does not add a sentry hook if config's SentryDSN is empty", t, func() {
config := NewTestConfig()
config.SentryDSN = ""
app, _ := NewApp(config)
defer app.Close()
// we have to use reflection to see if the hook is added :(
r := reflect.ValueOf(app.log.Logger.Hooks)
So(r.Kind(), ShouldEqual, reflect.Map)
expectations := []struct {
Level logrus.Level
Assertion func(actual interface{}, options ...interface{}) string
}{
{logrus.DebugLevel, shouldNotHaveASentryHook},
{logrus.InfoLevel, shouldNotHaveASentryHook},
{logrus.WarnLevel, shouldNotHaveASentryHook},
{logrus.ErrorLevel, shouldNotHaveASentryHook},
{logrus.PanicLevel, shouldNotHaveASentryHook},
{logrus.FatalLevel, shouldNotHaveASentryHook},
}
for _, expectation := range expectations {
hooksv := r.MapIndex(reflect.ValueOf(expectation.Level))
var hooks []logrus.Hook
if hooksv.IsValid() {
hooks = hooksv.Interface().([]logrus.Hook)
} else {
hooks = nil
}
So(hooks, expectation.Assertion)
}
})
Convey("CORS support", t, func() {
app := NewTestApp()
defer app.Close()
rh := NewRequestHelper(app)
w := rh.Get("/", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
So(w.HeaderMap.Get("Access-Control-Allow-Origin"), ShouldEqual, "")
w = rh.Get("/", func(r *http.Request) {
r.Header.Set("Origin", "somewhere.com")
})
So(w.Code, ShouldEqual, 200)
So(w.HeaderMap.Get("Access-Control-Allow-Origin"), ShouldEqual, "somewhere.com")
})
Convey("Trailing slash causes redirect", t, func() {
test.LoadScenario("base")
app := NewTestApp()
defer app.Close()
rh := NewRequestHelper(app)
w := rh.Get("/accounts", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
w = rh.Get("/accounts/", test.RequestHelperNoop)
So(w.Code, ShouldEqual, 200)
})
}
开发者ID:FredericHeem,项目名称:go-horizon,代码行数:101,代码来源:app_test.go
示例19: TestTransactionPageQuery
func TestTransactionPageQuery(t *testing.T) {
test.LoadScenario("base")
Convey("TransactionPageQuery", t, func() {
var records []TransactionRecord
makeQuery := func(c string, o string, l int32) TransactionPageQuery {
pq, err := NewPageQuery(c, o, l)
So(err, ShouldBeNil)
return TransactionPageQuery{
SqlQuery: SqlQuery{history},
PageQuery: pq,
}
}
Convey("orders properly", func() {
// asc orders ascending by id
MustSelect(ctx, makeQuery("", "asc", 0), &records)
So(records, ShouldBeOrderedAscending, func(r interface{}) int64 {
So(r, ShouldHaveSameTypeAs, TransactionRecord{})
return r.(TransactionRecord).Id
})
// desc orders descending by id
MustSelect(ctx, makeQuery("", "desc", 0), &records)
So(records, ShouldBeOrderedDescending, func(r interface{}) int64 {
So(r, ShouldHaveSameTypeAs, TransactionRecord{})
return r.(TransactionRecord).Id
})
})
Convey("limits properly", func() {
// returns number specified
MustSelect(ctx, makeQuery("", "asc", 3), &records)
So(len(records), ShouldEqual, 3)
// returns all rows if limit is higher
MustSelect(ctx, makeQuery("", "asc", 10), &records)
So(len(records), ShouldEqual, 4)
})
Convey("cursor works properly", func() {
var record TransactionRecord
// lowest id if ordered ascending and no cursor
MustGet(ctx, makeQuery("", "asc", 0), &record)
So(record.Id, ShouldEqual, 8589938688)
// highest id if ordered descending and no cursor
MustGet(ctx, makeQuery("", "desc", 0), &record)
So(record.Id, ShouldEqual, 12884905984)
// starts after the cursor if ordered ascending
MustGet(ctx, makeQuery("8589938688", "asc", 0), &record)
So(record.Id, ShouldEqual, 8589942784)
// starts before the cursor if ordered descending
MustGet(ctx, makeQuery("12884905984", "desc", 0), &record)
So(record.Id, ShouldEqual, 8589946880)
})
Convey("restricts to address properly", func() {
address := "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ"
q := makeQuery("", "asc", 0)
q.AccountAddress = address
MustSelect(ctx, q, &records)
So(len(records), ShouldEqual, 3)
for _, r := range records {
So(r.Account, ShouldEqual, address)
}
})
Convey("restricts to ledger properly", func() {
q := makeQuery("", "asc", 0)
q.LedgerSequence = 3
MustSelect(ctx, q, &records)
So(len(records), ShouldEqual, 1)
for _, r := range records {
So(r.LedgerSequence, ShouldEqual, q.LedgerSequence)
}
})
})
}
开发者ID:FredericHeem,项目名称:go-horizon,代码行数:91,代码来源:query_transaction_page_test.go
示例20: TestTransactionPageQuery
func TestTransactionPageQuery(t *testing.T) {
test.LoadScenario("base")
Convey("TransactionPageQuery", t, func() {
var records []TransactionRecord
makeQuery := func(c string, o string, l int32) TransactionPageQuery {
pq, err := NewPageQuery(c, o, l)
So(err, ShouldBeNil)
return TransactionPageQuery{
SqlQuery: SqlQuery{history},
PageQuery: pq,
}
}
Convey("orders properly", func() {
// asc orders ascending by id
MustSelect(ctx, makeQuery("", "asc", 0), &records)
So(records, ShouldBeOrderedAscending, func(r interface{}) int64 {
So(r, ShouldHaveSameTypeAs, TransactionRecord{})
return r.(TransactionRecord).Id
})
// desc orders descending by id
MustSelect(ctx, makeQuery("", "desc", 0), &records)
So(records, ShouldBeOrderedDescending, func(r interface{}) int64 {
So(r, ShouldHaveSameTypeAs, TransactionRecord{})
return r.(TransactionRecord).Id
})
})
Convey("limits properly", func() {
// returns number specified
MustSelect(ctx, makeQuery("", "asc", 3), &records)
So(len(records), ShouldEqual, 3)
// returns all rows if limit is higher
MustSelect(ctx, makeQuery("", "asc", 10), &records)
So(len(records), ShouldEqual, 4)
})
Convey("cursor works properly", func() {
var record TransactionRecord
// lowest id if ordered ascending and no cursor
MustGet(ctx, makeQuery("", "asc", 0), &record)
So(record.Id, ShouldEqual, 12884905984)
// highest id if ordered descending and no cursor
MustGet(ctx, makeQuery("", "desc", 0), &record)
So(record.Id, ShouldEqual, 17179873280)
// starts after the cursor if ordered ascending
MustGet(ctx, makeQuery("12884905984", "asc", 0), &record)
So(record.Id, ShouldEqual, 12884910080)
// starts before the cursor if ordered descending
MustGet(ctx, makeQuery("17179873280", "desc", 0), &record)
So(record.Id, ShouldEqual, 12884914176)
})
Convey("restricts to address properly", func() {
address := "gspbxqXqEUZkiCCEFFCN9Vu4FLucdjLLdLcsV6E82Qc1T7ehsTC"
q := makeQuery("", "asc", 0)
q.AccountAddress = address
MustSelect(ctx, q, &records)
So(len(records), ShouldEqual, 3)
for _, r := range records {
So(r.Account, ShouldEqual, address)
}
})
Convey("restricts to ledger properly", func() {
q := makeQuery("", "asc", 0)
q.LedgerSequence = 4
MustSelect(ctx, q, &records)
So(len(records), ShouldEqual, 1)
for _, r := range records {
So(r.LedgerSequence, ShouldEqual, q.LedgerSequence)
}
})
})
}
开发者ID:jacksonh,项目名称:go-horizon,代码行数:91,代码来源:query_transaction_page_test.go
注:本文中的github.com/stellar/go-horizon/test.LoadScenario函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论