Skip to content

Commit 43a566f

Browse files
test(compute): add headers test (#4933)
* tests: add headers test * tests: names * review comments
1 parent 1f3d71b commit 43a566f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

compute/apiv1/smoke_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ package compute
1919
import (
2020
"context"
2121
"fmt"
22+
"net/http"
23+
"net/http/httptest"
24+
"strings"
2225
"testing"
2326
"time"
2427

28+
"google.golang.org/api/option"
29+
2530
"cloud.google.com/go/internal"
2631
"github.com/googleapis/gax-go/v2"
2732

@@ -593,3 +598,35 @@ func TestCapitalLetter(t *testing.T) {
593598
t.Fatalf("got(-),want(+):\n%s", diff)
594599
}
595600
}
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

Comments
 (0)