MCPcopy Create free account
hub / github.com/cli/cli / TestSelectSSHKeys

Function TestSelectSSHKeys

pkg/cmd/codespace/ssh_test.go:121–281  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

119}
120
121func TestSelectSSHKeys(t *testing.T) {
122 // This string will be substituted in sshArgs for test cases
123 // This is to work around the temp test ssh dir not being known until the test is executing
124 substituteSSHDir := "SUB_SSH_DIR"
125
126 tests := []struct {
127 sshDirFiles []string
128 sshConfigKeys []string
129 sshArgs []string
130 profileOpt string
131 wantKeyPair *ssh.KeyPair
132 wantShouldAddArg bool
133 }{
134 // -i tests
135 {
136 sshArgs: []string{"-i", "custom-private-key"},
137 wantKeyPair: &ssh.KeyPair{PrivateKeyPath: "custom-private-key", PublicKeyPath: "custom-private-key.pub"},
138 },
139 {
140 sshArgs: []string{"-i", path.Join(substituteSSHDir, automaticPrivateKeyName)},
141 wantKeyPair: &ssh.KeyPair{PrivateKeyPath: automaticPrivateKeyName, PublicKeyPath: automaticPrivateKeyName + ".pub"},
142 },
143 {
144 // Edge case check for missing arg value
145 sshArgs: []string{"-i"},
146 },
147
148 // Auto key exists tests
149 {
150 sshDirFiles: []string{automaticPrivateKeyName, automaticPrivateKeyName + ".pub"},
151 wantKeyPair: &ssh.KeyPair{PrivateKeyPath: automaticPrivateKeyName, PublicKeyPath: automaticPrivateKeyName + ".pub"},
152 wantShouldAddArg: true,
153 },
154 {
155 sshDirFiles: []string{automaticPrivateKeyName, automaticPrivateKeyName + ".pub", "custom-private-key", "custom-private-key.pub"},
156 wantKeyPair: &ssh.KeyPair{PrivateKeyPath: automaticPrivateKeyName, PublicKeyPath: automaticPrivateKeyName + ".pub"},
157 wantShouldAddArg: true,
158 },
159
160 // SSH config tests
161 {
162 sshDirFiles: []string{"custom-private-key", "custom-private-key.pub"},
163 sshConfigKeys: []string{"custom-private-key"},
164 wantKeyPair: &ssh.KeyPair{PrivateKeyPath: "custom-private-key", PublicKeyPath: "custom-private-key.pub"},
165 wantShouldAddArg: true,
166 },
167 {
168 // 2 pairs, but only 1 is configured
169 sshDirFiles: []string{"custom-private-key", "custom-private-key.pub", "custom-private-key-2", "custom-private-key-2.pub"},
170 sshConfigKeys: []string{"custom-private-key-2"},
171 wantKeyPair: &ssh.KeyPair{PrivateKeyPath: "custom-private-key-2", PublicKeyPath: "custom-private-key-2.pub"},
172 wantShouldAddArg: true,
173 },
174 {
175 // 2 pairs, but only 1 has both public and private
176 sshDirFiles: []string{"custom-private-key", "custom-private-key-2", "custom-private-key-2.pub"},
177 sshConfigKeys: []string{"custom-private-key", "custom-private-key-2"},
178 wantKeyPair: &ssh.KeyPair{PrivateKeyPath: "custom-private-key-2", PublicKeyPath: "custom-private-key-2.pub"},

Callers

nothing calls this directly

Calls 10

NewContextForTestsFunction · 0.92
selectSSHKeysFunction · 0.85
JoinMethod · 0.80
ReplaceMethod · 0.80
BaseMethod · 0.80
ContainsMethod · 0.80
CreateMethod · 0.65
ErrorfMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected