• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang test.LoadScenario函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/jojopoper/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/1/payments", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 0)

			w = rh.Get("/ledgers/3/payments", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 1)
		})

		Convey("GET /accounts/:account_id/payments", func() {
			w := rh.Get("/accounts/GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2/payments", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 1)

			test.LoadScenario("pathed_payment")
			w = rh.Get("/accounts/GCQPYGH4K57XBDENKKX55KDTWOTK5WDWRQOH2LHEDX3EKVIQRLMESGBG/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/42450ffe3956b8618cffaae48665c252869440aeb41fd8bf4921929a61982630/payments", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 0)

			w = rh.Get("/transactions/95324dec7c94f8cc992522794b2a84a732cddcb5641992589cfe328884a4c132/payments", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 1)
		})

	})
}
开发者ID:jojopoper,项目名称:horizon,代码行数:49,代码来源:actions_payment_test.go


示例2: TestOperationByIdQuery

func TestOperationByIdQuery(t *testing.T) {
	test.LoadScenario("base")

	Convey("OperationByIdQuery", t, func() {
		var op OperationRecord

		Convey("Existing record behavior", func() {
			id := int64(8589938689)
			q := OperationByIdQuery{
				SqlQuery{history},
				id,
			}
			err := Get(ctx, q, &op)
			So(err, ShouldBeNil)
			So(op.Id, ShouldEqual, id)
			So(op.TransactionId, ShouldEqual, id-1)
		})

		Convey("Missing record behavior", func() {
			id := int64(0)
			q := OperationByIdQuery{
				SqlQuery{history},
				id,
			}
			err := Get(ctx, q, &op)
			So(err, ShouldEqual, ErrNoResults)
		})

	})
}
开发者ID:jojopoper,项目名称:horizon,代码行数:30,代码来源:query_operation_by_id_test.go


示例3: 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/GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H", func() {
			w := rh.Get("/accounts/GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H", 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:jojopoper,项目名称:horizon,代码行数:35,代码来源:actions_account_test.go


示例4: 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:jojopoper,项目名称:horizon,代码行数:28,代码来源:query_ledger_by_sequence_test.go


示例5: TestTradeActions

func TestTradeActions(t *testing.T) {

	Convey("Trade Actions:", t, func() {
		test.LoadScenario("trades")
		app := NewTestApp()
		defer app.Close()
		rh := NewRequestHelper(app)

		Convey("GET /accounts/:account_id/trades", func() {
			w := rh.Get("/accounts/GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2/trades", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 1)
		})

		Convey("GET /order_book/trades", func() {
			url := "/order_book/trades?" +
				"selling_asset_type=credit_alphanum4&" +
				"selling_asset_code=EUR&" +
				"selling_asset_issuer=GCQPYGH4K57XBDENKKX55KDTWOTK5WDWRQOH2LHEDX3EKVIQRLMESGBG&" +
				"buying_asset_type=credit_alphanum4&" +
				"buying_asset_code=USD&" +
				"buying_asset_issuer=GC23QF2HUE52AMXUFUH3AYJAXXGXXV2VHXYYR6EYXETPKDXZSAW67XO4"

			w := rh.Get(url, test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 1)
		})
	})
}
开发者ID:jojopoper,项目名称:horizon,代码行数:29,代码来源:actions_trade_test.go


示例6: 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:jojopoper,项目名称:horizon,代码行数:28,代码来源:query_ledger_page_test.go


示例7: TestHistoryAccountByAddressQuery

func TestHistoryAccountByAddressQuery(t *testing.T) {
	test.LoadScenario("base")

	Convey("AccountByAddress", t, func() {
		var account HistoryAccountRecord

		Convey("Existing record behavior", func() {
			address := "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H"
			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:jojopoper,项目名称:horizon,代码行数:30,代码来源:query_history_account_by_address_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, 3)

			})

			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:jojopoper,项目名称:horizon,代码行数:60,代码来源:actions_ledger_test.go


示例9: TestAccountByAddressQuery

func TestAccountByAddressQuery(t *testing.T) {
	test.LoadScenario("non_native_payment")

	Convey("AccountByAddress", t, func() {
		var account AccountRecord

		notreal := "not_real"
		withtl := "GBXGQJWVLWOYHFLVTKWV5FGHA3LNYY2JQKM7OAJAUEQFU6LPCSEFVXON"
		notl := "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H"

		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:jojopoper,项目名称:horizon,代码行数:33,代码来源:query_account_by_address_test.go


示例10: TestEffectActions

func TestEffectActions(t *testing.T) {
	test.LoadScenario("base")

	Convey("Effect Actions:", t, func() {
		app := NewTestApp()
		defer app.Close()
		rh := NewRequestHelper(app)

		Convey("GET /effects", func() {
			w := rh.Get("/effects?limit=20", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 11)
		})

		Convey("GET /ledgers/:ledger_id/effects", func() {
			w := rh.Get("/ledgers/1/effects", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 0)

			w = rh.Get("/ledgers/2/effects", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 9)

			w = rh.Get("/ledgers/3/effects", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 2)
		})

		Convey("GET /accounts/:account_id/effects", func() {
			w := rh.Get("/accounts/GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H/effects", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 3)

			w = rh.Get("/accounts/GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2/effects", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 2)

			w = rh.Get("/accounts/GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU/effects", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 3)
		})

		Convey("GET /transactions/:tx_id/effects", func() {
			w := rh.Get("/transactions/c492d87c4642815dfb3c7dcce01af4effd162b031064098a0d786b6e0a00fd74/effects", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 3)
		})

		Convey("GET /operations/:op_id/effects", func() {
			w := rh.Get("/operations/8589938689/effects", test.RequestHelperNoop)
			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 3)
		})
	})
}
开发者ID:jojopoper,项目名称:horizon,代码行数:55,代码来源:actions_effects_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:jojopoper,项目名称:horizon,代码行数:13,代码来源:actions_root_test.go


示例12: 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, 3)
		So(ls.StellarCoreSequence, ShouldEqual, 3)
	})
}
开发者ID:jojopoper,项目名称:horizon,代码行数:17,代码来源:query_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/GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2/offers", func() {
			w := rh.Get("/accounts/GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2/offers", test.RequestHelperNoop)

			So(w.Code, ShouldEqual, 200)
			So(w.Body, ShouldBePageOf, 3)
		})

	})
}
开发者ID:jojopoper,项目名称:horizon,代码行数:17,代码来源:actions_offer_test.go


