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
163164func 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 \n import \" fmt\" \n func main() {\n \t fmt.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
199208func 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 ,
0 commit comments