本文整理汇总了Golang中github.com/attic-labs/testify/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestPanicIfTrue
func TestPanicIfTrue(t *testing.T) {
assert := assert.New(t)
arg := "arg value"
format := "could be a format: %s"
formatted := fmt.Sprintf(format, arg)
assert.Panics(func() {
PanicIfTrue(true, "Panicking!!!!")
})
assert.NotPanics(func() {
PanicIfTrue(false, "Not panicking")
})
err := Try(func() {
PanicIfTrue(true, format)
})
assert.Equal(errors.New(format), Unwrap(err))
err = Try(func() {
PanicIfTrue(true, format, arg)
})
assert.Equal(errors.New(formatted), Unwrap(err))
}
示例2: TestMapTypeAfterMutations
func TestMapTypeAfterMutations(t *testing.T) {
assert := assert.New(t)
test := func(n int, c interface{}) {
values := make([]Value, 2*n)
for i := 0; i < n; i++ {
values[2*i] = Number(i)
values[2*i+1] = Number(i)
}
m := NewMap(values...)
assert.Equal(m.Len(), uint64(n))
assert.IsType(c, m.sequence())
assert.True(m.Type().Equals(MakeMapType(NumberType, NumberType)))
m = m.Set(String("a"), String("a"))
assert.Equal(m.Len(), uint64(n+1))
assert.IsType(c, m.sequence())
assert.True(m.Type().Equals(MakeMapType(MakeUnionType(NumberType, StringType), MakeUnionType(NumberType, StringType))))
m = m.Remove(String("a"))
assert.Equal(m.Len(), uint64(n))
assert.IsType(c, m.sequence())
assert.True(m.Type().Equals(MakeMapType(NumberType, NumberType)))
}
test(10, mapLeafSequence{})
test(1000, orderedMetaSequence{})
}
示例3: TestBuildWriteValueRequest
func TestBuildWriteValueRequest(t *testing.T) {
assert := assert.New(t)
input1, input2 := "abc", "def"
chnx := []chunks.Chunk{
chunks.NewChunk([]byte(input1)),
chunks.NewChunk([]byte(input2)),
}
hints := map[hash.Hash]struct{}{
hash.Parse("sha1-0000000000000000000000000000000000000002"): struct{}{},
hash.Parse("sha1-0000000000000000000000000000000000000003"): struct{}{},
}
compressed := buildWriteValueRequest(serializeChunks(chnx, assert), hints)
gr := snappy.NewReader(compressed)
count := 0
for hint := range deserializeHints(gr) {
count++
_, present := hints[hint]
assert.True(present)
}
assert.Equal(len(hints), count)
chunkChan := make(chan *chunks.Chunk, 16)
go chunks.DeserializeToChan(gr, chunkChan)
for c := range chunkChan {
assert.Equal(chnx[0].Hash(), c.Hash())
chnx = chnx[1:]
}
assert.Empty(chnx)
}
示例4: TestStringString
func TestStringString(t *testing.T) {
assert := assert.New(t)
s1 := String("")
s2 := String("foo")
assert.Equal("", string(s1))
assert.Equal("foo", string(s2))
}
示例5: TestListDiffRemove5x100
func TestListDiffRemove5x100(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
t.Parallel()
assert := assert.New(t)
nums1 := generateNumbersAsValues(5000)
nums2 := generateNumbersAsValues(5000)
for count := 5; count > 0; count-- {
nums2 = spliceValues(nums2, (count-1)*1000, 100)
}
l1 := NewList(nums1...)
l2 := NewList(nums2...)
diff1 := l1.Diff(l2)
diff2 := l2.Diff(l1)
assert.Equal(len(diff1), len(diff2))
diff2Expected := []Splice{
Splice{0, 100, 0, 0},
Splice{1000, 100, 0, 0},
Splice{2000, 100, 0, 0},
Splice{3000, 100, 0, 0},
Splice{4000, 100, 0, 0},
}
assert.Equal(diff2Expected, diff2, "expected diff is wrong")
}
示例6: 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{})
}
示例7: TestHandleGetRefs
func TestHandleGetRefs(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)
body := strings.NewReader(fmt.Sprintf("ref=%s&ref=%s", chnx[0].Hash(), chnx[1].Hash()))
w := httptest.NewRecorder()
HandleGetRefs(w,
&http.Request{Body: ioutil.NopCloser(body), Method: "POST", Header: http.Header{
"Content-Type": {"application/x-www-form-urlencoded"},
}},
params{},
cs,
)
if assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes())) {
chunkChan := make(chan *chunks.Chunk)
go chunks.DeserializeToChan(w.Body, chunkChan)
for c := range chunkChan {
assert.Equal(chnx[0].Hash(), c.Hash())
chnx = chnx[1:]
}
assert.Empty(chnx)
}
}
示例8: 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")
}
示例9: TestListDiffReverseWithLargerLimit
func TestListDiffReverseWithLargerLimit(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
smallTestChunks()
defer normalProductionChunks()
assert := assert.New(t)
nums1 := generateNumbersAsValues(5000)
nums2 := reverseValues(nums1)
l1 := NewList(nums1...)
l2 := NewList(nums2...)
diff1 := accumulateDiffSplicesWithLimit(l1, l2, 27e6)
diff2 := accumulateDiffSplicesWithLimit(l2, l1, 27e6)
assert.Equal(len(diff2), len(diff1))
diffExpected := []Splice{
Splice{0, 2499, 2500, 0},
Splice{2500, 2500, 2499, 2501},
}
assert.Equal(diffExpected, diff1, "expected diff is wrong")
assert.Equal(diffExpected, diff2, "expected diff is wrong")
}
示例10: TestBlobSplice
func TestBlobSplice(t *testing.T) {
assert := assert.New(t)
blob := NewEmptyBlob()
buf := new(bytes.Buffer)
blob = blob.Splice(0, 0, []byte("I'll do anything"))
buf.Reset()
buf.ReadFrom(blob.Reader())
assert.Equal(buf.String(), "I'll do anything")
blob = blob.Splice(16, 0, []byte(" for arv"))
buf.Reset()
buf.ReadFrom(blob.Reader())
assert.Equal(buf.String(), "I'll do anything for arv")
blob = blob.Splice(0, 0, []byte("Yes, "))
buf.Reset()
buf.ReadFrom(blob.Reader())
assert.Equal(buf.String(), "Yes, I'll do anything for arv")
blob = blob.Splice(5, 20, []byte("it's hard to satisfy"))
buf.Reset()
buf.ReadFrom(blob.Reader())
assert.Equal(buf.String(), "Yes, it's hard to satisfy arv")
}
示例11: TestIncrementalLoadList
func TestIncrementalLoadList(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
vs := newLocalValueStore(cs)
expected := NewList(testVals...)
ref := vs.WriteValue(expected).TargetHash()
actualVar := vs.ReadValue(ref)
actual := actualVar.(List)
expectedCount := cs.Reads
assert.Equal(1, expectedCount)
// There will be one read per chunk.
chunkReads := make([]int, expected.Len())
for i := uint64(0); i < expected.Len(); i++ {
v := actual.Get(i)
assert.True(expected.Get(i).Equals(v))
expectedCount += isEncodedOutOfLine(v)
assert.Equal(expectedCount+chunkReads[i], cs.Reads)
// Do it again to make sure multiple derefs don't do multiple loads.
v = actual.Get(i)
assert.Equal(expectedCount+chunkReads[i], cs.Reads)
}
}
示例12: TestLDBObject
func TestLDBObject(t *testing.T) {
assert := assert.New(t)
dir, err := ioutil.TempDir(os.TempDir(), "")
assert.NoError(err)
ldbpath := path.Join(dir, "xx-yy")
dsId := "dsId"
cs1 := chunks.NewLevelDBStoreUseFlags(ldbpath, "")
store1 := datas.NewDatabase(cs1)
dataset1 := dataset.NewDataset(store1, dsId)
s1 := types.String("Commit Value")
r1 := store1.WriteValue(s1)
_, err = dataset1.Commit(r1)
assert.NoError(err)
store1.Close()
spec2 := fmt.Sprintf("ldb:%s::%s", ldbpath, dsId)
assert.NoError(err)
sp1, err := ParseDatasetSpec(spec2)
assert.NoError(err)
dataset2, err := sp1.Dataset()
assert.NoError(err)
r2 := dataset2.HeadValue()
s2 := r2.(types.Ref).TargetValue(dataset2.Database())
assert.Equal(s1, s2)
dataset2.Database().Close()
spec3 := fmt.Sprintf("ldb:%s::%s", ldbpath, s1.Hash().String())
sp3, err := ParsePathSpec(spec3)
database, v3, err := sp3.Value()
assert.Equal(s1, v3)
database.Close()
}
示例13: 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])
}
}
示例14: SkipTestIncrementalAddRef
func SkipTestIncrementalAddRef(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
vs := newLocalValueStore(cs)
expectedItem := Number(42)
ref := vs.WriteValue(expectedItem)
expected := NewList(ref)
ref = vs.WriteValue(expected)
actualVar := vs.ReadValue(ref.TargetHash())
assert.Equal(1, cs.Reads)
assert.True(expected.Equals(actualVar))
actual := actualVar.(List)
actualItem := actual.Get(0)
assert.Equal(2, cs.Reads)
assert.True(expectedItem.Equals(actualItem))
// do it again to make sure caching works.
actualItem = actual.Get(0)
assert.Equal(2, cs.Reads)
assert.True(expectedItem.Equals(actualItem))
}
示例15: TestHeadValueFunctions
func TestHeadValueFunctions(t *testing.T) {
assert := assert.New(t)
id1 := "testdataset"
id2 := "otherdataset"
cs := chunks.NewMemoryStore()
ds1 := newDS(id1, cs)
// ds1: |a|
a := types.String("a")
ds1, err := ds1.CommitValue(a)
assert.NoError(err)
hv := ds1.Head().Get(datas.ValueField)
assert.Equal(a, hv)
assert.Equal(a, ds1.HeadValue())
hv, ok := ds1.MaybeHeadValue()
assert.True(ok)
assert.Equal(a, hv)
ds2 := newDS(id2, cs)
assert.Panics(func() {
ds2.HeadValue()
})
_, ok = ds2.MaybeHeadValue()
assert.False(ok)
}