本文整理汇总了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"}`)
}
示例2: TestDocumentGetNumberPanicsIfTheUnderlyingTypeIsNotANumber
func TestDocumentGetNumberPanicsIfTheUnderlyingTypeIsNotANumber(t *testing.T) {
doc := dynago.Document{"id": "not-a-dynago-number"}
assert.Panics(t, func() {
doc.GetNumber("id")
})
}
示例3: TestDocumentGetNumberReturnsAnEmptyNumberWhenTheKeyIsNotPresent
func TestDocumentGetNumberReturnsAnEmptyNumberWhenTheKeyIsNotPresent(t *testing.T) {
doc := dynago.Document{}
assert.Equal(t, dynago.Number(""), doc.GetNumber("id"))
}
示例4: TestDocumentGetNumberReturnsTheDynagoNumberWrappingTheValue
func TestDocumentGetNumberReturnsTheDynagoNumberWrappingTheValue(t *testing.T) {
doc := dynago.Document{"id": dynago.Number("12")}
assert.Equal(t, dynago.Number("12"), doc.GetNumber("id"))
}
示例5: TestDocumentGetStringReturnsAnEmptyStringWhenTheKeyIsNotPresent
func TestDocumentGetStringReturnsAnEmptyStringWhenTheKeyIsNotPresent(t *testing.T) {
doc := dynago.Document{}
assert.Equal(t, "", doc.GetString("name"))
}
示例6: TestDocumentGetStringReturnsTheUnderlyingValueAsAString
func TestDocumentGetStringReturnsTheUnderlyingValueAsAString(t *testing.T) {
doc := dynago.Document{"name": "Timmy Testerson"}
assert.Equal(t, "Timmy Testerson", doc.GetString("name"))
}
示例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") })
}
示例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")
})
}
示例9: TestDocumentGetTimePanicsWhenFormatIsNotIso8601
func TestDocumentGetTimePanicsWhenFormatIsNotIso8601(t *testing.T) {
doc := dynago.Document{"time": "Foo"}
assert.Panics(t, func() { doc.GetTime("time") })
}
示例10: TestDocumentGetTimeReturnsNilWhenTheKeyDoesNotExist
func TestDocumentGetTimeReturnsNilWhenTheKeyDoesNotExist(t *testing.T) {
doc := dynago.Document{}
assert.Nil(t, doc.GetTime("time"))
}
示例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"))
}
示例12: TestDocumentGetStringSetPanic
func TestDocumentGetStringSetPanic(t *testing.T) {
doc := dynago.Document{"vals": "not-a-string-slice"}
assert.Panics(t, func() {
doc.GetStringSet("vals")
})
}
示例13: TestDocumentGetStringSetReturnsAnEmptyStringSetWhenTheKeyDoesNotExist
func TestDocumentGetStringSetReturnsAnEmptyStringSetWhenTheKeyDoesNotExist(t *testing.T) {
doc := dynago.Document{}
assert.Equal(t, dynago.StringSet{}, doc.GetStringSet("vals"))
}
示例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"))
}