2024-09-24 13:44:54 -04:00
|
|
|
package taskfile
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGitNode_ssh(t *testing.T) {
|
2024-12-12 01:47:10 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2024-09-24 13:44:54 -04:00
|
|
|
node, err := NewGitNode("git@github.com:foo/bar.git//Taskfile.yml?ref=main", "", false)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "main", node.ref)
|
|
|
|
assert.Equal(t, "Taskfile.yml", node.path)
|
|
|
|
assert.Equal(t, "ssh://git@github.com/foo/bar.git//Taskfile.yml?ref=main", node.rawUrl)
|
|
|
|
assert.Equal(t, "ssh://git@github.com/foo/bar.git", node.URL.String())
|
|
|
|
entrypoint, err := node.ResolveEntrypoint("common.yml")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "ssh://git@github.com/foo/bar.git//common.yml?ref=main", entrypoint)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGitNode_sshWithDir(t *testing.T) {
|
2024-12-12 01:47:10 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2024-09-24 13:44:54 -04:00
|
|
|
node, err := NewGitNode("git@github.com:foo/bar.git//directory/Taskfile.yml?ref=main", "", false)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "main", node.ref)
|
|
|
|
assert.Equal(t, "directory/Taskfile.yml", node.path)
|
|
|
|
assert.Equal(t, "ssh://git@github.com/foo/bar.git//directory/Taskfile.yml?ref=main", node.rawUrl)
|
|
|
|
assert.Equal(t, "ssh://git@github.com/foo/bar.git", node.URL.String())
|
|
|
|
entrypoint, err := node.ResolveEntrypoint("common.yml")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "ssh://git@github.com/foo/bar.git//directory/common.yml?ref=main", entrypoint)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGitNode_https(t *testing.T) {
|
2024-12-12 01:47:10 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2024-09-24 13:44:54 -04:00
|
|
|
node, err := NewGitNode("https://github.com/foo/bar.git//Taskfile.yml?ref=main", "", false)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "main", node.ref)
|
|
|
|
assert.Equal(t, "Taskfile.yml", node.path)
|
|
|
|
assert.Equal(t, "https://github.com/foo/bar.git//Taskfile.yml?ref=main", node.rawUrl)
|
|
|
|
assert.Equal(t, "https://github.com/foo/bar.git", node.URL.String())
|
|
|
|
entrypoint, err := node.ResolveEntrypoint("common.yml")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "https://github.com/foo/bar.git//common.yml?ref=main", entrypoint)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGitNode_httpsWithDir(t *testing.T) {
|
2024-12-12 01:47:10 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2024-09-24 13:44:54 -04:00
|
|
|
node, err := NewGitNode("https://github.com/foo/bar.git//directory/Taskfile.yml?ref=main", "", false)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "main", node.ref)
|
|
|
|
assert.Equal(t, "directory/Taskfile.yml", node.path)
|
|
|
|
assert.Equal(t, "https://github.com/foo/bar.git//directory/Taskfile.yml?ref=main", node.rawUrl)
|
|
|
|
assert.Equal(t, "https://github.com/foo/bar.git", node.URL.String())
|
|
|
|
entrypoint, err := node.ResolveEntrypoint("common.yml")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "https://github.com/foo/bar.git//directory/common.yml?ref=main", entrypoint)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGitNode_FilenameAndDir(t *testing.T) {
|
2024-12-12 01:47:10 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2024-09-24 13:44:54 -04:00
|
|
|
node, err := NewGitNode("https://github.com/foo/bar.git//directory/Taskfile.yml?ref=main", "", 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//Taskfile.yml?ref=main", "", 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//multiple/directory/Taskfile.yml?ref=main", "", false)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
filename, dir = node.FilenameAndLastDir()
|
|
|
|
assert.Equal(t, "Taskfile.yml", filename)
|
|
|
|
assert.Equal(t, "directory", dir)
|
|
|
|
}
|