示例#1
0
func TestRename(t *testing.T) {
	path := "c:/gowork/example.txt"
	os.Remove(path)
	f := file.New(path)
	err := f.Create()
	if err != nil {
		t.Fatal(err)
	}
	ex, err := exists(path)
	if err != nil {
		t.Fatal(err)
	}
	if !ex {
		t.Fatal("Not created.")
	}
	newname := "laliboy.txt"
	err = f.Rename(newname)
	if err != nil {
		t.Fatal(err)
	}
	newpath := filepath.Join(filepath.Dir(path), newname)
	ex, err = exists(newpath)
	if err != nil {
		t.Fatal(err)
	}
	if !ex {
		t.Fatal("Rename didn't happen.")
	}
}
示例#2
0
func TestCreate(t *testing.T) {
	path := "c:/gowork/example.txt"
	os.Remove(path)
	f := file.New(path)
	err := f.Create()
	if err != nil {
		t.Fatal(err)
	}
	ex, err := exists(path)
	if err != nil {
		t.Fatal(err)
	}
	if !ex {
		t.Fatal("Not created.")
	}
}
示例#3
0
func (d *Directory) File(s string) iface.File {
	return file.New(filepath.Join(d.path, s))
}
示例#4
0
func (f *FileInfo) File() iface.File {
	if f.isDir {
		panic("Not a file")
	}
	return file.New(f.path)
}
示例#5
0
func (d *Directory) File(s ...string) iface.File {
	arg := []string{d.path}
	arg = append(arg, s...)
	return file.New(filepath.Join(arg...))
}