diff --git a/Makefile b/Makefile index 2a1e304..9c73383 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,22 @@ - -.PHONEY: all setup test cover - +.PHONEY: all all: setup cover +.PHONEY: setup setup: - go get golang.org/x/tools/cmd/cover - go get google.golang.org/appengine/urlfetch - go get ./... + go get golang.org/x/tools/cmd/cover + go get google.golang.org/appengine/urlfetch + go get ./... +.PHONEY: test test: - go test -v ./... + go test -v ./... +.PHONEY: cover cover: - go test -coverprofile=coverage.txt ./... + go test -coverprofile=coverage.txt ./... + +.PHONEY: generate +generate: + rm -rf ./appstore/mocks/* + rm -rf ./playstore/mocks/* + go generate ./... diff --git a/appstore/mocks/mock_appstore.go b/appstore/mocks/appstore.go similarity index 100% rename from appstore/mocks/mock_appstore.go rename to appstore/mocks/appstore.go diff --git a/appstore/validator.go b/appstore/validator.go index 301ce59..f68f2b6 100644 --- a/appstore/validator.go +++ b/appstore/validator.go @@ -10,7 +10,7 @@ import ( "time" ) -//go:generate mockgen -destination=mocks/mock_appstore.go -package=mocks github.com/awa/go-iap/appstore IAPClient +//go:generate mockgen -destination=mocks/appstore.go -package=mocks github.com/awa/go-iap/appstore IAPClient const ( // SandboxURL is the endpoint for sandbox environment. diff --git a/playstore/mocks/mock_playstore.go b/playstore/mocks/playstore.go similarity index 100% rename from playstore/mocks/mock_playstore.go rename to playstore/mocks/playstore.go diff --git a/playstore/validator.go b/playstore/validator.go index 5a6e1ba..f572029 100644 --- a/playstore/validator.go +++ b/playstore/validator.go @@ -8,16 +8,17 @@ import ( "crypto/x509" "encoding/base64" "fmt" - "google.golang.org/api/option" "net/http" "time" + "google.golang.org/api/option" + "golang.org/x/oauth2" "golang.org/x/oauth2/google" androidpublisher "google.golang.org/api/androidpublisher/v3" ) -//go:generate mockgen -destination=mocks/mock_playstore.go -package=mocks github.com/awa/go-iap/playstore IABProduct,IABSubscription +//go:generate mockgen -destination=mocks/playstore.go -package=mocks github.com/awa/go-iap/playstore IABProduct,IABSubscription // The IABProduct type is an interface for product service type IABProduct interface { @@ -46,7 +47,6 @@ func New(jsonKey []byte) (*Client, error) { c := &http.Client{Timeout: 10 * time.Second} ctx := context.WithValue(context.Background(), oauth2.HTTPClient, c) - conf, err := google.JWTConfigFromJSON(jsonKey, androidpublisher.AndroidpublisherScope) if err != nil { return nil, err diff --git a/playstore/validator_test.go b/playstore/validator_test.go index b40ba52..4f90541 100644 --- a/playstore/validator_test.go +++ b/playstore/validator_test.go @@ -35,7 +35,7 @@ func TestNew(t *testing.T) { t.Parallel() // Exception scenario - expected := "oauth2: cannot fetch token: 400 Bad Request\nResponse: {\n \"error\": \"invalid_grant\",\n \"error_description\": \"Invalid issuer: Not a service account.\"\n}" + expected := "oauth2: cannot fetch token: 400 Bad Request\nResponse: {\"error\":\"invalid_grant\",\"error_description\":\"Invalid JWT: iss field missing.\"}" _, err := New(dummyKey) if err == nil || err.Error() != expected {