|
1 | 1 | package integration |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "context" |
5 | 6 | "os" |
6 | 7 | "strings" |
@@ -126,3 +127,72 @@ func TestRepositoryCheckout(t *testing.T) { |
126 | 127 | "Expected branch to be %s or cu-%s, got %s", env.ID, env.ID, actualBranch) |
127 | 128 | }) |
128 | 129 | } |
| 130 | + |
| 131 | +// TestRepositoryLog tests retrieving commit history for an environment |
| 132 | +func TestRepositoryLog(t *testing.T) { |
| 133 | + t.Parallel() |
| 134 | + WithRepository(t, "repository-log", SetupEmptyRepo, func(t *testing.T, repo *repository.Repository, user *UserActions) { |
| 135 | + ctx := context.Background() |
| 136 | + |
| 137 | + // Create an environment and add some commits |
| 138 | + env := user.CreateEnvironment("Test Log", "Testing repository log") |
| 139 | + user.FileWrite(env.ID, "file1.txt", "initial content", "Initial commit") |
| 140 | + user.FileWrite(env.ID, "file1.txt", "updated content", "Update file") |
| 141 | + user.FileWrite(env.ID, "file2.txt", "new file", "Add second file") |
| 142 | + |
| 143 | + // Get commit log without patches |
| 144 | + var logBuf bytes.Buffer |
| 145 | + err := repo.Log(ctx, env.ID, false, &logBuf) |
| 146 | + logOutput := logBuf.String() |
| 147 | + require.NoError(t, err, logOutput) |
| 148 | + |
| 149 | + // Verify commit messages are present |
| 150 | + assert.Contains(t, logOutput, "Add second file") |
| 151 | + assert.Contains(t, logOutput, "Update file") |
| 152 | + assert.Contains(t, logOutput, "Initial commit") |
| 153 | + |
| 154 | + // Get commit log with patches |
| 155 | + logBuf.Reset() |
| 156 | + err = repo.Log(ctx, env.ID, true, &logBuf) |
| 157 | + logWithPatchOutput := logBuf.String() |
| 158 | + require.NoError(t, err, logWithPatchOutput) |
| 159 | + |
| 160 | + // Verify patch information is included |
| 161 | + assert.Contains(t, logWithPatchOutput, "diff --git") |
| 162 | + assert.Contains(t, logWithPatchOutput, "+updated content") |
| 163 | + |
| 164 | + // Test log for non-existent environment |
| 165 | + err = repo.Log(ctx, "non-existent-env", false, &logBuf) |
| 166 | + assert.Error(t, err) |
| 167 | + }) |
| 168 | +} |
| 169 | + |
| 170 | +// TestRepositoryDiff tests retrieving changes between commits |
| 171 | +func TestRepositoryDiff(t *testing.T) { |
| 172 | + t.Parallel() |
| 173 | + WithRepository(t, "repository-diff", SetupEmptyRepo, func(t *testing.T, repo *repository.Repository, user *UserActions) { |
| 174 | + ctx := context.Background() |
| 175 | + |
| 176 | + // Create an environment and make some changes |
| 177 | + env := user.CreateEnvironment("Test Diff", "Testing repository diff") |
| 178 | + |
| 179 | + // First commit - add a file |
| 180 | + user.FileWrite(env.ID, "test.txt", "initial content\n", "Initial commit") |
| 181 | + |
| 182 | + // Make changes to the file |
| 183 | + user.FileWrite(env.ID, "test.txt", "initial content\nupdated content\n", "Update file") |
| 184 | + |
| 185 | + // Get diff output |
| 186 | + var diffBuf bytes.Buffer |
| 187 | + err := repo.Diff(ctx, env.ID, &diffBuf) |
| 188 | + diffOutput := diffBuf.String() |
| 189 | + require.NoError(t, err, diffOutput) |
| 190 | + |
| 191 | + // Verify diff contains expected changes |
| 192 | + assert.Contains(t, diffOutput, "+updated content") |
| 193 | + |
| 194 | + // Test diff with non-existent environment |
| 195 | + err = repo.Diff(ctx, "non-existent-env", &diffBuf) |
| 196 | + assert.Error(t, err) |
| 197 | + }) |
| 198 | +} |
0 commit comments