From cc98ffd6fa56f55dfeb2a6b5b130fd634f8b8abe Mon Sep 17 00:00:00 2001 From: Caleb Brose <5447118+cmbrose@users.noreply.github.com> Date: Wed, 21 Sep 2022 19:43:31 +0000 Subject: [PATCH] Ensure local keys don't interfere with ssh_test --- pkg/cmd/codespace/ssh_test.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/cmd/codespace/ssh_test.go b/pkg/cmd/codespace/ssh_test.go index fdbca1974..3f6cdfae3 100644 --- a/pkg/cmd/codespace/ssh_test.go +++ b/pkg/cmd/codespace/ssh_test.go @@ -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) - } - - tt.sshArgs = append(tt.sshArgs, "-F", configPath) + for _, key := range tt.sshConfigKeys { + configContent += fmt.Sprintf("IdentityFile %s\n", filepath.Join(sshDir, key)) } + 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 {