Repository navigation
Expand file tree
/
Copy pathpath_test.go
More file actions
72 lines (65 loc) · 1.61 KB
/
Copy pathpath_test.go
File metadata and controls
72 lines (65 loc) · 1.61 KB
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
72
package gitconfig_test
import (
"io/ioutil"
"os"
"testing"
"github.com/denormal/go-gitconfig"
"github.com/denormal/go-gittools"
)
func TestPath(t *testing.T) {
// skip this test if git is not installed
if !gittools.HasGit() {
t.Skip("git not installed")
}
// ensure New() works as expected
// - the current directory should be a working copy
// - these tests should work with current drectory and ""
_cwd, _err := os.Getwd()
if _err != nil {
t.Fatalf(
"unable to determine current working directory: %s",
_err.Error(),
)
}
// ensure Path() returns the expected value
for _, _path := range []string{_cwd, ""} {
_config, _err := gitconfig.NewWithPath(_path)
if _err != nil {
t.Fatalf(
"%q: unexpected error from NewWithPath: %s",
_path, _err.Error(),
)
} else if _config == nil {
t.Fatalf("%q: unexpected nil from NewWithPath", _path)
} else if _config.Path() != _cwd {
t.Fatalf(
"path mismatch: expected %q, got %q",
_cwd, _config.Path(),
)
}
}
// ensure New() works with a temporary directory that is
// not a part of a working copy
_dir, _err := ioutil.TempDir("", "")
if _err != nil {
t.Fatalf(
"unable to create temporary directory: %s",
_err.Error(),
)
}
defer os.RemoveAll(_dir)
_config, _err := gitconfig.NewWithPath(_dir)
if _err != nil {
t.Fatalf(
"%q: unexpected error from NewWithPath: %s",
_dir, _err.Error(),
)
} else if _config == nil {
t.Fatalf("%q: unexpected nil from NewWithPath", _dir)
} else if _config.Path() != _dir {
t.Fatalf(
"path mismatch: expected %q, got %q",
_dir, _config.Path(),
)
}
} // TestPath()