mirror of
https://github.com/imjasonh/staticmaps
synced 2026-07-19 07:15:38 +00:00
use new context, API_KEY env for tests
This commit is contained in:
parent
9d0e43710d
commit
179b8975a7
11 changed files with 20 additions and 27 deletions
|
|
@ -1,9 +1,8 @@
|
||||||
package maps
|
package maps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type contextKey int
|
type contextKey int
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
package maps
|
package maps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
package maps
|
package maps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// DistanceMatrix requests travel distance and time for a matrix of origins and destinations.
|
// DistanceMatrix requests travel distance and time for a matrix of origins and destinations.
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
package maps
|
package maps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Elevation requests elevation data for a series of locations.
|
// Elevation requests elevation data for a series of locations.
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
package maps
|
package maps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
||||||
3
maps.go
3
maps.go
|
|
@ -1,6 +1,7 @@
|
||||||
package maps
|
package maps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
|
@ -8,8 +9,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
||||||
17
maps_test.go
17
maps_test.go
|
|
@ -1,22 +1,25 @@
|
||||||
package maps
|
package maps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
apiKey = flag.String("apiKey", "", "Google Maps API key")
|
apiKey string
|
||||||
|
ctx = NewContext("", &http.Client{})
|
||||||
ctx = NewContext("", &http.Client{})
|
wctx = NewWorkContext("clientID", "privKey", &http.Client{})
|
||||||
wctx = NewWorkContext("clientID", "privKey", &http.Client{})
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.Parse()
|
apiKey = os.Getenv("API_KEY")
|
||||||
|
if apiKey == "" {
|
||||||
|
log.Fatal("API_KEY must be provided")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDirections(t *testing.T) {
|
func TestDirections(t *testing.T) {
|
||||||
|
|
@ -200,7 +203,7 @@ func TestSnapToRoads(t *testing.T) {
|
||||||
t.Errorf("unexpected error, got %v, want %v", err, ErrNoAPIKey)
|
t.Errorf("unexpected error, got %v, want %v", err, ErrNoAPIKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
keyCtx := NewContext(*apiKey, &http.Client{})
|
keyCtx := NewContext(apiKey, &http.Client{})
|
||||||
r, err := SnapToRoads(keyCtx, path, opts)
|
r, err := SnapToRoads(keyCtx, path, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
|
|
||||||
3
roads.go
3
roads.go
|
|
@ -1,10 +1,9 @@
|
||||||
package maps
|
package maps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"code.google.com/p/go.net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const roadsAPIBaseURL = "https://roads.googleapis.com/v1/"
|
const roadsAPIBaseURL = "https://roads.googleapis.com/v1/"
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
package maps
|
package maps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
package maps
|
package maps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// StreetView requests a static StreetView image of the requested size.
|
// StreetView requests a static StreetView image of the requested size.
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
package maps
|
package maps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TimeZone requests time zone information about a location.
|
// TimeZone requests time zone information about a location.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue