forked from Mirrors/go-iap
Test errors for increased coverage on PlayStore
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package playstore
|
package playstore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -27,6 +28,18 @@ func TestInit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInitWithoutClientSecret(t *testing.T) {
|
||||||
|
expected := errors.New("Client Secret Key is required")
|
||||||
|
|
||||||
|
os.Setenv("IAB_CLIENT_ID", "dummyId")
|
||||||
|
actual := Init()
|
||||||
|
os.Clearenv()
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
|
t.Errorf("got %v\nwant %v", actual, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestInitWithConfig(t *testing.T) {
|
func TestInitWithConfig(t *testing.T) {
|
||||||
expected := &oauth.Config{
|
expected := &oauth.Config{
|
||||||
ClientId: "dummyId",
|
ClientId: "dummyId",
|
||||||
@@ -50,6 +63,34 @@ func TestInitWithConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInitWithConfigErrors(t *testing.T) {
|
||||||
|
expected := errors.New("Client ID is required")
|
||||||
|
|
||||||
|
config := &oauth.Config{
|
||||||
|
Scope: "https://www.googleapis.com/auth/androidpublisher",
|
||||||
|
AuthURL: "https://accounts.google.com/o/oauth2/auth",
|
||||||
|
TokenURL: "https://accounts.google.com/o/oauth2/token",
|
||||||
|
}
|
||||||
|
actual := InitWithConfig(config)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
|
t.Errorf("got %v\nwant %v", actual, expected)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = errors.New("Client Secret Key is required")
|
||||||
|
config = &oauth.Config{
|
||||||
|
ClientId: "dummyId",
|
||||||
|
Scope: "https://www.googleapis.com/auth/androidpublisher",
|
||||||
|
AuthURL: "https://accounts.google.com/o/oauth2/auth",
|
||||||
|
TokenURL: "https://accounts.google.com/o/oauth2/token",
|
||||||
|
}
|
||||||
|
actual = InitWithConfig(config)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
|
t.Errorf("got %v\nwant %v", actual, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestNew(t *testing.T) {
|
func TestNew(t *testing.T) {
|
||||||
// Initialize config
|
// Initialize config
|
||||||
_config := &oauth.Config{
|
_config := &oauth.Config{
|
||||||
@@ -106,6 +147,16 @@ func TestVerifySubscription(t *testing.T) {
|
|||||||
// TODO Nomal scenario
|
// TODO Nomal scenario
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVerifySubscriptionAndroidPublisherError(t *testing.T) {
|
||||||
|
client := Client{nil}
|
||||||
|
expected := errors.New("client is nil")
|
||||||
|
_, actual := client.VerifySubscription("package", "subscriptionID", "purchaseToken")
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
|
t.Errorf("got %v\nwant %v", actual, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestVerifyProduct(t *testing.T) {
|
func TestVerifyProduct(t *testing.T) {
|
||||||
Init()
|
Init()
|
||||||
|
|
||||||
@@ -126,3 +177,13 @@ func TestVerifyProduct(t *testing.T) {
|
|||||||
|
|
||||||
// TODO Nomal scenario
|
// TODO Nomal scenario
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVerifyProductAndroidPublisherError(t *testing.T) {
|
||||||
|
client := Client{nil}
|
||||||
|
expected := errors.New("client is nil")
|
||||||
|
_, actual := client.VerifyProduct("package", "productID", "purchaseToken")
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
|
t.Errorf("got %v\nwant %v", actual, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user