2022-08-01 11:51:19 +08:00
|
|
|
package define
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2024-08-16 00:50:07 +08:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-08-01 11:51:19 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseGitBuildContext(t *testing.T) {
|
2025-02-04 13:36:03 +08:00
|
|
|
t.Parallel()
|
2022-08-01 11:51:19 +08:00
|
|
|
// Tests with only repo
|
|
|
|
repo, subdir, branch := parseGitBuildContext("https://github.com/containers/repo.git")
|
|
|
|
assert.Equal(t, repo, "https://github.com/containers/repo.git")
|
|
|
|
assert.Equal(t, subdir, "")
|
|
|
|
assert.Equal(t, branch, "")
|
|
|
|
// Tests url with branch
|
|
|
|
repo, subdir, branch = parseGitBuildContext("https://github.com/containers/repo.git#main")
|
|
|
|
assert.Equal(t, repo, "https://github.com/containers/repo.git")
|
|
|
|
assert.Equal(t, subdir, "")
|
|
|
|
assert.Equal(t, branch, "main")
|
|
|
|
// Tests url with no branch and subdir
|
|
|
|
repo, subdir, branch = parseGitBuildContext("https://github.com/containers/repo.git#:mydir")
|
|
|
|
assert.Equal(t, repo, "https://github.com/containers/repo.git")
|
|
|
|
assert.Equal(t, subdir, "mydir")
|
|
|
|
assert.Equal(t, branch, "")
|
|
|
|
// Tests url with branch and subdir
|
|
|
|
repo, subdir, branch = parseGitBuildContext("https://github.com/containers/repo.git#main:mydir")
|
|
|
|
assert.Equal(t, repo, "https://github.com/containers/repo.git")
|
|
|
|
assert.Equal(t, subdir, "mydir")
|
|
|
|
assert.Equal(t, branch, "main")
|
|
|
|
}
|