MCPcopy Index your code
hub / github.com/cli/cli / TestSelectSSHKeys

Function TestSelectSSHKeys

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected