From b7c353553a83f013c4663e16126d29a9647626f2 Mon Sep 17 00:00:00 2001 From: Micheal Wilkinson Date: Thu, 19 Mar 2026 14:25:37 +0000 Subject: [PATCH] test(core): add dedicated list and show_path suites --- internal/homesick/core/list_test.go | 72 ++++++++++++++++++++++++ internal/homesick/core/show_path_test.go | 51 +++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 internal/homesick/core/list_test.go create mode 100644 internal/homesick/core/show_path_test.go diff --git a/internal/homesick/core/list_test.go b/internal/homesick/core/list_test.go new file mode 100644 index 0000000..19f9a97 --- /dev/null +++ b/internal/homesick/core/list_test.go @@ -0,0 +1,72 @@ +package core_test + +import ( + "bytes" + "io" + "os" + "path/filepath" + "testing" + + "git.hrafn.xyz/aether/gosick/internal/homesick/core" + git "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/config" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" +) + +type ListSuite struct { + suite.Suite + tmpDir string + homeDir string + reposDir string + stdout *bytes.Buffer + app *core.App +} + +func TestListSuite(t *testing.T) { + suite.Run(t, new(ListSuite)) +} + +func (s *ListSuite) SetupTest() { + s.tmpDir = s.T().TempDir() + s.homeDir = filepath.Join(s.tmpDir, "home") + s.reposDir = filepath.Join(s.homeDir, ".homesick", "repos") + require.NoError(s.T(), os.MkdirAll(s.reposDir, 0o755)) + + s.stdout = &bytes.Buffer{} + s.app = &core.App{ + HomeDir: s.homeDir, + ReposDir: s.reposDir, + Stdout: s.stdout, + Stderr: io.Discard, + } +} + +func (s *ListSuite) createCastleRepo(castle string, remoteURL string) { + castleRoot := filepath.Join(s.reposDir, filepath.FromSlash(castle)) + require.NoError(s.T(), os.MkdirAll(castleRoot, 0o755)) + + repo, err := git.PlainInit(castleRoot, false) + require.NoError(s.T(), err) + + if remoteURL != "" { + _, err = repo.CreateRemote(&config.RemoteConfig{Name: "origin", URLs: []string{remoteURL}}) + require.NoError(s.T(), err) + } +} + +func (s *ListSuite) TestList_OutputsSortedCastlesWithRemoteURLs() { + s.createCastleRepo("zomg", "git://github.com/technicalpickles/zomg.git") + s.createCastleRepo("wtf/zomg", "git://github.com/technicalpickles/wtf-zomg.git") + s.createCastleRepo("alpha", "git://github.com/technicalpickles/alpha.git") + + require.NoError(s.T(), s.app.List()) + + require.Equal( + s.T(), + "alpha git://github.com/technicalpickles/alpha.git\n"+ + "wtf/zomg git://github.com/technicalpickles/wtf-zomg.git\n"+ + "zomg git://github.com/technicalpickles/zomg.git\n", + s.stdout.String(), + ) +} \ No newline at end of file diff --git a/internal/homesick/core/show_path_test.go b/internal/homesick/core/show_path_test.go new file mode 100644 index 0000000..8241e9b --- /dev/null +++ b/internal/homesick/core/show_path_test.go @@ -0,0 +1,51 @@ +package core_test + +import ( + "bytes" + "io" + "os" + "path/filepath" + "testing" + + "git.hrafn.xyz/aether/gosick/internal/homesick/core" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" +) + +type ShowPathSuite struct { + suite.Suite + tmpDir string + homeDir string + reposDir string + stdout *bytes.Buffer + app *core.App +} + +func TestShowPathSuite(t *testing.T) { + suite.Run(t, new(ShowPathSuite)) +} + +func (s *ShowPathSuite) SetupTest() { + s.tmpDir = s.T().TempDir() + s.homeDir = filepath.Join(s.tmpDir, "home") + s.reposDir = filepath.Join(s.homeDir, ".homesick", "repos") + require.NoError(s.T(), os.MkdirAll(s.reposDir, 0o755)) + + s.stdout = &bytes.Buffer{} + s.app = &core.App{ + HomeDir: s.homeDir, + ReposDir: s.reposDir, + Stdout: s.stdout, + Stderr: io.Discard, + } +} + +func (s *ShowPathSuite) TestShowPath_OutputsCastlePath() { + require.NoError(s.T(), s.app.ShowPath("castle_repo")) + + require.Equal( + s.T(), + filepath.Join(s.reposDir, "castle_repo")+"\n", + s.stdout.String(), + ) +}