-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add module parameter :use_ssh_agent to skip ssh-add before git over S…
…SH commands, fixes #171
- Loading branch information
Showing
7 changed files
with
105 additions
and
7 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
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 |
---|---|---|
|
@@ -98,7 +98,9 @@ func equalGitModule(a, b GitModule) bool { | |
a.ref != b.ref || | ||
a.link != b.link || | ||
a.ignoreUnreachable != b.ignoreUnreachable || | ||
a.installPath != b.installPath { | ||
a.installPath != b.installPath || | ||
a.local != b.local || | ||
a.useSSHAgent != b.useSSHAgent { | ||
return false | ||
} | ||
if len(a.fallback) != len(b.fallback) { | ||
|
@@ -500,3 +502,24 @@ func TestReadPuppetfileGitDashNSlashNotation(t *testing.T) { | |
t.Errorf("Expected Puppetfile: %+v, but got Puppetfile: %+v", expected, got) | ||
} | ||
} | ||
|
||
func TestReadPuppetfileSSHKeyAlreadyLoaded(t *testing.T) { | ||
quiet = true | ||
funcName := strings.Split(funcName(), ".")[len(strings.Split(funcName(), "."))-1] | ||
got := readPuppetfile("tests/"+funcName, "", "test", "test", false, false) | ||
|
||
fm := make(map[string]ForgeModule) | ||
gm := make(map[string]GitModule) | ||
gm["example_module"] = GitModule{git: "[email protected]/foo/example-module.git", branch: "foo", useSSHAgent: true} | ||
|
||
expected := Puppetfile{source: "test", gitModules: gm, forgeModules: fm} | ||
//fmt.Println(got) | ||
|
||
if !equalPuppetfile(got, expected) { | ||
fmt.Println("Expected:") | ||
spew.Dump(expected) | ||
fmt.Println("Got:") | ||
spew.Dump(got) | ||
t.Errorf("Expected Puppetfile: %+v, but got Puppetfile: %+v", expected, got) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"os/exec" | ||
"path/filepath" | ||
"reflect" | ||
"runtime" | ||
"strconv" | ||
"strings" | ||
"syscall" | ||
|
@@ -3208,3 +3209,56 @@ func TestBranchFilterRegex(t *testing.T) { | |
|
||
purgeDir("/tmp/branchfilter", funcName) | ||
} | ||
|
||
func TestResolvePuppetfileUseSSHAgent(t *testing.T) { | ||
quiet = true | ||
funcName := strings.Split(funcName(), ".")[len(strings.Split(funcName(), "."))-1] | ||
configFile = "tests/TestConfigUseSSHAgent.yaml" | ||
config = readConfigfile(configFile) | ||
if os.Getenv("TEST_FOR_CRASH_"+funcName) == "1" { | ||
purgeDir("/tmp/example/", funcName) | ||
purgeDir("/tmp/g10k/", funcName) | ||
debug = true | ||
branchParam = "use_ssh_agent" | ||
resolvePuppetEnvironment(false, "") | ||
return | ||
} | ||
|
||
cmd := exec.Command(os.Args[0], "-test.run="+funcName+"$") | ||
cmd.Env = append(os.Environ(), "TEST_FOR_CRASH_"+funcName+"=1") | ||
out, err := cmd.CombinedOutput() | ||
|
||
exitCode := 0 | ||
if msg, ok := err.(*exec.ExitError); ok { // there is error code | ||
exitCode = msg.Sys().(syscall.WaitStatus).ExitStatus() | ||
} | ||
|
||
if 1 != exitCode { | ||
t.Errorf("terminated with %v, but we expected exit status %v Output: %s", exitCode, 1, string(out)) | ||
} | ||
//fmt.Println(string(out)) | ||
|
||
sshAddCmd := "ssh-add" | ||
if runtime.GOOS == "darwin" { | ||
sshAddCmd = "ssh-add -K" | ||
} | ||
|
||
expectedLines := []string{ | ||
"DEBUG git repo url [email protected]:foo/git_module_with_ssh_agent.git with loaded SSH keys from ssh-agent", | ||
"DEBUG git repo url [email protected]:foobar/github_module_without_ssh_add.git with SSH key tests/TestConfigUseSSHAgent.yaml", | ||
"DEBUG git repo url [email protected]:bar/git_module_with_ssh_add.git with SSH key tests/TestConfigUseSSHAgent.yaml", | ||
"DEBUG executeCommand(): Executing git clone --mirror [email protected]:foo/git_module_with_ssh_agent.git /tmp/g10k/modules/[email protected]_git_module_with_ssh_agent.git", | ||
"DEBUG executeCommand(): Executing git clone --mirror [email protected]:foobar/github_module_without_ssh_add.git /tmp/g10k/modules/[email protected]_github_module_without_ssh_add.git", | ||
"DEBUG executeCommand(): Executing ssh-agent bash -c '" + sshAddCmd + " tests/TestConfigUseSSHAgent.yaml; git clone --mirror [email protected]:bar/git_module_with_ssh_add.git /tmp/g10k/modules/[email protected]_git_module_with_ssh_add.git'", | ||
} | ||
|
||
for _, expectedLine := range expectedLines { | ||
if !strings.Contains(string(out), expectedLine) { | ||
t.Errorf("Could not find expected line '" + expectedLine + "' in debug output") | ||
} | ||
} | ||
|
||
moduleParam = "" | ||
debug = false | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
:cachedir: '/tmp/g10k' | ||
|
||
sources: | ||
example: | ||
remote: 'https://github.com/xorpaul/g10k-environment.git' | ||
basedir: '/tmp/example/' | ||
private_key: 'tests/TestConfigUseSSHAgent.yaml' # just some existing file, we just want to check if the ssh-add command isn't used |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod 'example_module', | ||
:git => '[email protected]/foo/example-module.git', | ||
:branch => 'foo', | ||
:use_ssh_agent => true | ||
|