Skip to content

Commit

Permalink
Support Go 1.6 (#120)
Browse files Browse the repository at this point in the history
* all: use golang.org/x/net/context

* internal: use ctxhttp to use /x/ context

The 1.6 Request type doesn't have WithContext.

* all: don't use subtests to keep 1.6 compatibility

* 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/messaging: use t.Fatal not log.Fatal

* travis: add 1.6.x

* changelog: mention addition of 1.6 support

* readme: mention go version support
  • Loading branch information
tbpg authored and avishalom committed Mar 15, 2018
1 parent 9bd56f9 commit 0c849e9
Show file tree
Hide file tree
Showing 32 changed files with 101 additions and 85 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: go

go:
- 1.6.x
- 1.7.x
- 1.8.x
- 1.9.x
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).

Expand Down
3 changes: 2 additions & 1 deletion auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package auth

import (
"context"
"crypto/rsa"
"crypto/x509"
"encoding/json"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion auth/auth_appengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package auth

import (
"context"
"golang.org/x/net/context"

"google.golang.org/appengine"
)
Expand Down
2 changes: 1 addition & 1 deletion auth/auth_std.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package auth

import "context"
import "golang.org/x/net/context"

func newSigner(ctx context.Context) (signer, error) {
return serviceAcctSigner{}, nil
Expand Down
3 changes: 2 additions & 1 deletion auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package auth

import (
"context"
"encoding/json"
"errors"
"fmt"
Expand All @@ -26,6 +25,8 @@ import (
"testing"
"time"

"golang.org/x/net/context"

"golang.org/x/oauth2/google"

"google.golang.org/api/option"
Expand Down
3 changes: 2 additions & 1 deletion auth/user_mgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package auth

import (
"context"
"encoding/json"
"fmt"
"net/http"
Expand All @@ -24,6 +23,8 @@ import (
"strings"
"time"

"golang.org/x/net/context"

"google.golang.org/api/identitytoolkit/v3"
"google.golang.org/api/iterator"
)
Expand Down
3 changes: 2 additions & 1 deletion auth/user_mgt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package auth

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io/ioutil"
Expand All @@ -27,6 +26,8 @@ import (
"testing"
"time"

"golang.org/x/net/context"

"firebase.google.com/go/internal"

"golang.org/x/oauth2"
Expand Down
3 changes: 2 additions & 1 deletion firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 14 additions & 18 deletions firebase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package firebase

import (
"context"
"fmt"
"io/ioutil"
"log"
"net/http"
Expand All @@ -28,6 +26,8 @@ import (
"testing"
"time"

"golang.org/x/net/context"

"golang.org/x/oauth2/google"

"google.golang.org/api/transport"
Expand Down Expand Up @@ -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)
}
}
}

Expand Down Expand Up @@ -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)
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion iid/iid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion iid/iid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion integration/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package auth

import (
"bytes"
"context"
"encoding/json"
"flag"
"fmt"
Expand All @@ -28,6 +27,8 @@ import (
"testing"
"time"

"golang.org/x/net/context"

"firebase.google.com/go/auth"
"firebase.google.com/go/integration/internal"
)
Expand Down
10 changes: 5 additions & 5 deletions integration/auth/user_mgt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions integration/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
3 changes: 2 additions & 1 deletion integration/firestore/firestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
package firestore

import (
"context"
"log"
"reflect"
"testing"

"golang.org/x/net/context"

"firebase.google.com/go/integration/internal"
)

Expand Down
3 changes: 2 additions & 1 deletion integration/iid/iid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
3 changes: 2 additions & 1 deletion integration/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
package internal

import (
"context"
"encoding/json"
"go/build"
"io/ioutil"
"net/http"
"path/filepath"
"strings"

"golang.org/x/net/context"

firebase "firebase.google.com/go"
"firebase.google.com/go/internal"
"google.golang.org/api/option"
Expand Down
5 changes: 3 additions & 2 deletions integration/messaging/messaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion integration/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
package storage

import (
"context"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"testing"

"golang.org/x/net/context"

"firebase.google.com/go"

gcs "cloud.google.com/go/storage"
Expand Down
7 changes: 5 additions & 2 deletions internal/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Expand Down
Loading

0 comments on commit 0c849e9

Please sign in to comment.