mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 13:56:46 +00:00
Add a simple unit test with a temp repository
This commit is contained in:
@@ -26,7 +26,8 @@ How to build with `libgit2` statically linked into a single executable without d
|
||||
replace github.com/libgit2/git2go/v30 => ./static/git2go
|
||||
```
|
||||
|
||||
- Build `git-get` with `--tags static` flag:
|
||||
- Build, install and test `git-get` with `--tags static` flag, eg:
|
||||
```
|
||||
go build -i --tags static
|
||||
go test --tags static
|
||||
```
|
||||
|
||||
33
git-get_test.go
Normal file
33
git-get_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/libgit2/git2go/v30"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func createTempRepo(t *testing.T) *git.Repository {
|
||||
dir, err := ioutil.TempDir("", "test-repo-")
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't create a temp repo directory: %s", err.Error())
|
||||
}
|
||||
|
||||
t.Cleanup(func() {
|
||||
_ = os.RemoveAll(dir)
|
||||
})
|
||||
|
||||
repo, err := git.InitRepository(dir, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't init a temp repo: %s", err.Error())
|
||||
}
|
||||
return repo
|
||||
}
|
||||
|
||||
func TestTempRepo(t *testing.T) {
|
||||
repo := createTempRepo(t)
|
||||
|
||||
if repo.IsBare() {
|
||||
t.Errorf("Repository %s should not be bare", repo.Path())
|
||||
}
|
||||
}
|
||||
1
go.mod
1
go.mod
@@ -5,4 +5,3 @@ go 1.14
|
||||
require github.com/libgit2/git2go/v30 v30.0.3
|
||||
|
||||
replace github.com/libgit2/git2go/v30 => ./static/git2go
|
||||
|
||||
|
||||
Reference in New Issue
Block a user