Skip to content

Commit

Permalink
internal: add tests for isDirectPathEnabled
Browse files Browse the repository at this point in the history
Change-Id: I67ab9d4b353aef8e6ebbfaaa7567b472d1387a31
Reviewed-on: https://code-review.googlesource.com/c/google-api-go-client/+/41691
Reviewed-by: kokoro <[email protected]>
Reviewed-by: Chris Broadfoot <[email protected]>
  • Loading branch information
jeanbza committed Jun 6, 2019
1 parent ba71ec0 commit 2dd36e4
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions transport/grpc/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"errors"
"net"
"os"
"testing"
"time"

Expand Down Expand Up @@ -64,3 +65,65 @@ func TestGRPCHook(t *testing.T) {
t.Error("expected a call to expected dialer, didn't get one")
}
}

func TestIsDirectPathEnabled(t *testing.T) {
for _, testcase := range []struct {
name string
endpoint string
envVar string
want bool
}{
{
name: "matches",
endpoint: "some-api",
envVar: "some-api",
want: true,
},
{
name: "does not match",
endpoint: "some-api",
envVar: "some-other-api",
want: false,
},
{
name: "matches in list",
endpoint: "some-api-2",
envVar: "some-api-1,some-api-2,some-api-3",
want: true,
},
{
name: "empty env var",
endpoint: "",
envVar: "",
want: false,
},
{
name: "trailing comma",
endpoint: "",
envVar: "foo,bar,",
want: false,
},
{
name: "dns schemes are allowed",
endpoint: "dns:///foo",
envVar: "dns:///foo",
want: true,
},
{
name: "non-dns schemes are disallowed",
endpoint: "https://foo",
envVar: "https://foo",
want: false,
},
} {
t.Run(testcase.name, func(t *testing.T) {
if err := os.Setenv("GOOGLE_CLOUD_ENABLE_DIRECT_PATH", testcase.envVar); err != nil {
t.Fatal(err)
}

if got := isDirectPathEnabled(testcase.endpoint); got != testcase.want {
t.Fatalf("got %v, want %v", got, testcase.want)
}
})
}
}

0 comments on commit 2dd36e4

Please sign in to comment.