Skip to content

Commit

Permalink
blob/gcsblob: add more URL opener tests
Browse files Browse the repository at this point in the history
Suggested by @vangent in google#1359
  • Loading branch information
zombiezen committed Feb 20, 2019
1 parent 6838e15 commit a75e83d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion blob/gcsblob/gcsblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,38 @@ func TestURLOpenerForParams(t *testing.T) {

tests := []struct {
name string
currOpts Options
query url.Values
wantOpts Options
wantErr bool
}{
{
name: "InvalidParam",
query: url.Values{
"foo": {"bar"},
},
wantErr: true,
},
{
name: "AccessID",
query: url.Values{
"access_id": {"bar"},
},
wantOpts: Options{GoogleAccessID: "bar"},
},
{
name: "AccessID override",
currOpts: Options{GoogleAccessID: "foo"},
query: url.Values{
"access_id": {"bar"},
},
wantOpts: Options{GoogleAccessID: "bar"},
},
{
name: "AccessID not overridden",
currOpts: Options{GoogleAccessID: "bar"},
wantOpts: Options{GoogleAccessID: "bar"},
},
{
name: "BadPrivateKeyPath",
query: url.Values{
Expand All @@ -322,7 +343,8 @@ func TestURLOpenerForParams(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := new(URLOpener).forParams(ctx, test.query)
o := &URLOpener{Options: test.currOpts}
got, err := o.forParams(ctx, test.query)
if (err != nil) != test.wantErr {
t.Errorf("got err %v want error %v", err, test.wantErr)
}
Expand Down

0 comments on commit a75e83d

Please sign in to comment.