diff --git a/.travis.gofmt.sh b/.travis.gofmt.sh new file mode 100755 index 00000000..e33451d7 --- /dev/null +++ b/.travis.gofmt.sh @@ -0,0 +1,6 @@ +#!/bin/bash +if [[ ! -z "$(gofmt -l -s .)" ]]; then + echo "Go code is not formatted:" + gofmt -d -s . + exit 1 +fi diff --git a/.travis.yml b/.travis.yml index 53f411b4..ab496972 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: go go: + - 1.6.x - 1.7.x - 1.8.x - 1.9.x @@ -26,5 +27,6 @@ install: script: - golint -set_exit_status $(go list ./...) + - ./.travis.gofmt.sh - go test -v -race -test.short ./... # Run tests with the race detector. - go vet -v ./... # Run Go static analyzer. diff --git a/CHANGELOG.md b/CHANGELOG.md index 5852ed27..893bb9ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # Unreleased -- +# v2.6.1 + +- [added] Added support for Go 1.6. +- [changed] Fixed a bug in the + [`UnsubscribeFromTopic()`](https://godoc.org/firebase.google.com/go/messaging#Client.UnsubscribeFromTopic) + function. +- [changed] Improved the error message returned by `GetUser()`, + `GetUserByEmail()` and `GetUserByPhoneNumber()` APIs in + [`auth`](https://godoc.org/firebase.google.com/go/auth) package. # v2.6.0 diff --git a/README.md b/README.md index 3ea293a2..e91d1188 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,13 @@ go get firebase.google.com/go Please refer to the [CONTRIBUTING page](./CONTRIBUTING.md) for more information about how you can contribute to this project. We welcome bug reports, feature -requests, code review feedback, and also pull requests. +requests, code review feedback, and also pull requests. +## Supported Go Versions + +We support Go v1.6 and higher. +[Continuous integration](https://travis-ci.org/firebase/firebase-admin-go) system +tests the code on Go v1.6 through v1.10. ## Documentation diff --git a/auth/auth.go b/auth/auth.go index 98822fef..2576165e 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -16,7 +16,6 @@ package auth import ( - "context" "crypto/rsa" "crypto/x509" "encoding/json" @@ -25,6 +24,8 @@ import ( "fmt" "strings" + "golang.org/x/net/context" + "firebase.google.com/go/internal" "google.golang.org/api/identitytoolkit/v3" "google.golang.org/api/transport" @@ -62,7 +63,6 @@ type Token struct { // Client facilitates generating custom JWT tokens for Firebase clients, and verifying ID tokens issued // by Firebase backend services. type Client struct { - hc *internal.HTTPClient is *identitytoolkit.Service ks keySource projectID string @@ -123,7 +123,6 @@ func NewClient(ctx context.Context, c *internal.AuthConfig) (*Client, error) { } return &Client{ - hc: &internal.HTTPClient{Client: hc}, is: is, ks: newHTTPKeySource(googleCertURL, hc), projectID: c.ProjectID, diff --git a/auth/auth_appengine.go b/auth/auth_appengine.go index 5e05cdb1..351f61c1 100644 --- a/auth/auth_appengine.go +++ b/auth/auth_appengine.go @@ -17,7 +17,7 @@ package auth import ( - "context" + "golang.org/x/net/context" "google.golang.org/appengine" ) diff --git a/auth/auth_std.go b/auth/auth_std.go index f593a7cc..2055af38 100644 --- a/auth/auth_std.go +++ b/auth/auth_std.go @@ -16,7 +16,7 @@ package auth -import "context" +import "golang.org/x/net/context" func newSigner(ctx context.Context) (signer, error) { return serviceAcctSigner{}, nil diff --git a/auth/auth_test.go b/auth/auth_test.go index 2676f6c4..6aea0d3a 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -15,7 +15,6 @@ package auth import ( - "context" "encoding/json" "errors" "fmt" @@ -26,6 +25,8 @@ import ( "testing" "time" + "golang.org/x/net/context" + "golang.org/x/oauth2/google" "google.golang.org/api/option" diff --git a/auth/user_mgt.go b/auth/user_mgt.go index 551753ea..e6d7386b 100644 --- a/auth/user_mgt.go +++ b/auth/user_mgt.go @@ -15,7 +15,6 @@ package auth import ( - "context" "encoding/json" "fmt" "net/http" @@ -24,6 +23,8 @@ import ( "strings" "time" + "golang.org/x/net/context" + "google.golang.org/api/identitytoolkit/v3" "google.golang.org/api/iterator" ) @@ -567,7 +568,7 @@ func (c *Client) getUser(ctx context.Context, request *identitytoolkit.Identityt return nil, err } if len(resp.Users) == 0 { - return nil, fmt.Errorf("cannot find user from params: %v", request) + return nil, fmt.Errorf("cannot find user given params: id:%v, phone:%v, email: %v", request.LocalId, request.PhoneNumber, request.Email) } eu, err := makeExportedUser(resp.Users[0]) diff --git a/auth/user_mgt_test.go b/auth/user_mgt_test.go index 3f298ed6..30072d4f 100644 --- a/auth/user_mgt_test.go +++ b/auth/user_mgt_test.go @@ -16,7 +16,6 @@ package auth import ( "bytes" - "context" "encoding/json" "fmt" "io/ioutil" @@ -27,6 +26,8 @@ import ( "testing" "time" + "golang.org/x/net/context" + "firebase.google.com/go/internal" "golang.org/x/oauth2" @@ -148,17 +149,24 @@ func TestGetNonExistingUser(t *testing.T) { s := echoServer([]byte(resp), t) defer s.Close() - user, err := s.Client.GetUser(context.Background(), "ignored_id") - if user != nil || err == nil { - t.Errorf("GetUser(non-existing) = (%v, %v); want = (nil, error)", user, err) + want := "cannot find user given params: id:[%s], phone:[%s], email: [%s]" + + we := fmt.Sprintf(want, "id-nonexisting", "", "") + user, err := s.Client.GetUser(context.Background(), "id-nonexisting") + if user != nil || err == nil || err.Error() != we { + t.Errorf("GetUser(non-existing) = (%v, %q); want = (nil, %q)", user, err, we) } - user, err = s.Client.GetUserByEmail(context.Background(), "test@email.com") - if user != nil || err == nil { - t.Errorf("GetUserByEmail(non-existing) = (%v, %v); want = (nil, error)", user, err) + + we = fmt.Sprintf(want, "", "", "foo@bar.nonexisting") + user, err = s.Client.GetUserByEmail(context.Background(), "foo@bar.nonexisting") + if user != nil || err == nil || err.Error() != we { + t.Errorf("GetUserByEmail(non-existing) = (%v, %q); want = (nil, %q)", user, err, we) } - user, err = s.Client.GetUserByPhoneNumber(context.Background(), "+1234567890") - if user != nil || err == nil { - t.Errorf("GetUserPhoneNumber(non-existing) = (%v, %v); want = (nil, error)", user, err) + + we = fmt.Sprintf(want, "", "+12345678901", "") + user, err = s.Client.GetUserByPhoneNumber(context.Background(), "+12345678901") + if user != nil || err == nil || err.Error() != we { + t.Errorf("GetUserPhoneNumber(non-existing) = (%v, %q); want = (nil, %q)", user, err, we) } } diff --git a/db/db_test.go b/db/db_test.go index 01234504..e811c9df 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -107,7 +107,7 @@ func TestNewClient(t *testing.T) { func TestNewClientAuthOverrides(t *testing.T) { cases := []map[string]interface{}{ nil, - map[string]interface{}{"uid": "user1"}, + {"uid": "user1"}, } for _, tc := range cases { c, err := NewClient(context.Background(), &internal.DatabaseConfig{ diff --git a/db/query.go b/db/query.go index c6013483..ca377c12 100644 --- a/db/query.go +++ b/db/query.go @@ -306,7 +306,7 @@ func (q *queryNodeImpl) Key() string { if q.CompKey.Str != nil { return *q.CompKey.Str } - // Numeric keys in queryNodeImpl are always array indices, and can be safely coverted into int. + // Numeric keys in queryNodeImpl are always array indices, and can be safely converted into int. return strconv.Itoa(int(*q.CompKey.Num)) } diff --git a/db/ref_test.go b/db/ref_test.go index 93e348d0..8c489467 100644 --- a/db/ref_test.go +++ b/db/ref_test.go @@ -265,12 +265,12 @@ func TestGetIfChanged(t *testing.T) { } checkAllRequests(t, mock.Reqs, []*testReq{ - &testReq{ + { Method: "GET", Path: "/peter.json", Header: http.Header{"If-None-Match": []string{"old-etag"}}, }, - &testReq{ + { Method: "GET", Path: "/peter.json", Header: http.Header{"If-None-Match": []string{"new-etag"}}, @@ -513,7 +513,7 @@ func TestInvalidUpdate(t *testing.T) { cases := []map[string]interface{}{ nil, make(map[string]interface{}), - map[string]interface{}{"foo": func() {}}, + {"foo": func() {}}, } for _, tc := range cases { if err := testref.Update(context.Background(), tc); err == nil { @@ -542,12 +542,12 @@ func TestTransaction(t *testing.T) { t.Fatal(err) } checkAllRequests(t, mock.Reqs, []*testReq{ - &testReq{ + { Method: "GET", Path: "/peter.json", Header: http.Header{"X-Firebase-ETag": []string{"true"}}, }, - &testReq{ + { Method: "PUT", Path: "/peter.json", Body: serialize(map[string]interface{}{ @@ -591,12 +591,12 @@ func TestTransactionRetry(t *testing.T) { t.Errorf("Transaction() retries = %d; want = %d", cnt, 2) } checkAllRequests(t, mock.Reqs, []*testReq{ - &testReq{ + { Method: "GET", Path: "/peter.json", Header: http.Header{"X-Firebase-ETag": []string{"true"}}, }, - &testReq{ + { Method: "PUT", Path: "/peter.json", Body: serialize(map[string]interface{}{ @@ -605,7 +605,7 @@ func TestTransactionRetry(t *testing.T) { }), Header: http.Header{"If-Match": []string{"mock-etag1"}}, }, - &testReq{ + { Method: "PUT", Path: "/peter.json", Body: serialize(map[string]interface{}{ @@ -650,12 +650,12 @@ func TestTransactionError(t *testing.T) { t.Errorf("Transaction() retries = %d; want = %d", cnt, 1) } checkAllRequests(t, mock.Reqs, []*testReq{ - &testReq{ + { Method: "GET", Path: "/peter.json", Header: http.Header{"X-Firebase-ETag": []string{"true"}}, }, - &testReq{ + { Method: "PUT", Path: "/peter.json", Body: serialize(map[string]interface{}{ @@ -694,7 +694,7 @@ func TestTransactionAbort(t *testing.T) { t.Errorf("Transaction() = nil; want error") } wanted := []*testReq{ - &testReq{ + { Method: "GET", Path: "/peter.json", Header: http.Header{"X-Firebase-ETag": []string{"true"}}, diff --git a/firebase.go b/firebase.go index 0e34c058..c341dfce 100644 --- a/firebase.go +++ b/firebase.go @@ -18,12 +18,13 @@ package firebase import ( - "context" "encoding/json" "errors" "io/ioutil" "os" + "golang.org/x/net/context" + "cloud.google.com/go/firestore" "firebase.google.com/go/auth" @@ -41,7 +42,7 @@ import ( var defaultAuthOverrides = make(map[string]interface{}) // Version of the Firebase Go Admin SDK. -const Version = "2.6.0" +const Version = "2.6.1" // firebaseEnvName is the name of the environment variable with the Config. const firebaseEnvName = "FIREBASE_CONFIG" diff --git a/firebase_test.go b/firebase_test.go index bbf1a4c3..8ba2b762 100644 --- a/firebase_test.go +++ b/firebase_test.go @@ -15,8 +15,6 @@ package firebase import ( - "context" - "fmt" "io/ioutil" "log" "net/http" @@ -28,6 +26,8 @@ import ( "testing" "time" + "golang.org/x/net/context" + "golang.org/x/oauth2/google" "google.golang.org/api/transport" @@ -247,8 +247,8 @@ func TestDatabase(t *testing.T) { func TestDatabaseAuthOverrides(t *testing.T) { cases := []map[string]interface{}{ nil, - map[string]interface{}{}, - map[string]interface{}{"uid": "user1"}, + {}, + {"uid": "user1"}, } for _, tc := range cases { ctx := context.Background() @@ -539,15 +539,13 @@ func TestAutoInit(t *testing.T) { defer reinstateEnv(credEnvVar, credOld) for _, test := range tests { - t.Run(fmt.Sprintf("NewApp(%s)", test.name), func(t *testing.T) { - overwriteEnv(firebaseEnvName, test.optionsConfig) - app, err := NewApp(context.Background(), test.initOptions) - if err != nil { - t.Error(err) - } else { - compareConfig(app, test.wantOptions, t) - } - }) + overwriteEnv(firebaseEnvName, test.optionsConfig) + app, err := NewApp(context.Background(), test.initOptions) + if err != nil { + t.Errorf("NewApp(%s): %v", test.name, err) + } else { + compareConfig(app, test.wantOptions, t) + } } } @@ -577,13 +575,11 @@ func TestAutoInitInvalidFiles(t *testing.T) { defer reinstateEnv(credEnvVar, credOld) for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - overwriteEnv(firebaseEnvName, test.filename) - _, err := NewApp(context.Background(), nil) - if err == nil || err.Error() != test.wantError { - t.Errorf("got error = %s; want = %s", err, test.wantError) - } - }) + overwriteEnv(firebaseEnvName, test.filename) + _, err := NewApp(context.Background(), nil) + if err == nil || err.Error() != test.wantError { + t.Errorf("%s got error = %s; want = %s", test.name, err, test.wantError) + } } } diff --git a/iid/iid.go b/iid/iid.go index b282db40..566833e6 100644 --- a/iid/iid.go +++ b/iid/iid.go @@ -16,11 +16,12 @@ package iid import ( - "context" "errors" "fmt" "net/http" + "golang.org/x/net/context" + "google.golang.org/api/transport" "firebase.google.com/go/internal" diff --git a/iid/iid_test.go b/iid/iid_test.go index b3e69638..4d0e33aa 100644 --- a/iid/iid_test.go +++ b/iid/iid_test.go @@ -15,12 +15,13 @@ package iid import ( - "context" "fmt" "net/http" "net/http/httptest" "testing" + "golang.org/x/net/context" + "google.golang.org/api/option" "firebase.google.com/go/internal" diff --git a/integration/auth/auth_test.go b/integration/auth/auth_test.go index 2b8d6bd6..b84ff126 100644 --- a/integration/auth/auth_test.go +++ b/integration/auth/auth_test.go @@ -17,7 +17,6 @@ package auth import ( "bytes" - "context" "encoding/json" "flag" "fmt" @@ -28,6 +27,8 @@ import ( "testing" "time" + "golang.org/x/net/context" + "firebase.google.com/go/auth" "firebase.google.com/go/integration/internal" ) diff --git a/integration/auth/user_mgt_test.go b/integration/auth/user_mgt_test.go index 4121d62c..dc9ceba0 100644 --- a/integration/auth/user_mgt_test.go +++ b/integration/auth/user_mgt_test.go @@ -16,12 +16,13 @@ package auth import ( - "context" "fmt" "reflect" "testing" "time" + "golang.org/x/net/context" + "google.golang.org/api/iterator" "firebase.google.com/go/auth" @@ -40,6 +41,8 @@ func TestUserManagement(t *testing.T) { }{ {"Create test users", testCreateUsers}, {"Get user", testGetUser}, + {"Get user by phone", testGetUserByPhoneNumber}, + {"Get user by email", testGetUserByEmail}, {"Iterate users", testUserIterator}, {"Paged iteration", testPager}, {"Disable user account", testDisableUser}, @@ -50,11 +53,10 @@ func TestUserManagement(t *testing.T) { {"Delete test users", testDeleteUsers}, } // The tests are meant to be run in sequence. A failure in creating the users - // should be fatal so non of the other tests run. However calling Fatal from a - // subtest does not prevent the other subtests from running, hence we check the - // success of each subtest before proceeding. + // should be fatal so none of the other tests run. for _, run := range orderedRuns { - if ok := t.Run(run.name, run.testFunc); !ok { + run.testFunc(t) + if t.Failed() { t.Fatalf("Failed run %v", run.name) } } @@ -96,7 +98,8 @@ func testCreateUsers(t *testing.T) { UID(uid). Email(uid + "email@test.com"). DisplayName("display_name"). - Password("password") + Password("password"). + PhoneNumber("+12223334444") if u, err = client.CreateUser(context.Background(), params); err != nil { t.Fatal(err) diff --git a/integration/db/db_test.go b/integration/db/db_test.go index 0754d5bf..e5f61f04 100644 --- a/integration/db/db_test.go +++ b/integration/db/db_test.go @@ -690,11 +690,11 @@ func protectedRef(t *testing.T, p string) string { } type Dinosaur struct { - Appeared int `json:"appeared"` + Appeared float64 `json:"appeared"` Height float64 `json:"height"` Length float64 `json:"length"` Order string `json:"order"` - Vanished int `json:"vanished"` + Vanished float64 `json:"vanished"` Weight int `json:"weight"` Ratings Ratings `json:"ratings"` } diff --git a/integration/firestore/firestore_test.go b/integration/firestore/firestore_test.go index 1b861d92..c89e68e6 100644 --- a/integration/firestore/firestore_test.go +++ b/integration/firestore/firestore_test.go @@ -15,11 +15,12 @@ package firestore import ( - "context" "log" "reflect" "testing" + "golang.org/x/net/context" + "firebase.google.com/go/integration/internal" ) diff --git a/integration/iid/iid_test.go b/integration/iid/iid_test.go index 2b1b1c9c..82ecd0ac 100644 --- a/integration/iid/iid_test.go +++ b/integration/iid/iid_test.go @@ -16,12 +16,13 @@ package iid import ( - "context" "flag" "log" "os" "testing" + "golang.org/x/net/context" + "firebase.google.com/go/iid" "firebase.google.com/go/integration/internal" ) diff --git a/integration/internal/internal.go b/integration/internal/internal.go index a5cd7af6..497065eb 100644 --- a/integration/internal/internal.go +++ b/integration/internal/internal.go @@ -16,7 +16,6 @@ package internal import ( - "context" "encoding/json" "go/build" "io/ioutil" @@ -24,6 +23,8 @@ import ( "path/filepath" "strings" + "golang.org/x/net/context" + firebase "firebase.google.com/go" "firebase.google.com/go/internal" "google.golang.org/api/option" diff --git a/integration/messaging/messaging_test.go b/integration/messaging/messaging_test.go index 4b8ef6d7..10818ddd 100644 --- a/integration/messaging/messaging_test.go +++ b/integration/messaging/messaging_test.go @@ -15,13 +15,14 @@ package messaging import ( - "context" "flag" "log" "os" "regexp" "testing" + "golang.org/x/net/context" + "firebase.google.com/go/integration/internal" "firebase.google.com/go/messaging" ) @@ -88,7 +89,7 @@ func TestSend(t *testing.T) { } name, err := client.SendDryRun(context.Background(), msg) if err != nil { - log.Fatalln(err) + t.Fatal(err) } const pattern = "^projects/.*/messages/.*$" if !regexp.MustCompile(pattern).MatchString(name) { diff --git a/integration/storage/storage_test.go b/integration/storage/storage_test.go index b5a205d5..c47b29a8 100644 --- a/integration/storage/storage_test.go +++ b/integration/storage/storage_test.go @@ -15,7 +15,6 @@ package storage import ( - "context" "flag" "fmt" "io/ioutil" @@ -23,6 +22,8 @@ import ( "os" "testing" + "golang.org/x/net/context" + "firebase.google.com/go" gcs "cloud.google.com/go/storage" diff --git a/internal/http_client.go b/internal/http_client.go index 984e8a1d..7f3df67a 100644 --- a/internal/http_client.go +++ b/internal/http_client.go @@ -16,12 +16,15 @@ package internal import ( "bytes" - "context" "encoding/json" "fmt" "io" "io/ioutil" "net/http" + + "golang.org/x/net/context/ctxhttp" + + "golang.org/x/net/context" ) // HTTPClient is a convenient API to make HTTP calls. @@ -43,7 +46,7 @@ func (c *HTTPClient) Do(ctx context.Context, r *Request) (*Response, error) { return nil, err } - resp, err := c.Client.Do(req.WithContext(ctx)) + resp, err := ctxhttp.Do(ctx, c.Client, req) if err != nil { return nil, err } diff --git a/internal/http_client_test.go b/internal/http_client_test.go index 14729d17..bdac7474 100644 --- a/internal/http_client_test.go +++ b/internal/http_client_test.go @@ -14,13 +14,14 @@ package internal import ( - "context" "encoding/json" "io/ioutil" "net/http" "net/http/httptest" "reflect" "testing" + + "golang.org/x/net/context" ) var cases = []struct { diff --git a/messaging/messaging.go b/messaging/messaging.go index 231e7212..fb6fa5dd 100644 --- a/messaging/messaging.go +++ b/messaging/messaging.go @@ -17,7 +17,6 @@ package messaging import ( - "context" "encoding/json" "errors" "fmt" @@ -26,6 +25,8 @@ import ( "strings" "time" + "golang.org/x/net/context" + "firebase.google.com/go/internal" "google.golang.org/api/transport" ) @@ -364,7 +365,7 @@ func (c *Client) UnsubscribeFromTopic(ctx context.Context, tokens []string, topi req := &iidRequest{ Topic: topic, Tokens: tokens, - op: iidSubscribe, + op: iidUnsubscribe, } return c.makeTopicManagementRequest(ctx, req) } diff --git a/messaging/messaging_test.go b/messaging/messaging_test.go index 79ef498b..1d6d3ad5 100644 --- a/messaging/messaging_test.go +++ b/messaging/messaging_test.go @@ -15,7 +15,6 @@ package messaging import ( - "context" "encoding/json" "io/ioutil" "net/http" @@ -25,6 +24,8 @@ import ( "testing" "time" + "golang.org/x/net/context" + "firebase.google.com/go/internal" "google.golang.org/api/option" ) @@ -565,13 +566,11 @@ func TestSend(t *testing.T) { client.fcmEndpoint = ts.URL for _, tc := range validMessages { - t.Run(tc.name, func(t *testing.T) { - name, err := client.Send(ctx, tc.req) - if name != testMessageID || err != nil { - t.Errorf("Send() = (%q, %v); want = (%q, nil)", name, err, testMessageID) - } - checkFCMRequest(t, b, tr, tc.want, false) - }) + name, err := client.Send(ctx, tc.req) + if name != testMessageID || err != nil { + t.Errorf("Send(%s) = (%q, %v); want = (%q, nil)", tc.name, name, err, testMessageID) + } + checkFCMRequest(t, b, tr, tc.want, false) } } @@ -594,13 +593,11 @@ func TestSendDryRun(t *testing.T) { client.fcmEndpoint = ts.URL for _, tc := range validMessages { - t.Run(tc.name, func(t *testing.T) { - name, err := client.SendDryRun(ctx, tc.req) - if name != testMessageID || err != nil { - t.Errorf("SendDryRun() = (%q, %v); want = (%q, nil)", name, err, testMessageID) - } - checkFCMRequest(t, b, tr, tc.want, true) - }) + name, err := client.SendDryRun(ctx, tc.req) + if name != testMessageID || err != nil { + t.Errorf("SendDryRun(%s) = (%q, %v); want = (%q, nil)", tc.name, name, err, testMessageID) + } + checkFCMRequest(t, b, tr, tc.want, true) } } @@ -657,12 +654,10 @@ func TestInvalidMessage(t *testing.T) { t.Fatal(err) } for _, tc := range invalidMessages { - t.Run(tc.name, func(t *testing.T) { - name, err := client.Send(ctx, tc.req) - if err == nil || err.Error() != tc.want { - t.Errorf("Send() = (%q, %v); want = (%q, %q)", name, err, "", tc.want) - } - }) + name, err := client.Send(ctx, tc.req) + if err == nil || err.Error() != tc.want { + t.Errorf("Send(%s) = (%q, %v); want = (%q, %q)", tc.name, name, err, "", tc.want) + } } } @@ -699,12 +694,10 @@ func TestInvalidSubscribe(t *testing.T) { t.Fatal(err) } for _, tc := range invalidTopicMgtArgs { - t.Run(tc.name, func(t *testing.T) { - name, err := client.SubscribeToTopic(ctx, tc.tokens, tc.topic) - if err == nil || err.Error() != tc.want { - t.Errorf("SubscribeToTopic() = (%q, %v); want = (%q, %q)", name, err, "", tc.want) - } - }) + name, err := client.SubscribeToTopic(ctx, tc.tokens, tc.topic) + if err == nil || err.Error() != tc.want { + t.Errorf("SubscribeToTopic(%s) = (%q, %v); want = (%q, %q)", tc.name, name, err, "", tc.want) + } } } @@ -730,7 +723,7 @@ func TestUnsubscribe(t *testing.T) { if err != nil { t.Fatal(err) } - checkIIDRequest(t, b, tr, iidSubscribe) + checkIIDRequest(t, b, tr, iidUnsubscribe) checkTopicMgtResponse(t, resp) } @@ -741,12 +734,10 @@ func TestInvalidUnsubscribe(t *testing.T) { t.Fatal(err) } for _, tc := range invalidTopicMgtArgs { - t.Run(tc.name, func(t *testing.T) { - name, err := client.UnsubscribeFromTopic(ctx, tc.tokens, tc.topic) - if err == nil || err.Error() != tc.want { - t.Errorf("UnsubscribeFromTopic() = (%q, %v); want = (%q, %q)", name, err, "", tc.want) - } - }) + name, err := client.UnsubscribeFromTopic(ctx, tc.tokens, tc.topic) + if err == nil || err.Error() != tc.want { + t.Errorf("UnsubscribeFromTopic(%s) = (%q, %v); want = (%q, %q)", tc.name, name, err, "", tc.want) + } } } diff --git a/snippets/auth.go b/snippets/auth.go index 9fb739ba..b80fa418 100644 --- a/snippets/auth.go +++ b/snippets/auth.go @@ -15,9 +15,10 @@ package snippets import ( - "context" "log" + "golang.org/x/net/context" + firebase "firebase.google.com/go" "firebase.google.com/go/auth" "google.golang.org/api/iterator" diff --git a/snippets/db.go b/snippets/db.go index 8e0bea71..c853e12a 100644 --- a/snippets/db.go +++ b/snippets/db.go @@ -16,10 +16,11 @@ package snippets // [START authenticate_db_imports] import ( - "context" "fmt" "log" + "golang.org/x/net/context" + "firebase.google.com/go/db" "firebase.google.com/go" @@ -153,11 +154,11 @@ func setValue(ctx context.Context, ref *db.Ref) { // [START set_value] usersRef := ref.Child("users") err := usersRef.Set(ctx, map[string]*User{ - "alanisawesome": &User{ + "alanisawesome": { DateOfBirth: "June 23, 1912", FullName: "Alan Turing", }, - "gracehop": &User{ + "gracehop": { DateOfBirth: "December 9, 1906", FullName: "Grace Hopper", }, diff --git a/snippets/init.go b/snippets/init.go index 8af16a12..2513ae9d 100644 --- a/snippets/init.go +++ b/snippets/init.go @@ -16,9 +16,10 @@ package snippets // [START admin_import_golang] import ( - "context" "log" + "golang.org/x/net/context" + firebase "firebase.google.com/go" "firebase.google.com/go/auth" diff --git a/snippets/messaging.go b/snippets/messaging.go index 18f6e462..b3ce67d4 100644 --- a/snippets/messaging.go +++ b/snippets/messaging.go @@ -15,11 +15,12 @@ package snippets import ( - "context" "fmt" "log" "time" + "golang.org/x/net/context" + "firebase.google.com/go" "firebase.google.com/go/messaging" ) diff --git a/snippets/storage.go b/snippets/storage.go index a39538a3..169d56e4 100644 --- a/snippets/storage.go +++ b/snippets/storage.go @@ -15,9 +15,10 @@ package snippets import ( - "context" "log" + "golang.org/x/net/context" + firebase "firebase.google.com/go" "google.golang.org/api/option" ) diff --git a/storage/storage.go b/storage/storage.go index 878e2175..dbcd1303 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -16,9 +16,10 @@ package storage import ( - "context" "errors" + "golang.org/x/net/context" + "cloud.google.com/go/storage" "firebase.google.com/go/internal" ) diff --git a/storage/storage_test.go b/storage/storage_test.go index 7a77e60c..eff97a1b 100644 --- a/storage/storage_test.go +++ b/storage/storage_test.go @@ -15,9 +15,10 @@ package storage import ( - "context" "testing" + "golang.org/x/net/context" + "google.golang.org/api/option" "firebase.google.com/go/internal"