Skip to content

Commit

Permalink
Merge pull request cli#6317 from cli/cmbrose/local-ssh-test-fix
Browse files Browse the repository at this point in the history
Ensure local keys don't interfere with ssh_test
  • Loading branch information
Nate Smith authored Sep 22, 2022
2 parents 6664707 + cc98ffd commit 87a0db2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pkg/cmd/codespace/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,22 @@ func TestSelectSSHKeys(t *testing.T) {
f.Close()
}

if tt.sshConfigKeys != nil {
configPath := filepath.Join(sshDir, "test-config")
configPath := filepath.Join(sshDir, "test-config")

configContent := ""
for _, key := range tt.sshConfigKeys {
configContent += fmt.Sprintf("IdentityFile %s\n", filepath.Join(sshDir, key))
}
// Seed the config with a non-existent key so that the default config won't apply
configContent := "IdentityFile dummy\n"

err := os.WriteFile(configPath, []byte(configContent), 0666)
if err != nil {
t.Fatalf("could not write test config %v", err)
}
for _, key := range tt.sshConfigKeys {
configContent += fmt.Sprintf("IdentityFile %s\n", filepath.Join(sshDir, key))
}

tt.sshArgs = append(tt.sshArgs, "-F", configPath)
err := os.WriteFile(configPath, []byte(configContent), 0666)
if err != nil {
t.Fatalf("could not write test config %v", err)
}

tt.sshArgs = append([]string{"-F", configPath}, tt.sshArgs...)

gotKeyPair, gotShouldAddArg, err := selectSSHKeys(context.Background(), sshContext, tt.sshArgs, sshOptions{profile: tt.profileOpt})

if tt.wantKeyPair == nil {
Expand Down

0 comments on commit 87a0db2

Please sign in to comment.