Skip to content

Commit 96c6e63

Browse files
committed
add tests for get path
1 parent 54a8082 commit 96c6e63

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

cloner/clone_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cloner
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/joshmedeski/sesh/model"
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestListSessions(t *testing.T) {
12+
t.Run("get path with both cmd and repo", func(t *testing.T) {
13+
mockOpts := model.GitCloneOptions{Repo: "https://www.github.comtest/repo.git", CmdDir: "cmdDir", Dir: "dir"}
14+
actual := getPath(mockOpts)
15+
assert.Equal(t, "cmdDir/dir", actual)
16+
})
17+
t.Run("get path cmdDir", func(t *testing.T) {
18+
mockOpts := model.GitCloneOptions{Repo: "https://www.github.comtest/repo.git", CmdDir: "cmdDir"}
19+
actual := getPath(mockOpts)
20+
assert.Equal(t, "cmdDir/repo", actual)
21+
})
22+
t.Run("get path dir", func(t *testing.T) {
23+
mockOpts := model.GitCloneOptions{Repo: "https://www.github.comtest/repo.git", Dir: "dir"}
24+
actual := getPath(mockOpts)
25+
expected, _ := os.Getwd()
26+
expected = expected + "/" + "dir"
27+
assert.Equal(t, expected, actual)
28+
})
29+
t.Run("get path with no dir or cmdDir", func(t *testing.T) {
30+
mockOpts := model.GitCloneOptions{Repo: "https://www.github.comtest/repo.git"}
31+
actual := getPath(mockOpts)
32+
expected, _ := os.Getwd()
33+
expected = expected + "/" + "repo"
34+
assert.Equal(t, expected, actual)
35+
})
36+
}

cloner/cloner.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ func (c *RealCloner) Clone(opts model.GitCloneOptions) (string, error) {
3131
return "", err
3232
}
3333

34+
path := getPath(opts)
35+
36+
newOpts := model.ConnectOpts{}
37+
if _, err := c.connector.Connect(path, newOpts); err != nil {
38+
return "", err
39+
}
40+
41+
return "", nil
42+
43+
}
44+
45+
func getPath(opts model.GitCloneOptions) string {
3446
var path string
3547
if opts.CmdDir != "" {
3648
path = opts.CmdDir
@@ -44,14 +56,7 @@ func (c *RealCloner) Clone(opts model.GitCloneOptions) (string, error) {
4456
repoName := getRepoName(opts.Repo)
4557
path = path + "/" + repoName
4658
}
47-
48-
newOpts := model.ConnectOpts{}
49-
if _, err := c.connector.Connect(path, newOpts); err != nil {
50-
return "", err
51-
}
52-
53-
return "", nil
54-
59+
return path
5560
}
5661

5762
func getRepoName(url string) string {

0 commit comments

Comments
 (0)