diff --git a/.travis.yml b/.travis.yml index 0ff8cd68..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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e6ddb29..5a29b807 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased +- [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. diff --git a/README.md b/README.md index b3ddcdf5..364aab9c 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ Admin Go SDK enables access to Firebase services from privileged environments (such as servers or cloud) in Go. Currently this SDK provides Firebase custom authentication support. +Go versions >= 1.6 are supported. + For more information, visit the [Firebase Admin SDK setup guide](https://firebase.google.com/docs/admin/setup/). diff --git a/auth/auth.go b/auth/auth.go index dbb42fd2..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" 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 0c1af368..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" ) diff --git a/auth/user_mgt_test.go b/auth/user_mgt_test.go index fedb0baf..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" diff --git a/firebase.go b/firebase.go index 0e34c058..2e0291ec 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" diff --git a/firebase_test.go b/firebase_test.go index 4781b378..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" @@ -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 6a5aeb04..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" @@ -52,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) } } 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 aaeeee5c..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" ) diff --git a/messaging/messaging_test.go b/messaging/messaging_test.go index 4bf9d89c..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) + } } } @@ -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 fc9bd852..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" 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"