示例#1
0
文件: fs_test.go 项目: koding/koding
func TestMain(m *testing.M) {
	flag.Parse()

	// NOTE(rjeczalik): copy testdata/testfile1.txt so after test execution
	// the file is not modified.
	if err := testutil.FileCopy("testdata/testfile1.txt", testfile1); err != nil {
		panic(err)
	}

	kiteURL := testutil.GenKiteURL()

	fs = kite.New("fs", "0.0.1")
	fs.Config.DisableAuthentication = true
	fs.Config.Port = kiteURL.Port()
	fs.HandleFunc("readDirectory", ReadDirectory)
	fs.HandleFunc("glob", Glob)
	fs.HandleFunc("readFile", ReadFile)
	fs.HandleFunc("writeFile", WriteFile)
	fs.HandleFunc("uniquePath", UniquePath)
	fs.HandleFunc("getInfo", GetInfo)
	fs.HandleFunc("setPermissions", SetPermissions)
	fs.HandleFunc("remove", Remove)
	fs.HandleFunc("rename", Rename)
	fs.HandleFunc("createDirectory", CreateDirectory)
	fs.HandleFunc("move", Move)
	fs.HandleFunc("copy", Copy)
	fs.HandleFunc("getDiskInfo", GetDiskInfo)

	go fs.Run()
	<-fs.ServerReadyNotify()
	defer fs.Close()

	remoteKite := kite.New("remote", "0.0.1")
	remoteKite.Config.Username = "******"
	remote = remoteKite.NewClient(kiteURL.String())
	err := remote.Dial()
	if err != nil {
		log.Fatalf("err")
	}
	defer remoteKite.Close()

	remoteKite2 := kite.New("remote2", "0.0.1")
	remoteKite2.Config.Username = "******"
	remote2 = remoteKite2.NewClient(kiteURL.String())
	err = remote2.Dial()
	if err != nil {
		log.Fatalf("err")
	}
	defer remoteKite2.Close()

	os.Exit(m.Run())
}
示例#2
0
func makeTempAndCopy(copyFrom string) (dir, path string, err error) {
	tmpDir, err := ioutil.TempDir("", "logfetcher")
	if err != nil {
		return "", "", err
	}

	tmpFile := filepath.Join(tmpDir, "file")

	// Create a new file for testing, so we can test offsetting and watching.
	if err := testutil.FileCopy(copyFrom, tmpFile); err != nil {
		return "", "", err
	}

	return tmpDir, tmpFile, nil
}