本文整理汇总了Golang中github.com/attic-labs/testify/assert.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSetHas2
func TestSetHas2(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
smallTestChunks()
defer normalProductionChunks()
assert := assert.New(t)
vs := NewTestValueStore()
doTest := func(ts testSet) {
set := ts.toSet()
set2 := vs.ReadValue(vs.WriteValue(set).TargetHash()).(Set)
for _, v := range ts {
assert.True(set.Has(v))
assert.True(set2.Has(v))
}
diffSetTest(assert, set, set2, 0, 0)
}
doTest(getTestNativeOrderSet(16))
doTest(getTestRefValueOrderSet(2))
doTest(getTestRefToNativeOrderSet(2, vs))
doTest(getTestRefToValueOrderSet(2, vs))
}
开发者ID:Richardphp,项目名称:noms,代码行数:26,代码来源:set_test.go
示例2: TestHandleWriteValueBackpressure
func TestHandleWriteValueBackpressure(t *testing.T) {
assert := assert.New(t)
cs := &backpressureCS{ChunkStore: chunks.NewMemoryStore()}
ds := NewDatabase(cs)
l := types.NewList(
ds.WriteValue(types.Bool(true)),
ds.WriteValue(types.Bool(false)),
)
ds.WriteValue(l)
hint := l.Hash()
newItem := types.NewEmptyBlob()
itemChunk := types.EncodeValue(newItem, nil)
l2 := l.Insert(1, types.NewRef(newItem))
listChunk := types.EncodeValue(l2, nil)
body := &bytes.Buffer{}
serializeHints(body, map[hash.Hash]struct{}{hint: struct{}{}})
sz := chunks.NewSerializer(body)
sz.Put(itemChunk)
sz.Put(listChunk)
sz.Close()
w := httptest.NewRecorder()
HandleWriteValue(w, &http.Request{Body: ioutil.NopCloser(body), Method: "POST"}, params{}, cs)
if assert.Equal(httpStatusTooManyRequests, w.Code, "Handler error:\n%s", string(w.Body.Bytes())) {
hashes := deserializeHashes(w.Body)
assert.Len(hashes, 1)
assert.Equal(l2.Hash(), hashes[0])
}
}
开发者ID:willhite,项目名称:noms-old,代码行数:33,代码来源:remote_database_handlers_test.go
示例3: assertWriteTaggedHRSEqual
func assertWriteTaggedHRSEqual(t *testing.T, expected string, v Value) {
assert := assert.New(t)
var buf bytes.Buffer
w := &hrsWriter{w: &buf, floatFormat: 'g'}
w.WriteTagged(v)
assert.Equal(expected, buf.String())
}
开发者ID:kalman,项目名称:noms-pre-release,代码行数:7,代码来源:encode_human_readable_test.go
示例4: TestCursorGetMaxNPrevItemsWithSingleItemSequence
func TestCursorGetMaxNPrevItemsWithSingleItemSequence(t *testing.T) {
assert := assert.New(t)
cur := newTestSequenceCursor([]interface{}{[]interface{}{100}, []interface{}{101}, []interface{}{102}})
assert.Equal([]sequenceItem{}, cur.maxNPrevItems(0))
assert.Equal([]sequenceItem{}, cur.maxNPrevItems(1))
assert.Equal([]sequenceItem{}, cur.maxNPrevItems(2))
assert.Equal([]sequenceItem{}, cur.maxNPrevItems(3))
assert.Equal(0, cur.idx)
assert.True(cur.advance())
assert.Equal([]sequenceItem{}, cur.maxNPrevItems(0))
assert.Equal([]sequenceItem{100}, cur.maxNPrevItems(1))
assert.Equal([]sequenceItem{100}, cur.maxNPrevItems(2))
assert.Equal([]sequenceItem{100}, cur.maxNPrevItems(3))
assert.Equal(0, cur.idx)
assert.True(cur.advance())
assert.Equal([]sequenceItem{}, cur.maxNPrevItems(0))
assert.Equal([]sequenceItem{101}, cur.maxNPrevItems(1))
assert.Equal([]sequenceItem{100, 101}, cur.maxNPrevItems(2))
assert.Equal([]sequenceItem{100, 101}, cur.maxNPrevItems(3))
assert.Equal(0, cur.idx)
assert.False(cur.advance())
assert.Equal([]sequenceItem{102}, cur.maxNPrevItems(1))
assert.Equal([]sequenceItem{101, 102}, cur.maxNPrevItems(2))
assert.Equal([]sequenceItem{100, 101, 102}, cur.maxNPrevItems(3))
assert.Equal([]sequenceItem{100, 101, 102}, cur.maxNPrevItems(4))
assert.Equal(1, cur.idx)
}
开发者ID:willhite,项目名称:noms-old,代码行数:31,代码来源:sequence_cursor_test.go
示例5: TestHandlePostRoot
func TestHandlePostRoot(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
input1, input2 := "abc", "def"
chnx := []chunks.Chunk{
chunks.NewChunk([]byte(input1)),
chunks.NewChunk([]byte(input2)),
}
err := cs.PutMany(chnx)
assert.NoError(err)
// First attempt should fail, as 'last' won't match.
u := &url.URL{}
queryParams := url.Values{}
queryParams.Add("last", chnx[0].Hash().String())
queryParams.Add("current", chnx[1].Hash().String())
u.RawQuery = queryParams.Encode()
w := httptest.NewRecorder()
HandleRootPost(w, &http.Request{URL: u, Method: "POST"}, params{}, cs)
assert.Equal(http.StatusConflict, w.Code, "Handler error:\n%s", string(w.Body.Bytes()))
// Now, update the root manually to 'last' and try again.
assert.True(cs.UpdateRoot(chnx[0].Hash(), hash.Hash{}))
w = httptest.NewRecorder()
HandleRootPost(w, &http.Request{URL: u, Method: "POST"}, params{}, cs)
assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes()))
}
开发者ID:willhite,项目名称:noms-old,代码行数:28,代码来源:remote_database_handlers_test.go
示例6: TestReadToList
func TestReadToList(t *testing.T) {
assert := assert.New(t)
ds := datas.NewDatabase(chunks.NewMemoryStore())
dataString := `a,1,true
b,2,false
`
r := NewCSVReader(bytes.NewBufferString(dataString), ',')
headers := []string{"A", "B", "C"}
kinds := KindSlice{types.StringKind, types.NumberKind, types.BoolKind}
l, typ := ReadToList(r, "test", headers, kinds, ds)
assert.Equal(uint64(2), l.Len())
assert.Equal(types.StructKind, typ.Kind())
desc, ok := typ.Desc.(types.StructDesc)
assert.True(ok)
assert.Equal(desc.Len(), 3)
assert.Equal(types.StringKind, desc.Field("A").Kind())
assert.Equal(types.NumberKind, desc.Field("B").Kind())
assert.Equal(types.BoolKind, desc.Field("C").Kind())
assert.True(l.Get(0).(types.Struct).Get("A").Equals(types.String("a")))
assert.True(l.Get(1).(types.Struct).Get("A").Equals(types.String("b")))
assert.True(l.Get(0).(types.Struct).Get("B").Equals(types.Number(1)))
assert.True(l.Get(1).(types.Struct).Get("B").Equals(types.Number(2)))
assert.True(l.Get(0).(types.Struct).Get("C").Equals(types.Bool(true)))
assert.True(l.Get(1).(types.Struct).Get("C").Equals(types.Bool(false)))
}
开发者ID:willhite,项目名称:noms-old,代码行数:33,代码来源:read_test.go
示例7: TestHandlePostRoot
func TestHandlePostRoot(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
vs := types.NewValueStore(types.NewBatchStoreAdaptor(cs))
commit := NewCommit(types.String("head"), types.NewSet(), types.NewStruct("Meta", types.StructData{}))
newHead := types.NewMap(types.String("dataset1"), vs.WriteValue(commit))
chnx := []chunks.Chunk{
chunks.NewChunk([]byte("abc")),
types.EncodeValue(newHead, nil),
}
err := cs.PutMany(chnx)
assert.NoError(err)
// First attempt should fail, as 'last' won't match.
u := &url.URL{}
queryParams := url.Values{}
queryParams.Add("last", chnx[0].Hash().String())
queryParams.Add("current", chnx[1].Hash().String())
u.RawQuery = queryParams.Encode()
url := u.String()
w := httptest.NewRecorder()
HandleRootPost(w, newRequest("POST", "", url, nil, nil), params{}, cs)
assert.Equal(http.StatusConflict, w.Code, "Handler error:\n%s", string(w.Body.Bytes()))
// Now, update the root manually to 'last' and try again.
assert.True(cs.UpdateRoot(chnx[0].Hash(), hash.Hash{}))
w = httptest.NewRecorder()
HandleRootPost(w, newRequest("POST", "", url, nil, nil), params{}, cs)
assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes()))
}
开发者ID:Richardphp,项目名称:noms,代码行数:32,代码来源:remote_database_handlers_test.go
示例8: TestVerifyStructFieldName
func TestVerifyStructFieldName(t *testing.T) {
assert := assert.New(t)
assertInvalid := func(n string) {
assert.Panics(func() {
MakeStructType("S", TypeMap{n: StringType})
})
}
assertInvalid("")
assertInvalid(" ")
assertInvalid(" a")
assertInvalid("a ")
assertInvalid("0")
assertInvalid("_")
assertInvalid("0a")
assertInvalid("_a")
assertInvalid("💩")
assertValid := func(n string) {
MakeStructType("S", TypeMap{n: StringType})
}
assertValid("a")
assertValid("A")
assertValid("a0")
assertValid("a_")
assertValid("a0_")
}
开发者ID:willhite,项目名称:noms-old,代码行数:27,代码来源:type_test.go
示例9: TestStringString
func TestStringString(t *testing.T) {
assert := assert.New(t)
s1 := String("")
s2 := String("foo")
assert.Equal("", string(s1))
assert.Equal("foo", string(s2))
}
开发者ID:willhite,项目名称:noms-old,代码行数:7,代码来源:string_test.go
示例10: TestNomsStructDiff
func TestNomsStructDiff(t *testing.T) {
assert := assert.New(t)
expected := `(root) {
- "four": "four"
+ "four": "four-diff"
}
["three"] {
- field3: "field3-data"
+ field3: "field3-data-diff"
}
`
fieldData := []interface{}{
"field1", "field1-data",
"field2", "field2-data",
"field3", "field3-data",
"field4", "field4-data",
}
s1 := createStruct("TestData", fieldData...)
s2 := s1.Set("field3", types.String("field3-data-diff"))
m1 := createMap("one", 1, "two", 2, "three", s1, "four", "four")
m2 := createMap("one", 1, "two", 2, "three", s2, "four", "four-diff")
buf := util.NewBuffer(nil)
Diff(buf, m1, m2)
assert.Equal(expected, buf.String())
}
开发者ID:Richardphp,项目名称:noms,代码行数:28,代码来源:diff_test.go
示例11: TestTypes
func TestTypes(t *testing.T) {
assert := assert.New(t)
vs := NewTestValueStore()
mapType := MakeMapType(StringType, NumberType)
setType := MakeSetType(StringType)
mahType := MakeStructType("MahStruct", TypeMap{
"Field1": StringType,
"Field2": BoolType,
})
recType := MakeStructType("RecursiveStruct", TypeMap{
"self": nil,
})
recType.Desc.(StructDesc).SetField("self", recType)
mRef := vs.WriteValue(mapType).TargetHash()
setRef := vs.WriteValue(setType).TargetHash()
mahRef := vs.WriteValue(mahType).TargetHash()
recRef := vs.WriteValue(recType).TargetHash()
assert.True(mapType.Equals(vs.ReadValue(mRef)))
assert.True(setType.Equals(vs.ReadValue(setRef)))
assert.True(mahType.Equals(vs.ReadValue(mahRef)))
assert.True(recType.Equals(vs.ReadValue(recRef)))
}
开发者ID:willhite,项目名称:noms-old,代码行数:25,代码来源:type_test.go
示例12: TestSetTypeAfterMutations
func TestSetTypeAfterMutations(t *testing.T) {
assert := assert.New(t)
smallTestChunks()
defer normalProductionChunks()
test := func(n int, c interface{}) {
values := generateNumbersAsValues(n)
s := NewSet(values...)
assert.Equal(s.Len(), uint64(n))
assert.IsType(c, s.sequence())
assert.True(s.Type().Equals(MakeSetType(NumberType)))
s = s.Insert(String("a"))
assert.Equal(s.Len(), uint64(n+1))
assert.IsType(c, s.sequence())
assert.True(s.Type().Equals(MakeSetType(MakeUnionType(NumberType, StringType))))
s = s.Remove(String("a"))
assert.Equal(s.Len(), uint64(n))
assert.IsType(c, s.sequence())
assert.True(s.Type().Equals(MakeSetType(NumberType)))
}
test(10, setLeafSequence{})
test(2000, orderedMetaSequence{})
}
开发者ID:Richardphp,项目名称:noms,代码行数:28,代码来源:set_test.go
示例13: TestSetIter2
func TestSetIter2(t *testing.T) {
assert := assert.New(t)
smallTestChunks()
defer normalProductionChunks()
doTest := func(ts testSet) {
set := ts.toSet()
sort.Sort(ValueSlice(ts))
idx := uint64(0)
endAt := uint64(64)
set.Iter(func(v Value) (done bool) {
assert.True(ts[idx].Equals(v))
if idx == endAt {
done = true
}
idx++
return
})
assert.Equal(endAt, idx-1)
}
doTest(getTestNativeOrderSet(16))
doTest(getTestRefValueOrderSet(2))
doTest(getTestRefToNativeOrderSet(2, NewTestValueStore()))
doTest(getTestRefToValueOrderSet(2, NewTestValueStore()))
}
开发者ID:Richardphp,项目名称:noms,代码行数:29,代码来源:set_test.go
示例14: TestSetRemove2
func TestSetRemove2(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
smallTestChunks()
defer normalProductionChunks()
assert := assert.New(t)
doTest := func(incr, offset int, ts testSet) {
whole := ts.toSet()
run := func(from, to int) {
expected := ts.Remove(from, to).toSet()
actual := whole.Remove(ts[from:to]...)
assert.Equal(expected.Len(), actual.Len())
assert.True(expected.Equals(actual))
diffSetTest(assert, expected, actual, 0, 0)
}
for i := 0; i < len(ts)-offset; i += incr {
run(i, i+offset)
}
run(len(ts)-offset, len(ts))
}
doTest(18, 3, getTestNativeOrderSet(9))
doTest(64, 1, getTestNativeOrderSet(32))
doTest(32, 1, getTestRefValueOrderSet(4))
doTest(32, 1, getTestRefToNativeOrderSet(4, NewTestValueStore()))
doTest(32, 1, getTestRefToValueOrderSet(4, NewTestValueStore()))
}
开发者ID:Richardphp,项目名称:noms,代码行数:31,代码来源:set_test.go
示例15: TestListDiffAdd5x5
func TestListDiffAdd5x5(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
smallTestChunks()
defer normalProductionChunks()
assert := assert.New(t)
nums1 := generateNumbersAsValues(5000)
nums2 := generateNumbersAsValues(5000)
for count := 5; count > 0; count-- {
nums2 = spliceValues(nums2, (count-1)*1000, 0, Number(0), Number(1), Number(2), Number(3), Number(4))
}
l1 := NewList(nums1...)
l2 := NewList(nums2...)
diff1 := accumulateDiffSplices(l1, l2)
diff2 := accumulateDiffSplices(l2, l1)
assert.Equal(len(diff1), len(diff2))
diff2Expected := []Splice{
Splice{5, 0, 5, 5},
Splice{1000, 0, 5, 1005},
Splice{2000, 0, 5, 2010},
Splice{3000, 0, 5, 3015},
Splice{4000, 0, 5, 4020},
}
assert.Equal(diff2Expected, diff2, "expected diff is wrong")
}
开发者ID:Richardphp,项目名称:noms,代码行数:30,代码来源:list_test.go
示例16: TestListTypeAfterMutations
func TestListTypeAfterMutations(t *testing.T) {
smallTestChunks()
defer normalProductionChunks()
assert := assert.New(t)
test := func(n int, c interface{}) {
values := generateNumbersAsValues(n)
l := NewList(values...)
assert.Equal(l.Len(), uint64(n))
assert.IsType(c, l.sequence())
assert.True(l.Type().Equals(MakeListType(NumberType)))
l = l.Append(String("a"))
assert.Equal(l.Len(), uint64(n+1))
assert.IsType(c, l.sequence())
assert.True(l.Type().Equals(MakeListType(MakeUnionType(NumberType, StringType))))
l = l.Splice(l.Len()-1, 1)
assert.Equal(l.Len(), uint64(n))
assert.IsType(c, l.sequence())
assert.True(l.Type().Equals(MakeListType(NumberType)))
}
test(15, listLeafSequence{})
test(1500, indexedMetaSequence{})
}
开发者ID:Richardphp,项目名称:noms,代码行数:28,代码来源:list_test.go
示例17: TestListDiffReplaceReverse5x100
func TestListDiffReplaceReverse5x100(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
smallTestChunks()
defer normalProductionChunks()
assert := assert.New(t)
nums1 := generateNumbersAsValues(5000)
nums2 := generateNumbersAsValues(5000)
for count := 5; count > 0; count-- {
out := reverseValues(nums2[(count-1)*1000 : (count-1)*1000+100])
nums2 = spliceValues(nums2, (count-1)*1000, 100, out...)
}
l1 := NewList(nums1...)
l2 := NewList(nums2...)
diff := accumulateDiffSplices(l2, l1)
diffExpected := []Splice{
Splice{0, 49, 50, 0},
Splice{50, 50, 49, 51},
Splice{1000, 49, 50, 1000},
Splice{1050, 50, 49, 1051},
Splice{2000, 49, 50, 2000},
Splice{2050, 50, 49, 2051},
Splice{3000, 49, 50, 3000},
Splice{3050, 50, 49, 3051},
Splice{4000, 49, 50, 4000},
Splice{4050, 50, 49, 4051},
}
assert.Equal(diffExpected, diff, "expected diff is wrong")
}
开发者ID:Richardphp,项目名称:noms,代码行数:33,代码来源:list_test.go
示例18: TestStreamingListCreation
func TestStreamingListCreation(t *testing.T) {
smallTestChunks()
defer normalProductionChunks()
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
assert := assert.New(t)
vs := NewTestValueStore()
simpleList := getTestList()
cl := NewList(simpleList...)
valueChan := make(chan Value)
listChan := NewStreamingList(vs, valueChan)
for _, v := range simpleList {
valueChan <- v
}
close(valueChan)
sl := <-listChan
assert.True(cl.Equals(sl))
cl.Iter(func(v Value, idx uint64) (done bool) {
done = !assert.True(v.Equals(sl.Get(idx)))
return
})
}
开发者ID:Richardphp,项目名称:noms,代码行数:26,代码来源:list_test.go
示例19: TestReadToMap
func TestReadToMap(t *testing.T) {
assert := assert.New(t)
ds := datas.NewDatabase(chunks.NewMemoryStore())
dataString := `a,1,true
b,2,false
`
r := NewCSVReader(bytes.NewBufferString(dataString), ',')
headers := []string{"A", "B", "C"}
kinds := KindSlice{types.StringKind, types.NumberKind, types.BoolKind}
m := ReadToMap(r, headers, 0, kinds, ds)
assert.Equal(uint64(2), m.Len())
assert.True(m.Type().Equals(
types.MakeMapType(types.StringType, types.MakeStructType("", map[string]*types.Type{
"B": types.NumberType,
"C": types.BoolType,
}))))
assert.True(m.Get(types.String("a")).Equals(types.NewStruct("", map[string]types.Value{
"B": types.Number(1),
"C": types.Bool(true),
})))
assert.True(m.Get(types.String("b")).Equals(types.NewStruct("", map[string]types.Value{
"B": types.Number(2),
"C": types.Bool(false),
})))
}
开发者ID:willhite,项目名称:noms-old,代码行数:29,代码来源:read_test.go
示例20: TestListRemoveAtMiddle
func TestListRemoveAtMiddle(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
assert := assert.New(t)
smallTestChunks()
defer normalProductionChunks()
cl := getTestList().toList()
cl2 := cl.RemoveAt(100)
cl3 := cl2.RemoveAt(200)
expected := getTestList()
assert.Equal(expected, testListFromNomsList(cl))
assert.Equal(getTestListLen(), cl.Len())
assert.True(expected.toList().Equals(cl))
expected = expected.RemoveAt(100)
assert.Equal(expected, testListFromNomsList(cl2))
assert.Equal(getTestListLen()-1, cl2.Len())
assert.True(expected.toList().Equals(cl2))
expected = expected.RemoveAt(200)
assert.Equal(expected, testListFromNomsList(cl3))
assert.Equal(getTestListLen()-2, cl3.Len())
assert.True(expected.toList().Equals(cl3))
}
开发者ID:Richardphp,项目名称:noms,代码行数:28,代码来源:list_test.go
注:本文中的github.com/attic-labs/testify/assert.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论