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

Function TestRepositoryMerge

environment/integration/merge_test.go:17–62  ·  view source on GitHub ↗

TestRepositoryMerge tests merging an environment into the main branch

(t *testing.T)

Source from the content-addressed store, hash-verified

15
16// TestRepositoryMerge tests merging an environment into the main branch
17func TestRepositoryMerge(t *testing.T) {
18 t.Parallel()
19 WithRepository(t, "repository-merge", SetupEmptyRepo, func(t *testing.T, repo *repository.Repository, user *UserActions) {
20 ctx := context.Background()
21
22 // Create an environment and add some content
23 env := user.CreateEnvironment("Test Merge", "Testing repository merge")
24 user.FileWrite(env.ID, "merge-test.txt", "content from environment", "Add merge test file")
25 user.FileWrite(env.ID, "config.json", `{"version": "1.0"}`, "Add config file")
26
27 // Get initial branch
28 initialBranch, err := repository.RunGitCommand(ctx, repo.SourcePath(), "branch", "--show-current")
29 require.NoError(t, err)
30 initialBranch = strings.TrimSpace(initialBranch)
31
32 // Merge the environment (without squash)
33 var mergeOutput bytes.Buffer
34 err = repo.Merge(ctx, env.ID, &mergeOutput)
35 require.NoError(t, err, "Merge should succeed: %s", mergeOutput.String())
36
37 // Verify we're still on the initial branch
38 currentBranch, err := repository.RunGitCommand(ctx, repo.SourcePath(), "branch", "--show-current")
39 require.NoError(t, err)
40 assert.Equal(t, initialBranch, strings.TrimSpace(currentBranch))
41
42 // Verify the files were merged into the working directory
43 mergeTestPath := filepath.Join(repo.SourcePath(), "merge-test.txt")
44 content, err := os.ReadFile(mergeTestPath)
45 require.NoError(t, err)
46 assert.Equal(t, "content from environment", string(content))
47
48 configPath := filepath.Join(repo.SourcePath(), "config.json")
49 configContent, err := os.ReadFile(configPath)
50 require.NoError(t, err)
51 assert.Equal(t, `{"version": "1.0"}`, string(configContent))
52
53 // Verify commit history includes the environment changes
54 log, err := repository.RunGitCommand(ctx, repo.SourcePath(), "log", "--oneline", "-10")
55 require.NoError(t, err)
56 // The merge might be fast-forward, so check for either merge commit or environment commits
57 assert.True(t,
58 strings.Contains(log, "Merge environment "+env.ID) ||
59 (strings.Contains(log, "Add merge test file") && strings.Contains(log, "Add config file")),
60 "Log should contain merge commit or environment commits: %s", log)
61 })
62}
63
64// TestRepositoryApply tests applying an environment as staged changes (equivalent to merge --squash)
65func TestRepositoryApply(t *testing.T) {

Callers

nothing calls this directly

Calls 7

RunGitCommandFunction · 0.92
WithRepositoryFunction · 0.85
SourcePathMethod · 0.80
MergeMethod · 0.80
CreateEnvironmentMethod · 0.45
FileWriteMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected