test(core): add dedicated list and show_path suites
This commit is contained in:
72
internal/homesick/core/list_test.go
Normal file
72
internal/homesick/core/list_test.go
Normal file
@@ -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(),
|
||||
)
|
||||
}
|
||||
51
internal/homesick/core/show_path_test.go
Normal file
51
internal/homesick/core/show_path_test.go
Normal file
@@ -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(),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user