add tests

main
jolheiser 2025-02-23 11:58:10 -06:00
parent d4b287ed08
commit 20a8451427
No known key found for this signature in database
3 changed files with 49 additions and 1 deletions

3
go.mod
View File

@ -5,6 +5,7 @@ go 1.23.1
toolchain go1.23.3 toolchain go1.23.3
require ( require (
github.com/alecthomas/assert/v2 v2.11.0
github.com/alecthomas/chroma/v2 v2.15.0 github.com/alecthomas/chroma/v2 v2.15.0
github.com/charmbracelet/ssh v0.0.0-20241211182756-4fe22b0f1b7c github.com/charmbracelet/ssh v0.0.0-20241211182756-4fe22b0f1b7c
github.com/charmbracelet/wish v1.4.4 github.com/charmbracelet/wish v1.4.4
@ -25,6 +26,7 @@ require (
dario.cat/mergo v1.0.1 // indirect dario.cat/mergo v1.0.1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.1.4 // indirect github.com/ProtonMail/go-crypto v1.1.4 // indirect
github.com/alecthomas/repr v0.4.0 // indirect
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/bubbletea v1.2.4 // indirect github.com/charmbracelet/bubbletea v1.2.4 // indirect
@ -46,6 +48,7 @@ require (
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect

View File

@ -1 +1 @@
sha256-+pv4dv79+/WUMiPmlK9eebS3NR6aT8q/Cw+MZ5BWoxg= sha256-L87PnM43gHrDcsRr3wnkB4e1Th2S0LsSwkXuebAFH44=

View File

@ -0,0 +1,45 @@
package git_test
import (
"path/filepath"
"testing"
"github.com/alecthomas/assert/v2"
"go.jolheiser.com/ugit/internal/git"
)
func TestEnsureRepo(t *testing.T) {
tmp := t.TempDir()
ok, err := git.PathExists(filepath.Join(tmp, "test"))
assert.False(t, ok, "repo should not exist yet")
assert.NoError(t, err, "PathExists should not error when repo doesn't exist")
err = git.EnsureRepo(tmp, "test")
assert.NoError(t, err, "repo should be created")
ok, err = git.PathExists(filepath.Join(tmp, "test"))
assert.True(t, ok, "repo should exist")
assert.NoError(t, err, "EnsureRepo should not error when path exists")
err = git.EnsureRepo(tmp, "test")
assert.NoError(t, err, "repo should already exist")
}
func TestRepo(t *testing.T) {
tmp := t.TempDir()
err := git.EnsureRepo(tmp, "test.git")
assert.NoError(t, err, "should create repo")
repo, err := git.NewRepo(tmp, "test")
assert.NoError(t, err, "should init new repo")
assert.True(t, repo.Meta.Private, "repo should default to private")
repo.Meta.Private = false
err = repo.SaveMeta()
assert.NoError(t, err, "should save repo meta")
repo, err = git.NewRepo(tmp, "test")
assert.NoError(t, err, "should not error when getting existing repo")
assert.False(t, repo.Meta.Private, "repo should be public after saving meta")
}