本文整理汇总了Golang中github.com/attic-labs/testify/assert.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
}
示例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])
}
}
示例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())
}
示例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)
}
示例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()))
}
示例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)))
}
示例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()))
}
示例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_")
}
示例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))
}
示例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())
}
示例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)))
}
示例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{})
}
示例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()))
}
示例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()))
}
示例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")
}