From 77636e2463087a77ef8eb235d23e293de5a9a2f8 Mon Sep 17 00:00:00 2001 From: Grzegorz Dlugoszewski Date: Sat, 16 May 2020 15:22:39 +0200 Subject: [PATCH] Add a simple unit test with a temp repository --- README.md | 3 ++- git-get_test.go | 33 +++++++++++++++++++++++++++++++++ go.mod | 1 - go.sum | 2 -- 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 git-get_test.go diff --git a/README.md b/README.md index aaf03df..c46b159 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/git-get_test.go b/git-get_test.go new file mode 100644 index 0000000..78a6400 --- /dev/null +++ b/git-get_test.go @@ -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()) + } +} diff --git a/go.mod b/go.mod index 22e17b3..42a6272 100644 --- a/go.mod +++ b/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 - diff --git a/go.sum b/go.sum index 57f5668..e69de29 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +0,0 @@ -github.com/libgit2/git2go/v30 v30.0.3 h1:v+KRMhx85kHS0JzkPft7Wnt3+VUrYQrD/SQ77usTO/w= -github.com/libgit2/git2go/v30 v30.0.3/go.mod h1:YReiQ7xhMoyAL4ISYFLZt+OGqn6xtLqvTC1xJ9oAH7Y=