@@ -14,6 +14,7 @@ import (
14
14
"io"
15
15
"net/http"
16
16
"net/http/httptest"
17
+ "os"
17
18
"testing"
18
19
"time"
19
20
@@ -23,6 +24,7 @@ import (
23
24
"golang.org/x/build/internal/coordinator/remote"
24
25
"golang.org/x/build/internal/coordinator/schedule"
25
26
"golang.org/x/build/internal/gomote/protos"
27
+ "golang.org/x/build/internal/swarmclient"
26
28
"golang.org/x/crypto/ssh"
27
29
"golang.org/x/net/nettest"
28
30
"google.golang.org/grpc"
@@ -33,7 +35,7 @@ import (
33
35
34
36
const testBucketName = "unit-testing-bucket"
35
37
36
- func fakeGomoteServer (t * testing.T , ctx context.Context ) protos.GomoteServiceServer {
38
+ func fakeGomoteServer (t * testing.T , ctx context.Context , configClient * swarmclient. ConfigClient ) protos.GomoteServiceServer {
37
39
signer , err := ssh .ParsePrivateKey ([]byte (devCertCAPrivate ))
38
40
if err != nil {
39
41
t .Fatalf ("unable to parse raw certificate authority private key into signer=%s" , err )
@@ -44,17 +46,25 @@ func fakeGomoteServer(t *testing.T, ctx context.Context) protos.GomoteServiceSer
44
46
gceBucketName : testBucketName ,
45
47
scheduler : schedule .NewFake (),
46
48
sshCertificateAuthority : signer ,
49
+ luciConfigClient : configClient ,
47
50
}
48
51
}
49
52
50
53
func setupGomoteTest (t * testing.T , ctx context.Context ) protos.GomoteServiceClient {
54
+ contents , err := os .ReadFile ("../swarmclient/testdata/bb-sample.cfg" )
55
+ if err != nil {
56
+ t .Fatalf ("unable to read test buildbucket config: %s" , err )
57
+ }
58
+ configClient := swarmclient .NewMemoryConfigClient (ctx , []* swarmclient.ConfigEntry {
59
+ & swarmclient.ConfigEntry {"cr-buildbucket.cfg" , contents },
60
+ })
51
61
lis , err := nettest .NewLocalListener ("tcp" )
52
62
if err != nil {
53
63
t .Fatalf ("unable to create net listener: %s" , err )
54
64
}
55
65
sopts := access .FakeIAPAuthInterceptorOptions ()
56
66
s := grpc .NewServer (sopts ... )
57
- protos .RegisterGomoteServiceServer (s , fakeGomoteServer (t , ctx ))
67
+ protos .RegisterGomoteServiceServer (s , fakeGomoteServer (t , ctx , configClient ))
58
68
go s .Serve (lis )
59
69
60
70
// create GRPC client
@@ -415,6 +425,31 @@ func TestListInstance(t *testing.T) {
415
425
}
416
426
}
417
427
428
+ func TestListSwarmingBuilders (t * testing.T ) {
429
+ client := setupGomoteTest (t , context .Background ())
430
+ ctx := access .FakeContextWithOutgoingIAPAuth (context .Background (), fakeIAP ())
431
+ response , err := client .ListSwarmingBuilders (ctx , & protos.ListSwarmingBuildersRequest {})
432
+ if err != nil {
433
+ t .Fatalf ("client.ListSwarmingBuilders = nil, %s; want no error" , err )
434
+ }
435
+ got := response .GetBuilders ()
436
+ if diff := cmp .Diff ([]string {"gotip-linux-amd64-boringcrypto" }, got ); diff != "" {
437
+ t .Errorf ("ListBuilders() mismatch (-want, +got):\n %s" , diff )
438
+ }
439
+ }
440
+
441
+ func TestListSwarmingBuildersError (t * testing.T ) {
442
+ client := setupGomoteTest (t , context .Background ())
443
+ req := & protos.ListSwarmingBuildersRequest {}
444
+ got , err := client .ListSwarmingBuilders (context .Background (), req )
445
+ if err != nil && status .Code (err ) != codes .Unauthenticated {
446
+ t .Fatalf ("unexpected error: %s; want %s" , err , codes .Unauthenticated )
447
+ }
448
+ if err == nil {
449
+ t .Fatalf ("client.ListSwarmingBuilder(ctx, %v) = %v, nil; want error" , req , got )
450
+ }
451
+ }
452
+
418
453
func TestDestroyInstance (t * testing.T ) {
419
454
ctx := access .FakeContextWithOutgoingIAPAuth (context .Background (), fakeIAP ())
420
455
client := setupGomoteTest (t , context .Background ())
0 commit comments