-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remote helmfile from git::ssh source
The remote helmfile feature introduced by #648 was unable to be sourced from private git repositories due to URL parsing issue in helmfile. This fixes that. Ref #469 (comment)
- Loading branch information
Showing
2 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import ( | |
"testing" | ||
) | ||
|
||
func TestRemote(t *testing.T) { | ||
func TestRemote_HttpsGitHub(t *testing.T) { | ||
cleanfs := map[string]string{ | ||
"path/to/home": "", | ||
} | ||
|
@@ -85,6 +85,77 @@ func TestRemote(t *testing.T) { | |
} | ||
} | ||
|
||
func TestRemote_SShGitHub(t *testing.T) { | ||
cleanfs := map[string]string{ | ||
"path/to/home": "", | ||
} | ||
cachefs := map[string]string{ | ||
"path/to/home/.helmfile/cache/ssh_github_com_cloudposse_helmfiles_git.ref=0.40.0/releases/kiam.yaml": "foo: bar", | ||
} | ||
|
||
type testcase struct { | ||
files map[string]string | ||
expectCacheHit bool | ||
} | ||
|
||
testcases := []testcase{ | ||
{files: cleanfs, expectCacheHit: false}, | ||
{files: cachefs, expectCacheHit: true}, | ||
} | ||
|
||
for i := range testcases { | ||
testcase := testcases[i] | ||
|
||
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) { | ||
testfs := testhelper.NewTestFs(testcase.files) | ||
|
||
hit := true | ||
|
||
get := func(wd, src, dst string) error { | ||
if wd != "path/to/home" { | ||
return fmt.Errorf("unexpected wd: %s", wd) | ||
} | ||
if src != "git::ssh://[email protected]/cloudposse/helmfiles.git?ref=0.40.0" { | ||
return fmt.Errorf("unexpected src: %s", src) | ||
} | ||
|
||
hit = false | ||
|
||
return nil | ||
} | ||
|
||
getter := &testGetter{ | ||
get: get, | ||
} | ||
remote := &Remote{ | ||
Logger: helmexec.NewLogger(os.Stderr, "debug"), | ||
Home: "path/to/home", | ||
Getter: getter, | ||
ReadFile: testfs.ReadFile, | ||
FileExists: testfs.FileExistsAt, | ||
DirExists: testfs.DirectoryExistsAt, | ||
} | ||
|
||
url := "git::ssh://[email protected]/cloudposse/helmfiles.git@releases/kiam.yaml?ref=0.40.0" | ||
file, err := remote.Locate(url) | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
|
||
if file != "path/to/home/.helmfile/cache/ssh_github_com_cloudposse_helmfiles_git.ref=0.40.0/releases/kiam.yaml" { | ||
t.Errorf("unexpected file located: %s", file) | ||
} | ||
|
||
if testcase.expectCacheHit && !hit { | ||
t.Errorf("unexpected result: unexpected cache miss") | ||
} | ||
if !testcase.expectCacheHit && hit { | ||
t.Errorf("unexpected result: unexpected cache hit") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
type testGetter struct { | ||
get func(wd, src, dst string) error | ||
} | ||
|
e51de37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func TestRemote