Skip to content

Commit 2a22cf2

Browse files
committed
Adds test for function parsing git url
1 parent 2da3260 commit 2a22cf2

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

pkg/patterns/addon/pkg/loaders/git.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var _ Repository = &GitRepository{}
2222

2323
// NewGitRepository constructs an GitRepository
2424
func NewGitRepository(baseurl string) *GitRepository{
25-
baseurl, subDir := parseGitUrl(baseurl)
25+
baseurl, subDir := parseGitURL(baseurl)
2626
return &GitRepository{
2727
baseURL: baseurl,
2828
subDir: subDir,
@@ -119,7 +119,7 @@ func (r *GitRepository) readURL(url string) ([]byte, error) {
119119
return b, nil
120120
}
121121

122-
func parseGitUrl(url string) (string, string){
122+
func parseGitURL(url string) (string, string){
123123
// checks for git:: suffix
124124
var subdir string
125125
if strings.HasPrefix(url, "git::") {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package loaders
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestParseGitURL(t *testing.T) {
8+
tests := []struct{
9+
rawURL string
10+
baseURL string
11+
subDir string
12+
}{
13+
{
14+
rawURL: "https://github.com/testRepository.git",
15+
baseURL: "https://github.com/testRepository.git",
16+
subDir: "",
17+
},
18+
{
19+
rawURL: "git::https://github.com/testRepository.git",
20+
baseURL: "https://github.com/testRepository.git",
21+
subDir: "",
22+
},
23+
{
24+
rawURL: "git::https://github.com/testRepository.git//subDir/package",
25+
baseURL: "https://github.com/testRepository.git",
26+
subDir: "subDir/package",
27+
},
28+
}
29+
30+
for _, tt := range tests {
31+
actualBase, actualSubDir := parseGitURL(tt.rawURL)
32+
if actualBase != tt.baseURL {
33+
t.Errorf("Expected base url: %v, got %v", tt.baseURL, actualBase)
34+
}
35+
36+
if actualSubDir != tt.subDir {
37+
t.Errorf("Expected base url: %v, got %v", tt.subDir, actualSubDir)
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)