@@ -19,9 +19,14 @@ package compute
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "net/http"
23
+ "net/http/httptest"
24
+ "strings"
22
25
"testing"
23
26
"time"
24
27
28
+ "google.golang.org/api/option"
29
+
25
30
"cloud.google.com/go/internal"
26
31
"github.com/googleapis/gax-go/v2"
27
32
@@ -593,3 +598,35 @@ func TestCapitalLetter(t *testing.T) {
593
598
t .Fatalf ("got(-),want(+):\n %s" , diff )
594
599
}
595
600
}
601
+
602
+ func TestHeaders (t * testing.T ) {
603
+ ctx := context .Background ()
604
+
605
+ svr := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
606
+ contentType := r .Header .Get ("Content-Type" )
607
+ xGoog := r .Header .Get ("X-Goog-Api-Client" )
608
+ if contentType != "application/json" {
609
+ t .Fatalf ("Content-Type header was %s, expected `application/json`." , contentType )
610
+ }
611
+ if ! strings .Contains (xGoog , "rest/" ) {
612
+ t .Fatal ("X-Goog-Api-Client header doesn't contain `rest/`" )
613
+ }
614
+ }))
615
+ defer svr .Close ()
616
+ opts := []option.ClientOption {
617
+ option .WithEndpoint (svr .URL ),
618
+ option .WithoutAuthentication (),
619
+ }
620
+ c , err := NewAcceleratorTypesRESTClient (ctx , opts ... )
621
+ if err != nil {
622
+ t .Fatal (err )
623
+ }
624
+ _ , err = c .Get (ctx , & computepb.GetAcceleratorTypeRequest {
625
+ AcceleratorType : "test" ,
626
+ Project : "test" ,
627
+ Zone : "test" ,
628
+ })
629
+ if err != nil {
630
+ return
631
+ }
632
+ }
0 commit comments