diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-14 00:44:18 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-14 00:44:18 +0200 |
commit | f826cf9d42cc34e2ae5aaf6ede892ecab9d2f198 (patch) | |
tree | 7555e7596887f239ce26828e98142e4df25c388f /examples/fs_implementation | |
parent | 79087748f60f9aba219624a0fe9f4d33a0b51236 (diff) | |
download | go-git-f826cf9d42cc34e2ae5aaf6ede892ecab9d2f198.tar.gz |
fix tests and examples
Diffstat (limited to 'examples/fs_implementation')
-rw-r--r-- | examples/fs_implementation/main.go | 22 | ||||
-rw-r--r-- | examples/fs_implementation/main_test.go | 12 |
2 files changed, 17 insertions, 17 deletions
diff --git a/examples/fs_implementation/main.go b/examples/fs_implementation/main.go index 552a923..a9bfbe6 100644 --- a/examples/fs_implementation/main.go +++ b/examples/fs_implementation/main.go @@ -9,7 +9,7 @@ import ( "strings" "gopkg.in/src-d/go-git.v4" - gogitFS "gopkg.in/src-d/go-git.v4/utils/fs" + "gopkg.in/src-d/go-git.v4/utils/fs" ) func main() { @@ -18,9 +18,9 @@ func main() { os.Exit(1) } - fs := newFS(os.Args[1]) + fs := NewCustomFS(os.Args[1]) - repo, err := git.NewRepositoryFromFS(fs, ".git") + repo, err := git.NewFilesystemRepository(fs, ".git") if err != nil { fmt.Fprint(os.Stderr, err) os.Exit(1) @@ -57,19 +57,19 @@ func usage() { // // Example: when constructed with 'newFS("tmp")', a path like 'foo--bar' // will represent the local path "/tmp/foo/bar". -type fs struct { +type CustomFS struct { base string } const separator = "--" -func newFS(path string) *fs { - return &fs{ +func NewCustomFS(path string) *CustomFS { + return &CustomFS{ base: path, } } -func (fs *fs) Stat(path string) (info os.FileInfo, err error) { +func (fs *CustomFS) Stat(path string) (info os.FileInfo, err error) { f, err := os.Open(fs.ToReal(path)) if err != nil { return nil, err @@ -85,19 +85,19 @@ func (fs *fs) Stat(path string) (info os.FileInfo, err error) { return f.Stat() } -func (fs *fs) ToReal(path string) string { +func (fs *CustomFS) ToReal(path string) string { parts := strings.Split(path, separator) return filepath.Join(fs.base, filepath.Join(parts...)) } -func (fs *fs) Open(path string) (gogitFS.ReadSeekCloser, error) { +func (fs *CustomFS) Open(path string) (fs.ReadSeekCloser, error) { return os.Open(fs.ToReal(path)) } -func (fs *fs) ReadDir(path string) ([]os.FileInfo, error) { +func (fs *CustomFS) ReadDir(path string) ([]os.FileInfo, error) { return ioutil.ReadDir(fs.ToReal(path)) } -func (fs *fs) Join(elem ...string) string { +func (fs *CustomFS) Join(elem ...string) string { return strings.Join(elem, separator) } diff --git a/examples/fs_implementation/main_test.go b/examples/fs_implementation/main_test.go index 9683b1b..ed56cf1 100644 --- a/examples/fs_implementation/main_test.go +++ b/examples/fs_implementation/main_test.go @@ -20,7 +20,7 @@ func TestMain(m *testing.M) { func setUp() { var err error - repo, err = tgz.Extract("../../storage/filesystem/internal/gitdir/fixtures/spinnaker-gc.tgz") + repo, err = tgz.Extract("../../storage/filesystem/internal/dotgit/fixtures/spinnaker-gc.tgz") if err != nil { panic(err) } @@ -36,7 +36,7 @@ func tearDown() { } func TestJoin(t *testing.T) { - fs := newFS("") + fs := NewCustomFS("") for i, test := range [...]struct { input []string expected string @@ -64,7 +64,7 @@ func TestJoin(t *testing.T) { } func TestStat(t *testing.T) { - fs := newFS(filepath.Join(repo, ".git/")) + fs := NewCustomFS(filepath.Join(repo, ".git/")) for i, path := range [...]string{ "index", "info--refs", @@ -98,7 +98,7 @@ func TestStat(t *testing.T) { } func TestStatErrors(t *testing.T) { - fs := newFS(filepath.Join(repo, ".git/")) + fs := NewCustomFS(filepath.Join(repo, ".git/")) for i, test := range [...]struct { input string errRegExp string @@ -125,7 +125,7 @@ func TestStatErrors(t *testing.T) { } func TestOpen(t *testing.T) { - fs := newFS(filepath.Join(repo, ".git/")) + fs := NewCustomFS(filepath.Join(repo, ".git/")) for i, path := range [...]string{ "index", "info--refs", @@ -169,7 +169,7 @@ func TestOpen(t *testing.T) { } func TestReadDir(t *testing.T) { - fs := newFS(filepath.Join(repo, ".git/")) + fs := NewCustomFS(filepath.Join(repo, ".git/")) for i, path := range [...]string{ "info", ".", |