From f0278c7c2d8d2546da625a05cd5cc3da7ea656f8 Mon Sep 17 00:00:00 2001 From: Bogdan Constantinescu Date: Wed, 25 Feb 2015 11:15:20 +0200 Subject: [PATCH] Test errors for increased coverage on PlayStore --- playstore/validator_test.go | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/playstore/validator_test.go b/playstore/validator_test.go index ce2525e..248944e 100644 --- a/playstore/validator_test.go +++ b/playstore/validator_test.go @@ -1,6 +1,7 @@ package playstore import ( + "errors" "os" "reflect" "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) { expected := &oauth.Config{ 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) { // Initialize config _config := &oauth.Config{ @@ -106,6 +147,16 @@ func TestVerifySubscription(t *testing.T) { // 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) { Init() @@ -126,3 +177,13 @@ func TestVerifyProduct(t *testing.T) { // 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) + } +}