Skip to content

Commit

Permalink
test(compute): add headers test (#4933)
Browse files Browse the repository at this point in the history
* tests: add headers test

* tests: names

* review comments
  • Loading branch information
georgiyekkert committed Oct 1, 2021
1 parent 1f3d71b commit 43a566f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions compute/apiv1/smoke_test.go
Expand Up @@ -19,9 +19,14 @@ package compute
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"

"google.golang.org/api/option"

"cloud.google.com/go/internal"
"github.com/googleapis/gax-go/v2"

Expand Down Expand Up @@ -593,3 +598,35 @@ func TestCapitalLetter(t *testing.T) {
t.Fatalf("got(-),want(+):\n%s", diff)
}
}

func TestHeaders(t *testing.T) {
ctx := context.Background()

svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
contentType := r.Header.Get("Content-Type")
xGoog := r.Header.Get("X-Goog-Api-Client")
if contentType != "application/json" {
t.Fatalf("Content-Type header was %s, expected `application/json`.", contentType)
}
if !strings.Contains(xGoog, "rest/") {
t.Fatal("X-Goog-Api-Client header doesn't contain `rest/`")
}
}))
defer svr.Close()
opts := []option.ClientOption{
option.WithEndpoint(svr.URL),
option.WithoutAuthentication(),
}
c, err := NewAcceleratorTypesRESTClient(ctx, opts...)
if err != nil {
t.Fatal(err)
}
_, err = c.Get(ctx, &computepb.GetAcceleratorTypeRequest{
AcceleratorType: "test",
Project: "test",
Zone: "test",
})
if err != nil {
return
}
}

0 comments on commit 43a566f

Please sign in to comment.