當前位置: 首頁>>代碼示例>>Golang>>正文


Golang dynago.Document類代碼示例

本文整理匯總了Golang中github.com/underarmour/dynago.Document的典型用法代碼示例。如果您正苦於以下問題:Golang Document類的具體用法?Golang Document怎麽用?Golang Document使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Document類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestDocumentMarshalJSONDoesNotIncludeEmptyValues

func TestDocumentMarshalJSONDoesNotIncludeEmptyValues(t *testing.T) {
	doc := dynago.Document{"key1": "shows up", "key2": 9, "fields": dynago.StringSet([]string{"is", "present"}), "id": "", "name": nil, "tags": []string{}}
	jsonDoc, _ := doc.MarshalJSON()

	assert.Contains(t, string(jsonDoc), `"fields":{"SS":["is","present"]}`)
	assert.Contains(t, string(jsonDoc), `"key1":{"S":"shows up"}`)
	assert.Contains(t, string(jsonDoc), `"key2":{"N":"9"}`)
}
開發者ID:natebrennand,項目名稱:dynago,代碼行數:8,代碼來源:types_test.go

示例2: TestDocumentGetNumberPanicsIfTheUnderlyingTypeIsNotANumber

func TestDocumentGetNumberPanicsIfTheUnderlyingTypeIsNotANumber(t *testing.T) {
	doc := dynago.Document{"id": "not-a-dynago-number"}
	assert.Panics(t, func() {
		doc.GetNumber("id")
	})
}
開發者ID:natebrennand,項目名稱:dynago,代碼行數:6,代碼來源:types_test.go

示例3: TestDocumentGetNumberReturnsAnEmptyNumberWhenTheKeyIsNotPresent

func TestDocumentGetNumberReturnsAnEmptyNumberWhenTheKeyIsNotPresent(t *testing.T) {
	doc := dynago.Document{}
	assert.Equal(t, dynago.Number(""), doc.GetNumber("id"))
}
開發者ID:natebrennand,項目名稱:dynago,代碼行數:4,代碼來源:types_test.go

示例4: TestDocumentGetNumberReturnsTheDynagoNumberWrappingTheValue

func TestDocumentGetNumberReturnsTheDynagoNumberWrappingTheValue(t *testing.T) {
	doc := dynago.Document{"id": dynago.Number("12")}
	assert.Equal(t, dynago.Number("12"), doc.GetNumber("id"))
}
開發者ID:natebrennand,項目名稱:dynago,代碼行數:4,代碼來源:types_test.go

示例5: TestDocumentGetStringReturnsAnEmptyStringWhenTheKeyIsNotPresent

func TestDocumentGetStringReturnsAnEmptyStringWhenTheKeyIsNotPresent(t *testing.T) {
	doc := dynago.Document{}
	assert.Equal(t, "", doc.GetString("name"))
}
開發者ID:natebrennand,項目名稱:dynago,代碼行數:4,代碼來源:types_test.go

示例6: TestDocumentGetStringReturnsTheUnderlyingValueAsAString

func TestDocumentGetStringReturnsTheUnderlyingValueAsAString(t *testing.T) {
	doc := dynago.Document{"name": "Timmy Testerson"}
	assert.Equal(t, "Timmy Testerson", doc.GetString("name"))
}
開發者ID:natebrennand,項目名稱:dynago,代碼行數:4,代碼來源:types_test.go

示例7: TestDocumentGetList

func TestDocumentGetList(t *testing.T) {
	doc := dynago.Document{"vals": dynago.List{"val1", "val2"}, "wrongtype": 4}
	assert.Equal(t, dynago.List{"val1", "val2"}, doc.GetList("vals"))
	assert.Equal(t, dynago.List(nil), doc.GetList("notarealkey"))
	assert.Panics(t, func() { doc.GetList("wrongtype") })
}
開發者ID:natebrennand,項目名稱:dynago,代碼行數:6,代碼來源:types_test.go

示例8: TestDocumentGetBool

func TestDocumentGetBool(t *testing.T) {
	doc := dynago.Document{"val": dynago.Number("1")}
	assert.Equal(t, true, doc.GetBool("val"))

	doc = dynago.Document{}
	assert.Equal(t, false, doc.GetBool("val"))

	doc = dynago.Document{"val": nil}
	assert.Equal(t, false, doc.GetBool("val"))

	doc = dynago.Document{"val": dynago.Number("b")}
	assert.Panics(t, func() {
		doc.GetBool("val")
	})

	doc = dynago.Document{"val": "hello"}
	assert.Panics(t, func() {
		doc.GetBool("val")
	})
}
開發者ID:natebrennand,項目名稱:dynago,代碼行數:20,代碼來源:types_test.go

示例9: TestDocumentGetTimePanicsWhenFormatIsNotIso8601

func TestDocumentGetTimePanicsWhenFormatIsNotIso8601(t *testing.T) {
	doc := dynago.Document{"time": "Foo"}
	assert.Panics(t, func() { doc.GetTime("time") })
}
開發者ID:natebrennand,項目名稱:dynago,代碼行數:4,代碼來源:types_test.go

示例10: TestDocumentGetTimeReturnsNilWhenTheKeyDoesNotExist

func TestDocumentGetTimeReturnsNilWhenTheKeyDoesNotExist(t *testing.T) {
	doc := dynago.Document{}
	assert.Nil(t, doc.GetTime("time"))
}
開發者ID:natebrennand,項目名稱:dynago,代碼行數:4,代碼來源:types_test.go

示例11: TestDocumentGetTimeReturnsTheTimeValueFromISO8601

func TestDocumentGetTimeReturnsTheTimeValueFromISO8601(t *testing.T) {
	doc := dynago.Document{"time": "1990-04-16T00:00:00Z"}
	val, _ := time.Parse("2006-01-02T15:04:05Z", "1990-04-16T00:00:00Z")
	assert.Equal(t, &val, doc.GetTime("time"))
}
開發者ID:natebrennand,項目名稱:dynago,代碼行數:5,代碼來源:types_test.go

示例12: TestDocumentGetStringSetPanic

func TestDocumentGetStringSetPanic(t *testing.T) {
	doc := dynago.Document{"vals": "not-a-string-slice"}
	assert.Panics(t, func() {
		doc.GetStringSet("vals")
	})
}
開發者ID:natebrennand,項目名稱:dynago,代碼行數:6,代碼來源:types_test.go

示例13: TestDocumentGetStringSetReturnsAnEmptyStringSetWhenTheKeyDoesNotExist

func TestDocumentGetStringSetReturnsAnEmptyStringSetWhenTheKeyDoesNotExist(t *testing.T) {
	doc := dynago.Document{}
	assert.Equal(t, dynago.StringSet{}, doc.GetStringSet("vals"))
}
開發者ID:natebrennand,項目名稱:dynago,代碼行數:4,代碼來源:types_test.go

示例14: TestDocumentGetStringSetReturnsTheStringSetValue

func TestDocumentGetStringSetReturnsTheStringSetValue(t *testing.T) {
	doc := dynago.Document{"vals": dynago.StringSet{"val1", "val2"}}
	assert.Equal(t, dynago.StringSet{"val1", "val2"}, doc.GetStringSet("vals"))
}
開發者ID:natebrennand,項目名稱:dynago,代碼行數:4,代碼來源:types_test.go


注:本文中的github.com/underarmour/dynago.Document類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。