示例14: 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, 3)
		So(stellarCoreLedgerGauge.Value(), ShouldEqual, 3)
	})
}
开发者ID:jojopoper,项目名称:horizon,代码行数:17,代码来源:ledger_state_test.go


示例15: TestCoreTrustlinesByAddressQuery

func TestCoreTrustlinesByAddressQuery(t *testing.T) {
	test.LoadScenario("non_native_payment")

	Convey("CoreTrustlinesByAddress", t, func() {
		var tls []CoreTrustlineRecord

		withtl := "GBXGQJWVLWOYHFLVTKWV5FGHA3LNYY2JQKM7OAJAUEQFU6LPCSEFVXON"
		notl := "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H"

		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:jojopoper,项目名称:horizon,代码行数:37,代码来源:query_core_trustlines_by_address_test.go


示例16: TestEffectPageQueryByOrderBook

func TestEffectPageQueryByOrderBook(t *testing.T) {
	test.LoadScenario("trades")

	Convey("EffectOrderBookFilter", t, func() {
		var records []EffectRecord

		Convey("restricts to order book properly", func() {
			q := EffectPageQuery{
				SqlQuery:  SqlQuery{history},
				PageQuery: MustPageQuery("", "asc", 0),
				Filter: &EffectOrderBookFilter{
					SellingType:   xdr.AssetTypeAssetTypeCreditAlphanum4,
					SellingCode:   "EUR",
					SellingIssuer: "GCQPYGH4K57XBDENKKX55KDTWOTK5WDWRQOH2LHEDX3EKVIQRLMESGBG",
					BuyingType:    xdr.AssetTypeAssetTypeCreditAlphanum4,
					BuyingCode:    "USD",
					BuyingIssuer:  "GC23QF2HUE52AMXUFUH3AYJAXXGXXV2VHXYYR6EYXETPKDXZSAW67XO4",
				},
			}

			MustSelect(ctx, q, &records)

			So(len(records), ShouldEqual, 1)
			r := records[0]
			dets, _ := r.Details()

			So(dets["sold_asset_type"].(string), ShouldEqual, "credit_alphanum4")
			So(dets["sold_asset_code"], ShouldEqual, "EUR")
			So(dets["sold_asset_issuer"], ShouldEqual, "GCQPYGH4K57XBDENKKX55KDTWOTK5WDWRQOH2LHEDX3EKVIQRLMESGBG")

			So(dets["bought_asset_type"].(string), ShouldEqual, "credit_alphanum4")
			So(dets["bought_asset_code"], ShouldEqual, "USD")
			So(dets["bought_asset_issuer"], ShouldEqual, "GC23QF2HUE52AMXUFUH3AYJAXXGXXV2VHXYYR6EYXETPKDXZSAW67XO4")
		})
	})
}
开发者ID:jojopoper,项目名称:horizon,代码行数:36,代码来源:query_effect_page_test.go


示例17: TestCoreOfferPageByAddressQuery

func TestCoreOfferPageByAddressQuery(t *testing.T) {
	test.LoadScenario("trades")

	Convey("CoreOfferPageByAddressQuery", t, func() {

		makeQuery := func(c string, o string, l int32, a string) CoreOfferPageByAddressQuery {
			pq, err := NewPageQuery(c, o, l)

			So(err, ShouldBeNil)

			return CoreOfferPageByAddressQuery{
				SqlQuery:  SqlQuery{core},
				PageQuery: pq,
				Address:   a,
			}
		}

		var records []CoreOfferRecord

		Convey("works with native offers", func() {
			MustSelect(ctx, makeQuery("", "asc", 0, "GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU"), &records)
			So(len(records), ShouldEqual, 1)
		})

		Convey("filters properly", func() {
			MustSelect(ctx, makeQuery("", "desc", 0, "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H"), &records)
			So(len(records), ShouldEqual, 0)

			MustSelect(ctx, makeQuery("", "asc", 0, "GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2"), &records)
			So(len(records), ShouldEqual, 3)

		})

		Convey("orders properly", func() {
			// asc orders ascending by id
			MustSelect(ctx, makeQuery("", "asc", 0, "GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2"), &records)

			So(records, ShouldBeOrderedAscending, func(r interface{}) int64 {
				So(r, ShouldHaveSameTypeAs, CoreOfferRecord{})
				return r.(CoreOfferRecord).OfferID
			})

			// desc orders descending by id
			MustSelect(ctx, makeQuery("", "desc", 0, "GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2"), &records)

			So(records, ShouldBeOrderedDescending, func(r interface{}) int64 {
				So(r, ShouldHaveSameTypeAs, CoreOfferRecord{})
				return r.(CoreOfferRecord).OfferID
			})
		})

		Convey("limits properly", func() {
			// returns number specified
			MustSelect(ctx, makeQuery("", "asc", 2, "GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2"), &records)
			So(len(records), ShouldEqual, 2)

			// returns all rows if limit is higher
			MustSelect(ctx, makeQuery("", "asc", 10, "GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2"), &records)
			So(len(records), ShouldEqual, 3)
		})

		Convey("cursor works properly", func() {
			var record CoreOfferRecord
			// lowest id if ordered ascending and no cursor
			MustGet(ctx, makeQuery("", "asc", 0, "GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2"), &record)
			So(record.OfferID, ShouldEqual, 1)

			// highest id if ordered descending and no cursor
			MustGet(ctx, makeQuery("", "desc", 0, "GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2"), &record)
			So(record.OfferID, ShouldEqual, 3)

			// starts after the cursor if ordered ascending
			MustGet(ctx, makeQuery("1", "asc", 0, "GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2"), &record)
			So(record.OfferID, ShouldEqual, 2)

			// starts before the cursor if ordered descending
			MustGet(ctx, makeQuery("3", "desc", 0, "GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2"), &record)
			So(record.OfferID, ShouldEqual, 2)
		})

	})
}
开发者ID:jojopoper,项目名称:horizon,代码行数:82,代码来源:query_core_offer_page_by_address_test.go


示例18: TestOperationPageQuery

func TestOperationPageQuery(t *testing.T) {
	test.LoadScenario("base")

	Convey("OperationPageQuery", t, func() {
		var records []OperationRecord

		makeQuery := func(c string, o string, l int32) OperationPageQuery {
			pq, err := NewPageQuery(c, o, l)

			So(err, ShouldBeNil)

			return OperationPageQuery{
				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, OperationRecord{})
				return r.(OperationRecord).Id
			})

			// desc orders descending by id
			MustSelect(ctx, makeQuery("", "desc", 0), &records)
			So(records, ShouldBeOrderedDescending, func(r interface{}) int64 {
				So(r, ShouldHaveSameTypeAs, OperationRecord{})
				return r.(OperationRecord).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 OperationRecord

			// lowest id if ordered ascending and no cursor
			MustGet(ctx, makeQuery("", "asc", 0), &record)
			So(record.Id, ShouldEqual, 8589938689)

			// highest id if ordered descending and no cursor
			MustGet(ctx, makeQuery("", "desc", 0), &record)
			So(record.Id, ShouldEqual, 12884905985)

			// starts after the cursor if ordered ascending
			MustGet(ctx, makeQuery("8589938689", "asc", 0), &record)
			So(record.Id, ShouldEqual, 8589942785)

			// starts before the cursor if ordered descending
			MustGet(ctx, makeQuery("12884905985", "desc", 0), &record)
			So(record.Id, ShouldEqual, 8589946881)
		})

		Convey("restricts to address properly", func() {
			address := "GBXGQJWVLWOYHFLVTKWV5FGHA3LNYY2JQKM7OAJAUEQFU6LPCSEFVXON"
			q := makeQuery("", "asc", 0)
			q.AccountAddress = address
			MustSelect(ctx, q, &records)

			So(len(records), ShouldEqual, 2)
			So(records[0].Id, ShouldEqual, 8589946881)
			So(records[1].Id, ShouldEqual, 12884905985)
		})

		Convey("restricts to ledger properly", func() {
			q := makeQuery("", "asc", 0)
			q.LedgerSequence = 2
			MustSelect(ctx, q, &records)

			So(len(records), ShouldEqual, 3)

			for _, r := range records {
				toid := ParseTotalOrderId(r.TransactionId)
				So(toid.LedgerSequence, ShouldEqual, 2)
			}
		})

		Convey("restricts to transaction properly", func() {
			q := makeQuery("", "asc", 0)
			q.TransactionHash = "c492d87c4642815dfb3c7dcce01af4effd162b031064098a0d786b6e0a00fd74"
			MustSelect(ctx, q, &records)

			So(len(records), ShouldEqual, 1)

			for _, r := range records {
				So(r.TransactionId, ShouldEqual, 8589938688)
			}
		})

		Convey("errors if more than one filter is supplied", func() {
//.........这里部分代码省略.........
开发者ID:jojopoper,项目名称:horizon,代码行数:101,代码来源:query_operation_page_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 := "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H"
			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:jojopoper,项目名称:horizon,代码行数:91,代码来源:query_transaction_page_test.go


示例20: TestDBPackage

func TestDBPackage(t *testing.T) {
	test.LoadScenario("non_native_payment")

	Convey("db.Select", t, func() {
		Convey("overwrites the destination", func() {
			records := []mockResult{{1}, {2}}
			query := &mockQuery{5}
			err := Select(ctx, query, &records)
			So(err, ShouldBeNil)
			So(len(records), ShouldEqual, 5)
		})

		Convey("works on []interface{} destinations", func() {
			var records []mockResult
			query := &mockQuery{5}
			err := Select(ctx, query, &records)
			So(err, ShouldBeNil)
			So(len(records), ShouldEqual, 5)
		})

		Convey("returns an error when the provided destination is nil", func() {
			query := &mockQuery{5}
			err := Select(ctx, query, nil)
			So(err, ShouldEqual, ErrDestinationNil)
		})

		Convey("returns an error when the provided destination is not a pointer", func() {
			var records []mockResult
			query := &mockQuery{5}
			err := Select(ctx, query, records)
			So(err, ShouldEqual, ErrDestinationNotPointer)
		})

		Convey("returns an error when the provided destination is not a slice", func() {
			var records string
			query := &mockQuery{5}
			err := Select(ctx, query, &records)
			So(err, ShouldEqual, ErrDestinationNotSlice)
		})

		Convey("returns an error when the provided destination is a slice of an invalid type", func() {
			var records []string
			query := &mockQuery{5}
			err := Select(ctx, query, &records)
			So(err, ShouldEqual, ErrDestinationIncompatible)
		})
	})

	Convey("db.Get", t, func() {
		var result mockResult

		Convey("returns the first record", func() {
			So(Get(ctx, &mockQuery{2}, &result), ShouldBeNil)
			So(result, ShouldResemble, mockResult{0})
		})

		Convey("Missing records returns nil", func() {
			So(Get(ctx, &mockQuery{0}, &result), ShouldEqual, ErrNoResults)
		})

		Convey("Properly forwards non-RecordNotFound errors", func() {
			query := &BrokenQuery{errors.New("Some error")}
			So(Get(ctx, query, &result).Error(), ShouldEqual, "Some error")
		})
	})
}
开发者ID:jojopoper,项目名称:horizon,代码行数:66,代码来源:main_test.go



注:本文中的github.com/jojopoper/horizon/test.LoadScenario函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang baller.Client类代码示例发布时间:2022-05-23
下一篇:
Golang sse.Stream类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap