MCPcopy
hub / github.com/dagger/container-use / TestRepositoryOpen

Function TestRepositoryOpen

repository/repository_test.go:15–68  ·  view source on GitHub ↗

TestRepositoryOpen tests the Open function which initializes a Repository

(t *testing.T)

Source from the content-addressed store, hash-verified

13
14// TestRepositoryOpen tests the Open function which initializes a Repository
15func TestRepositoryOpen(t *testing.T) {
16 ctx := context.Background()
17
18 t.Run("not_a_git_repository", func(t *testing.T) {
19 tempDir := t.TempDir()
20 _, err := Open(ctx, tempDir)
21 assert.Error(t, err)
22 assert.Contains(t, err.Error(), "you must be in a git repository")
23 })
24
25 t.Run("valid_git_repository", func(t *testing.T) {
26 tempDir := t.TempDir()
27 configDir := t.TempDir() // Separate dir for container-use config
28
29 // Initialize a git repo
30 _, err := RunGitCommand(ctx, tempDir, "init")
31 require.NoError(t, err)
32
33 // Set git config
34 _, err = RunGitCommand(ctx, tempDir, "config", "user.email", "test@example.com")
35 require.NoError(t, err)
36 _, err = RunGitCommand(ctx, tempDir, "config", "user.name", "Test User")
37 require.NoError(t, err)
38
39 // Make initial commit
40 testFile := filepath.Join(tempDir, "README.md")
41 err = os.WriteFile(testFile, []byte("# Test"), 0644)
42 require.NoError(t, err)
43
44 _, err = RunGitCommand(ctx, tempDir, "add", ".")
45 require.NoError(t, err)
46 _, err = RunGitCommand(ctx, tempDir, "commit", "-m", "Initial commit")
47 require.NoError(t, err)
48
49 // Open repository with isolated base path
50 repo, err := OpenWithBasePath(ctx, tempDir, configDir)
51 require.NoError(t, err)
52 assert.NotNil(t, repo)
53 // Git resolves symlinks, so repo.userRepoPath will be the canonical path
54 // This is correct behavior - we should store what git reports
55 assert.NotEmpty(t, repo.userRepoPath)
56 assert.DirExists(t, repo.userRepoPath)
57 assert.NotEmpty(t, repo.forkRepoPath)
58
59 // Verify fork was created
60 _, err = os.Stat(repo.forkRepoPath)
61 assert.NoError(t, err)
62
63 // Verify remote was added
64 remote, err := RunGitCommand(ctx, tempDir, "remote", "get-url", "container-use")
65 require.NoError(t, err)
66 assert.Equal(t, repo.forkRepoPath, strings.TrimSpace(remote))
67 })
68}

Callers

nothing calls this directly

Calls 4

OpenFunction · 0.85
RunGitCommandFunction · 0.85
OpenWithBasePathFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected