MCPcopy Create free account
hub / github.com/coder/envbuilder / TestCloneRepoSSH

Function TestCloneRepoSSH

git/git_test.go:259–350  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

257}
258
259func TestCloneRepoSSH(t *testing.T) {
260 t.Parallel()
261
262 t.Run("Success", func(t *testing.T) {
263 t.Parallel()
264
265 tmpDir := t.TempDir()
266 srvFS := osfs.New(tmpDir, osfs.WithChrootOS())
267
268 _ = gittest.NewRepo(t, srvFS, gittest.Commit(t, "README.md", "Hello, world!", "Wow!"))
269 key := randKeygen(t)
270 tr := gittest.NewServerSSH(t, srvFS, key.PublicKey())
271 gitURL := tr.String()
272 clientFS := memfs.New()
273
274 cloned, err := git.CloneRepo(context.Background(), t.Logf, git.CloneRepoOptions{
275 Path: "/workspace",
276 RepoURL: gitURL,
277 Storage: clientFS,
278 RepoAuth: &gitssh.PublicKeys{
279 User: "",
280 Signer: key,
281 HostKeyCallbackHelper: gitssh.HostKeyCallbackHelper{
282 // Not testing host keys here.
283 HostKeyCallback: gossh.InsecureIgnoreHostKey(),
284 },
285 },
286 })
287 require.NoError(t, err)
288 require.True(t, cloned)
289 require.Equal(t, "Hello, world!", mustRead(t, clientFS, "/workspace/README.md"))
290 })
291
292 t.Run("AuthFailure", func(t *testing.T) {
293 t.Parallel()
294
295 tmpDir := t.TempDir()
296 srvFS := osfs.New(tmpDir, osfs.WithChrootOS())
297
298 _ = gittest.NewRepo(t, srvFS, gittest.Commit(t, "README.md", "Hello, world!", "Wow!"))
299 key := randKeygen(t)
300 tr := gittest.NewServerSSH(t, srvFS, key.PublicKey())
301 gitURL := tr.String()
302 clientFS := memfs.New()
303
304 anotherKey := randKeygen(t)
305 cloned, err := git.CloneRepo(context.Background(), t.Logf, git.CloneRepoOptions{
306 Path: "/workspace",
307 RepoURL: gitURL,
308 Storage: clientFS,
309 RepoAuth: &gitssh.PublicKeys{
310 User: "",
311 Signer: anotherKey,
312 HostKeyCallbackHelper: gitssh.HostKeyCallbackHelper{
313 // Not testing host keys here.
314 HostKeyCallback: gossh.InsecureIgnoreHostKey(),
315 },
316 },

Callers

nothing calls this directly

Calls 6

NewRepoFunction · 0.92
CommitFunction · 0.92
NewServerSSHFunction · 0.92
CloneRepoFunction · 0.92
randKeygenFunction · 0.85
mustReadFunction · 0.85

Tested by

no test coverage detected