/usr/share/gocode/src/github.com/hanwen/go-fuse/splice/copy_test.go is in golang-github-hanwen-go-fuse-dev 0.0~git20171124.0.14c3015-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | // Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package splice
import (
"io/ioutil"
"os"
"testing"
)
func check(err error) {
if err != nil {
panic(err)
}
}
func TestCopyFile(t *testing.T) {
src, _ := ioutil.TempFile("", "termite")
err := ioutil.WriteFile(src.Name(), []byte("hello"), 0644)
if err != nil {
t.Error(err)
}
dst, _ := ioutil.TempFile("", "termite")
err = CopyFile(dst.Name(), src.Name(), 0755)
if err != nil {
t.Error(err)
}
c, err := ioutil.ReadFile(dst.Name())
if err != nil {
t.Error(err)
}
if string(c) != "hello" {
t.Error("mismatch", string(c))
}
}
func TestSpliceCopy(t *testing.T) {
src, err := ioutil.TempFile("", "termite")
check(err)
bs := make([]byte, 2*1024*1024)
for i := range bs {
bs[i] = byte(i % 256)
}
_, err = src.Write(bs)
check(err)
err = src.Close()
check(err)
src, err = os.Open(src.Name())
check(err)
dst, err := ioutil.TempFile("", "termite")
check(err)
if maxPipeSize%4096 != 0 || maxPipeSize < 4096 {
t.Error("pipe size should be page size multiple", maxPipeSize)
}
pool := newSplicePairPool()
p, err := pool.get()
if p != nil {
p.MaxGrow()
t.Logf("Splice size %d", p.size)
SpliceCopy(dst, src, p)
dst.Close()
src.Close()
p.Close()
} else {
t.Error("Could not open splice: ", err)
}
}
|