Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 553d9b3

Browse files
committed
Clone a different depot in fusion test
1 parent cc7bd73 commit 553d9b3

File tree

2 files changed

+48
-36
lines changed

2 files changed

+48
-36
lines changed

dev/gqltest/external_service_test.go

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
"github.com/google/go-cmp/cmp"
9+
"github.com/stretchr/testify/assert"
910

1011
"github.com/sourcegraph/sourcegraph/internal/extsvc"
1112
"github.com/sourcegraph/sourcegraph/internal/gqltestutil"
@@ -161,39 +162,47 @@ func TestExternalService_BitbucketServer(t *testing.T) {
161162
}
162163

163164
func TestExternalService_Perforce(t *testing.T) {
164-
const repoName = "perforce/test-perms"
165-
166-
run := func(t *testing.T, useFusion bool) {
167-
checkPerforceEnvironment(t)
168-
// Make sure the repo wasn't already cloned by another test
169-
if err := client.DeleteRepoFromDiskByName(repoName); err != nil {
170-
t.Fatal(err)
171-
}
172-
createPerforceExternalService(t, useFusion)
173-
174-
err := client.WaitForReposToBeCloned(repoName)
175-
if err != nil {
176-
t.Fatal(err)
177-
}
178-
179-
blob, err := client.GitBlob(repoName, "master", "README.md")
180-
if err != nil {
181-
t.Fatal(err)
182-
}
183-
184-
wantBlob := `This depot is used to test user and group permissions.
185-
`
186-
if diff := cmp.Diff(wantBlob, blob); diff != "" {
187-
t.Fatalf("Blob mismatch (-want +got):\n%s", diff)
188-
}
165+
for _, tc := range []struct {
166+
name string
167+
depot string
168+
useFusion bool
169+
blobPath string
170+
wantBlob string
171+
}{
172+
{
173+
name: "git p4",
174+
depot: "test-perms",
175+
useFusion: false,
176+
blobPath: "README.md",
177+
wantBlob: `This depot is used to test user and group permissions.
178+
`,
179+
},
180+
{
181+
name: "p4 fusion",
182+
depot: "michelle-test",
183+
useFusion: true,
184+
blobPath: "main.go",
185+
wantBlob: "package main\n\nimport \"fmt\"\nfunc main() {\n\tfmt.Println(\"hello\")\n}\n",
186+
},
187+
} {
188+
t.Run(tc.name, func(t *testing.T) {
189+
repoName := "perforce/" + tc.depot
190+
checkPerforceEnvironment(t)
191+
createPerforceExternalService(t, tc.depot, tc.useFusion)
192+
193+
err := client.WaitForReposToBeCloned(repoName)
194+
if err != nil {
195+
t.Fatal(err)
196+
}
197+
198+
blob, err := client.GitBlob(repoName, "master", tc.blobPath)
199+
if err != nil {
200+
t.Fatal(err)
201+
}
202+
203+
assert.Equal(t, tc.wantBlob, blob)
204+
})
189205
}
190-
191-
t.Run("git-p4", func(t *testing.T) {
192-
run(t, false)
193-
})
194-
t.Run("p4-fusion", func(t *testing.T) {
195-
run(t, true)
196-
})
197206
}
198207

199208
func checkPerforceEnvironment(t *testing.T) {
@@ -202,7 +211,9 @@ func checkPerforceEnvironment(t *testing.T) {
202211
}
203212
}
204213

205-
func createPerforceExternalService(t *testing.T, useP4Fusion bool) {
214+
// createPerforceExternalService creates an Perforce external service that
215+
// includes the supplied depot.
216+
func createPerforceExternalService(t *testing.T, depot string, useP4Fusion bool) {
206217
t.Helper()
207218

208219
type Authorization = struct {
@@ -229,7 +240,7 @@ func createPerforceExternalService(t *testing.T, useP4Fusion bool) {
229240
P4Port: *perforcePort,
230241
P4User: *perforceUser,
231242
P4Password: *perforcePassword,
232-
Depots: []string{"//test-perms/"},
243+
Depots: []string{"//" + depot + "/"},
233244
RepositoryPathPattern: "perforce/{depot}",
234245
FusionClient: FusionClient{
235246
Enabled: useP4Fusion,

dev/gqltest/sub_repo_permissions_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ import (
1515

1616
const (
1717
perforceRepoName = "perforce/test-perms"
18+
testPermsDepot = "test-perms"
1819
aliceEmail = "[email protected]"
1920
aliceUsername = "alice"
2021
)
2122

2223
func TestSubRepoPermissionsPerforce(t *testing.T) {
2324
checkPerforceEnvironment(t)
2425
enableSubRepoPermissions(t)
25-
createPerforceExternalService(t, false)
26+
createPerforceExternalService(t, testPermsDepot, false)
2627
userClient, repoName := createTestUserAndWaitForRepo(t)
2728

2829
// Test cases
@@ -81,7 +82,7 @@ func TestSubRepoPermissionsPerforce(t *testing.T) {
8182
func TestSubRepoPermissionsSearch(t *testing.T) {
8283
checkPerforceEnvironment(t)
8384
enableSubRepoPermissions(t)
84-
createPerforceExternalService(t, false)
85+
createPerforceExternalService(t, testPermsDepot, false)
8586
userClient, _ := createTestUserAndWaitForRepo(t)
8687

8788
err := client.WaitForReposToBeIndexed(perforceRepoName)

0 commit comments

Comments
 (0)