Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
vmaerten committed Jun 28, 2024
1 parent 50c98b9 commit 2805b95
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
4 changes: 0 additions & 4 deletions taskfile/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,3 @@ func getDefaultDir(entrypoint, dir string) string {

return dir
}

func isGitNode(entrypoint string) (bool, error) {

}
3 changes: 1 addition & 2 deletions taskfile/node_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func NewGitNode(
if u.Scheme == "http" && !insecure {
return nil, &errors.TaskfileNotSecureError{URI: entrypoint}
}

return &GitNode{
BaseNode: base,
URL: u,
Expand Down Expand Up @@ -115,5 +114,5 @@ func (node *GitNode) ResolveDir(dir string) (string, error) {
}

func (node *GitNode) FilenameAndLastDir() (string, string) {
return "", filepath.Base(node.Entrypoint)
return filepath.Base(node.path), filepath.Base(filepath.Dir(node.path))
}
20 changes: 20 additions & 0 deletions taskfile/node_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,23 @@ func TestGitNode_httpsWithDir(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "https://github.com/foo/bar.git?ref=main//directory/common.yml", entrypoint)
}

func TestGitNode_FilenameAndDir(t *testing.T) {
node, err := NewGitNode("https://github.com/foo/bar.git?ref=main//directory/Taskfile.yml", "", false)
assert.NoError(t, err)
filename, dir := node.FilenameAndLastDir()
assert.Equal(t, "Taskfile.yml", filename)
assert.Equal(t, "directory", dir)

node, err = NewGitNode("https://github.com/foo/bar.git?ref=main//Taskfile.yml", "", false)
assert.NoError(t, err)
filename, dir = node.FilenameAndLastDir()
assert.Equal(t, "Taskfile.yml", filename)
assert.Equal(t, ".", dir)

node, err = NewGitNode("https://github.com/foo/bar.git?ref=main//multiple/directory/Taskfile.yml", "", false)
assert.NoError(t, err)
filename, dir = node.FilenameAndLastDir()
assert.Equal(t, "Taskfile.yml", filename)
assert.Equal(t, "directory", dir)
}
21 changes: 9 additions & 12 deletions taskfile/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ import (
"github.com/stretchr/testify/assert"
)

func TestIsGitNode(t *testing.T) {
isGit, err := isGitNode("https://github.com/foo/bar.git")
func TestScheme(t *testing.T) {
scheme, err := getScheme("https://github.com/foo/bar.git")
assert.NoError(t, err)
assert.True(t, isGit)
isGit, err = isGitNode("https://github.com/foo/bar.git?ref=v1//taskfile/common.yml")
assert.Equal(t, "git", scheme)
scheme, err = getScheme("https://github.com/foo/bar.git?ref=v1//taskfile/common.yml")
assert.NoError(t, err)
assert.True(t, isGit)
isGit, err = isGitNode("[email protected]:foo/bar.git?ref=main//Taskfile.yml")
assert.Equal(t, "git", scheme)
scheme, err = getScheme("[email protected]:foo/bar.git?ref=main//Taskfile.yml")
assert.NoError(t, err)
assert.True(t, isGit)
}

func TestIsNotGitNode(t *testing.T) {
isGit, err := isGitNode("https://github.com/foo/common.yml")
assert.Equal(t, "git", scheme)
scheme, err = getScheme("https://github.com/foo/common.yml")
assert.NoError(t, err)
assert.False(t, isGit)
assert.Equal(t, "https", scheme)
}

0 comments on commit 2805b95

Please sign in to comment.