本文整理匯總了Golang中camlistore/org/pkg/test.Fetcher.BlobContents方法的典型用法代碼示例。如果您正苦於以下問題:Golang Fetcher.BlobContents方法的具體用法?Golang Fetcher.BlobContents怎麽用?Golang Fetcher.BlobContents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類camlistore/org/pkg/test.Fetcher
的用法示例。
在下文中一共展示了Fetcher.BlobContents方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestReaderSeekStress
func TestReaderSeekStress(t *testing.T) {
const fileSize = 750<<10 + 123
bigFile := make([]byte, fileSize)
rnd := rand.New(rand.NewSource(1))
for i := range bigFile {
bigFile[i] = byte(rnd.Intn(256))
}
sto := new(test.Fetcher) // in-memory blob storage
fileMap := NewFileMap("testfile")
fileref, err := WriteFileMap(sto, fileMap, bytes.NewReader(bigFile))
if err != nil {
t.Fatalf("WriteFileMap: %v", err)
}
c, ok := sto.BlobContents(fileref)
if !ok {
t.Fatal("expected file contents to be present")
}
const debug = false
if debug {
t.Logf("Fileref %s: %s", fileref, c)
}
// Test a bunch of reads at different offsets, making sure we always
// get the same results.
skipBy := int64(999)
if testing.Short() {
skipBy += 10 << 10
}
for off := int64(0); off < fileSize; off += skipBy {
fr, err := NewFileReader(sto, fileref)
if err != nil {
t.Fatal(err)
}
skipBytes(fr, uint64(off))
got, err := ioutil.ReadAll(fr)
if err != nil {
t.Fatal(err)
}
want := bigFile[off:]
if !bytes.Equal(got, want) {
t.Errorf("Incorrect read at offset %d:\n got: %s\n want: %s", off, summary(got), summary(want))
off := 0
for len(got) > 0 && len(want) > 0 && got[0] == want[0] {
off++
got = got[1:]
want = want[1:]
}
t.Errorf(" differences start at offset %d:\n got: %s\n want: %s\n", off, summary(got), summary(want))
break
}
fr.Close()
}
}