From 5419adf86a1c496af793274cba2edb5934af9120 Mon Sep 17 00:00:00 2001 From: Tyler Bui-Palsulich Date: Fri, 9 Mar 2018 14:58:53 -0500 Subject: [PATCH 1/8] all: use golang.org/x/net/context --- auth/auth.go | 3 ++- auth/auth_appengine.go | 2 +- auth/auth_std.go | 2 +- auth/auth_test.go | 3 ++- auth/user_mgt.go | 3 ++- auth/user_mgt_test.go | 3 ++- firebase.go | 3 ++- firebase_test.go | 3 ++- iid/iid.go | 3 ++- iid/iid_test.go | 3 ++- integration/auth/auth_test.go | 3 ++- integration/auth/user_mgt_test.go | 3 ++- integration/firestore/firestore_test.go | 3 ++- integration/iid/iid_test.go | 3 ++- integration/internal/internal.go | 3 ++- integration/messaging/messaging_test.go | 3 ++- integration/storage/storage_test.go | 3 ++- internal/http_client.go | 3 ++- internal/http_client_test.go | 3 ++- messaging/messaging.go | 3 ++- messaging/messaging_test.go | 3 ++- snippets/auth.go | 3 ++- snippets/db.go | 3 ++- snippets/init.go | 3 ++- snippets/messaging.go | 3 ++- snippets/storage.go | 3 ++- storage/storage.go | 3 ++- storage/storage_test.go | 3 ++- 28 files changed, 54 insertions(+), 28 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 98822fef..bd2a208a 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 551753ea..00c23a4c 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 3f298ed6..08559921 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 bbf1a4c3..a14f6412 100644 --- a/firebase_test.go +++ b/firebase_test.go @@ -15,7 +15,6 @@ package firebase import ( - "context" "fmt" "io/ioutil" "log" @@ -28,6 +27,8 @@ import ( "testing" "time" + "golang.org/x/net/context" + "golang.org/x/oauth2/google" "google.golang.org/api/transport" 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..317f87e0 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" 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..b41bf87e 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" ) 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..bd40c366 100644 --- a/internal/http_client.go +++ b/internal/http_client.go @@ -16,12 +16,13 @@ package internal import ( "bytes" - "context" "encoding/json" "fmt" "io" "io/ioutil" "net/http" + + "golang.org/x/net/context" ) // HTTPClient is a convenient API to make HTTP calls. 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..9514082b 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 79ef498b..76fb531c 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" ) 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..2b3c8972 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" From df78231a00d588d5ecafd283c086ba2b8eb836a9 Mon Sep 17 00:00:00 2001 From: Tyler Bui-Palsulich Date: Fri, 9 Mar 2018 15:00:39 -0500 Subject: [PATCH 2/8] internal: use ctxhttp to use /x/ context The 1.6 Request type doesn't have WithContext. --- internal/http_client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/http_client.go b/internal/http_client.go index bd40c366..7f3df67a 100644 --- a/internal/http_client.go +++ b/internal/http_client.go @@ -22,6 +22,8 @@ import ( "io/ioutil" "net/http" + "golang.org/x/net/context/ctxhttp" + "golang.org/x/net/context" ) @@ -44,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 } From 4a4f4cc27580b4eca9b0aab878bad69c77773981 Mon Sep 17 00:00:00 2001 From: Tyler Bui-Palsulich Date: Mon, 12 Mar 2018 09:41:24 -0400 Subject: [PATCH 3/8] all: don't use subtests to keep 1.6 compatibility --- firebase_test.go | 29 +++++++---------- integration/auth/user_mgt_test.go | 7 ++-- messaging/messaging_test.go | 54 +++++++++++++------------------ 3 files changed, 37 insertions(+), 53 deletions(-) diff --git a/firebase_test.go b/firebase_test.go index a14f6412..5f189889 100644 --- a/firebase_test.go +++ b/firebase_test.go @@ -15,7 +15,6 @@ package firebase import ( - "fmt" "io/ioutil" "log" "net/http" @@ -540,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) + } } } @@ -578,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/integration/auth/user_mgt_test.go b/integration/auth/user_mgt_test.go index 317f87e0..3ebf0a29 100644 --- a/integration/auth/user_mgt_test.go +++ b/integration/auth/user_mgt_test.go @@ -51,11 +51,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/messaging/messaging_test.go b/messaging/messaging_test.go index 76fb531c..8f244bad 100644 --- a/messaging/messaging_test.go +++ b/messaging/messaging_test.go @@ -566,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) } } @@ -595,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) } } @@ -658,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) + } } } @@ -700,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) + } } } @@ -742,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) + } } } From bda1070cd7b4664f59597cd4bfac748f1a2666e2 Mon Sep 17 00:00:00 2001 From: Tyler Bui-Palsulich Date: Mon, 12 Mar 2018 13:09:51 -0400 Subject: [PATCH 4/8] integration: use float64 for fields with exp value Values like -7e+07 cannot be parsed into ints in Go 1.6. So, use floats instead. --- integration/db/db_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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"` } From 8121c6d3bb7b2c5ecfd6863b9241deeb46169f74 Mon Sep 17 00:00:00 2001 From: Tyler Bui-Palsulich Date: Thu, 15 Mar 2018 09:57:51 -0400 Subject: [PATCH 5/8] integration/messaging: use t.Fatal not log.Fatal --- integration/messaging/messaging_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/messaging/messaging_test.go b/integration/messaging/messaging_test.go index b41bf87e..10818ddd 100644 --- a/integration/messaging/messaging_test.go +++ b/integration/messaging/messaging_test.go @@ -89,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) { From 5bb8adecd79c44a25d096098e08e5f5d7c0fa534 Mon Sep 17 00:00:00 2001 From: Tyler Bui-Palsulich Date: Thu, 15 Mar 2018 10:00:16 -0400 Subject: [PATCH 6/8] travis: add 1.6.x --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 53f411b4..bf5dafa8 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 From 3f33b02825601387dc7ed10114b4b1a50d72cc3e Mon Sep 17 00:00:00 2001 From: Tyler Bui-Palsulich Date: Thu, 15 Mar 2018 13:47:39 -0400 Subject: [PATCH 7/8] changelog: mention addition of 1.6 support --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5852ed27..b6cae91b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Unreleased -- +- [added] Added support for Go 1.6. # v2.6.0 From 5a09197de9d507e371f90575f6ab27e5a442586e Mon Sep 17 00:00:00 2001 From: Tyler Bui-Palsulich Date: Thu, 15 Mar 2018 13:50:57 -0400 Subject: [PATCH 8/8] readme: mention go version support --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3ea293a2..61d196a3 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/).