8000 *: use gocheck's MkDir instead of TempDir for tests. Fixes #807 by uragirii · Pull Request #1194 · go-git/go-git · GitHub
[go: up one dir, main page]

Skip to content

*: use gocheck's MkDir instead of TempDir for tests. Fixes #807 #1194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
*: use gocheck's MkDir instead of TempDir for tests
  • Loading branch information
uragirii committed Sep 28, 2024
commit b3b5705d9de423fefc9ab2746221e59530a72d90
23 changes: 2 additions & 21 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,6 @@ func (s *BaseSuite) GetLocalRepositoryURL(f *fixtures.Fixture) string {
return f.DotGit().Root()
}

func (s *BaseSuite) TemporalDir() (path string, clean func()) {
fs := osfs.New(os.TempDir())
relPath, err := util.TempDir(fs, "", "")
if err != nil {
panic(err)
}

path = fs.Join(fs.Root(), relPath)
clean = func() {
_ = util.RemoveAll(fs, relPath)
}

return
}

func (s *BaseSuite) TemporalHomeDir() (path string, clean func()) {
home, err := os.UserHomeDir()
if err != nil {
Expand All @@ -171,8 +156,8 @@ func (s *BaseSuite) TemporalHomeDir() (path string, clean func()) {
return
}

func (s *BaseSuite) TemporalFilesystem() (fs billy.Filesystem, clean func()) {
fs = osfs.New(os.TempDir())
func (s *BaseSuite) TemporalFilesystem(c *C) (fs billy.Filesystem) {
fs = osfs.New(c.MkDir())
path, err := util.TempDir(fs, "", "")
if err != nil {
panic(err)
Expand All @@ -183,10 +168,6 @@ func (s *BaseSuite) TemporalFilesystem() (fs billy.Filesystem, clean func()) {
panic(err)
}

clean = func() {
_ = util.RemoveAll(fs, path)
}

return
}

Expand Down
3 changes: 1 addition & 2 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s *OptionsSuite) TestCreateTagOptionsLoadGlobal(c *C) {
}

func (s *OptionsSuite) writeGlobalConfig(c *C, cfg *config.Config) func() {
fs, clean := s.TemporalFilesystem()
fs := s.TemporalFilesystem(c)

tmp, err := util.TempDir(fs, "", "test-options")
c.Assert(err, IsNil)
Expand All @@ -115,7 +115,6 @@ func (s *OptionsSuite) writeGlobalConfig(c *C, cfg *config.Config) func() {
c.Assert(err, IsNil)

return func() {
clean()
os.Setenv("XDG_CONFIG_HOME", "")

}
Expand Down
2 changes: 1 addition & 1 deletion plumbing/format/packfile/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *ParserSuite) TestParserHashes(c *C) {
}

func (s *ParserSuite) TestThinPack(c *C) {
fs := osfs.New(os.TempDir())
fs := osfs.New(c.MkDir())
path, err := util.TempDir(fs, "", "")
c.Assert(err, IsNil)

Expand Down
3 changes: 1 addition & 2 deletions plumbing/transport/file/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (s *CommonSuite) SetUpSuite(c *C) {
}

var err error
s.tmpDir, err = os.MkdirTemp("", "")
s.tmpDir, err = os.MkdirTemp(c.MkDir(), "")
c.Assert(err, IsNil)
s.ReceivePackBin = filepath.Join(s.tmpDir, "git-receive-pack")
s.UploadPackBin = filepath.Join(s.tmpDir, "git-upload-pack")
Expand All @@ -38,5 +38,4 @@ func (s *CommonSuite) SetUpSuite(c *C) {

func (s *CommonSuite) TearDownSuite(c *C) {
defer s.Suite.TearDownSuite(c)
c.Assert(os.RemoveAll(s.tmpDir), IsNil)
}
7 changes: 1 addition & 6 deletions plumbing/transport/git/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *BaseSuite) SetUpTest(c *C) {
s.port, err = freePort()
c.Assert(err, IsNil)

s.base, err = 6DB6 os.MkdirTemp(os.TempDir(), fmt.Sprintf("go-git-protocol-%d", s.port))
s.base, err = os.MkdirTemp(c.MkDir(), fmt.Sprintf("go-git-protocol-%d", s.port))
c.Assert(err, IsNil)
}

Expand Down Expand Up @@ -95,11 +95,6 @@ func (s *BaseSuite) TearDownTest(c *C) {
_ = s.daemon.Process.Signal(os.Kill)
_ = s.daemon.Wait()
}

if s.base != "" {
err := os.RemoveAll(s.base)
c.Assert(err, IsNil)
}
}

func freePort() (int, error) {
Expand Down
7 changes: 1 addition & 6 deletions plumbing/transport/http/common_test.go
9E12
Original file line numberDiff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (s *BaseSuite) SetUpTest(c *C) {
l, err := net.Listen("tcp", "localhost:0")
c.Assert(err, IsNil)

base, err := os.MkdirTemp(os.TempDir(), fmt.Sprintf("go-git-http-%d", s.port))
base, err := os.MkdirTemp(c.MkDir(), fmt.Sprintf("go-git-http-%d", s.port))
c.Assert(err, IsNil)

s.port = l.Addr().(*net.TCPAddr).Port
Expand Down Expand Up @@ -283,8 +283,3 @@ func (s *BaseSuite) newEndpoint(c *C, name string) *transport.Endpoint {

return ep
}

func (s *BaseSuite) TearDownTest(c *C) {
err := os.RemoveAll(s.base)
c.Assert(err, IsNil)
}
2 changes: 1 addition & 1 deletion plumbing/transport/ssh/internal/test/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *ProxyEnvSuite) TestCommand(c *C) {
}()

s.port = sshListener.Addr().(*net.TCPAddr).Port
s.base, err = os.MkdirTemp(os.TempDir(), fmt.Sprintf("go-git-ssh-%d", s.port))
s.base, err = os.MkdirTemp(c.MkDir(), fmt.Sprintf("go-git-ssh-%d", s.port))
c.Assert(err, IsNil)

ggssh.DefaultAuthBuilder = func(user string) (ggssh.AuthMethod, error) {
Expand Down
2 changes: 1 addition & 1 deletion plumbing/transport/ssh/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *ProxySuite) TestCommand(c *C) {
}()

s.u.port = sshListener.Addr().(*net.TCPAddr).Port
s.u.base, err = os.MkdirTemp(os.TempDir(), fmt.Sprintf("go-git-ssh-%d", s.u.port))
s.u.base, err = os.MkdirTemp(c.MkDir(), fmt.Sprintf("go-git-ssh-%d", s.u.port))
c.Assert(err, IsNil)

DefaultAuthBuilder = func(user string) (AuthMethod, error) {
Expand Down
2 changes: 1 addition & 1 deletion plumbing/transport/ssh/upload_pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *UploadPackSuite) SetUpSuite(c *C) {
c.Assert(err, IsNil)

s.port = l.Addr().(*net.TCPAddr).Port
s.base, err = os.MkdirTemp(os.TempDir(), fmt.Sprintf("go-git-ssh-%d", s.port))
s.base, err = os.MkdirTemp(c.MkDir(), fmt.Sprintf("go-git-ssh-%d", s.port))
c.Assert(err, IsNil)

DefaultAuthBuilder = func(user string) (AuthMethod, error) {
Expand Down
Loading
Loading
0