ducky/subscriptions

Paddy 2015-06-14 Parent:56a2bef197cd Child:61c4ce5850da

1:f1a22fc2321d Go to Latest

ducky/subscriptions/subscription_store_test.go

Implement PostgreSQL support, drop subscription IDs. Create a Postgres object that wraps database/sql, so we can attach methods to it and fulfill interfaces. Create a postgres_init.sql script that will create the subscriptions table in a PostgreSQL database. Make our period type fulfill the driver.Valuer and driver.Scanner types, so it can be stored in and retrieved from SQL databases. Create a SubscriptionStats type, and add a method to our subscriptionStore interface that will allow us to retrieve current stats about the Subscriptions it is storing. Deprecated the ID property of our Subscription type, and use the Subscription.UserID property instead as our primary key. Subscriptions should be unique per user and we generally will want to access Subscriptions in the context of the User they belong to, so the UserID is a better primary key. This also means we removed the getSubscriptionByUserID method (and implementations) from our subscriptionStore, as getSubscriptions now fills that role. Implement our getSubscriptionStats method in the memstore. Implement the subscriptionStore interface on our new Postgres type. Run the subscription store tests on our Postgres type, as well, if the PG_TEST_DB environment variable is set. Round all our timestamps in our tests to the nearest millisecond, as Postgres silently truncates all timestamps to the nearest millisecond, and it was causing false test failures. Remove the tests for our getSubscriptionStoreByUser method, as that was removed.

History
     1.1 --- a/subscription_store_test.go	Thu Jun 11 23:15:01 2015 -0400
     1.2 +++ b/subscription_store_test.go	Sun Jun 14 02:48:08 2015 -0400
     1.3 @@ -1,6 +1,7 @@
     1.4  package subscriptions
     1.5  
     1.6  import (
     1.7 +	"os"
     1.8  	"strconv"
     1.9  	"testing"
    1.10  	"time"
    1.11 @@ -18,14 +19,21 @@
    1.12  	subscriptionChangeInLockout
    1.13  )
    1.14  
    1.15 +func init() {
    1.16 +	if os.Getenv("PG_TEST_DB") != "" {
    1.17 +		p, err := NewPostgres(os.Getenv("PG_TEST_DB"))
    1.18 +		if err != nil {
    1.19 +			panic(err)
    1.20 +		}
    1.21 +		testSubscriptionStores = append(testSubscriptionStores, p)
    1.22 +	}
    1.23 +}
    1.24 +
    1.25  var testSubscriptionStores = []subscriptionStore{
    1.26  	NewMemstore(),
    1.27  }
    1.28  
    1.29  func compareSubscriptions(sub1, sub2 Subscription) (bool, string, interface{}, interface{}) {
    1.30 -	if !sub1.ID.Equal(sub2.ID) {
    1.31 -		return false, "ID", sub1.ID, sub2.ID
    1.32 -	}
    1.33  	if !sub1.UserID.Equal(sub2.UserID) {
    1.34  		return false, "UserID", sub1.UserID, sub2.UserID
    1.35  	}
    1.36 @@ -59,7 +67,7 @@
    1.37  func subscriptionMapContains(subscriptionMap map[string]Subscription, subscriptions ...Subscription) (bool, []Subscription) {
    1.38  	var missing []Subscription
    1.39  	for _, sub := range subscriptions {
    1.40 -		if _, ok := subscriptionMap[sub.ID.String()]; !ok {
    1.41 +		if _, ok := subscriptionMap[sub.UserID.String()]; !ok {
    1.42  			missing = append(missing, sub)
    1.43  		}
    1.44  	}
    1.45 @@ -77,26 +85,25 @@
    1.46  		}
    1.47  		customerID := uuid.NewID()
    1.48  		sub := Subscription{
    1.49 -			ID:             uuid.NewID(),
    1.50  			UserID:         customerID,
    1.51  			StripeCustomer: "stripeCustomer1",
    1.52  			Amount:         200,
    1.53  			Period:         MonthlyPeriod,
    1.54 -			Created:        time.Now(),
    1.55 -			BeginCharging:  time.Now().Add(time.Hour),
    1.56 +			Created:        time.Now().Round(time.Millisecond),
    1.57 +			BeginCharging:  time.Now().Round(time.Millisecond).Add(time.Hour),
    1.58  		}
    1.59  		err = store.createSubscription(sub)
    1.60  		if err != nil {
    1.61  			t.Errorf("Error creating subscription in %T: %+v\n", store, err)
    1.62  		}
    1.63 -		retrieved, err := store.getSubscriptions([]uuid.ID{sub.ID})
    1.64 +		retrieved, err := store.getSubscriptions([]uuid.ID{sub.UserID})
    1.65  		if err != nil {
    1.66  			t.Errorf("Error retrieving subscription from %T: %+v\n", store, err)
    1.67  		}
    1.68 -		if _, returned := retrieved[sub.ID.String()]; !returned {
    1.69 -			t.Errorf("Error retrieving subscription from %T: %s wasn't in the results.", store, sub.ID)
    1.70 +		if _, returned := retrieved[sub.UserID.String()]; !returned {
    1.71 +			t.Errorf("Error retrieving subscription from %T: %s wasn't in the results.", store, sub.UserID)
    1.72  		}
    1.73 -		ok, field, expected, result := compareSubscriptions(sub, retrieved[sub.ID.String()])
    1.74 +		ok, field, expected, result := compareSubscriptions(sub, retrieved[sub.UserID.String()])
    1.75  		if !ok {
    1.76  			t.Errorf("Expected %s to be %v, got %v from %T\n", field, expected, result, store)
    1.77  		}
    1.78 @@ -104,10 +111,10 @@
    1.79  		if err != ErrSubscriptionAlreadyExists {
    1.80  			t.Errorf("Unexpected error creating subscription in %T (wanted %+v): %+v\n", store, ErrSubscriptionAlreadyExists, err)
    1.81  		}
    1.82 -		sub.ID = uuid.NewID()
    1.83 +		sub.UserID = uuid.NewID()
    1.84  		err = store.createSubscription(sub)
    1.85  		if err != ErrStripeCustomerAlreadyExists {
    1.86 -			t.Errorf("Unexpected error creating subscription in %T (wanted %+v): %+v\n", store, ErrStripeCustomerAlreadyExists, err)
    1.87 +			t.Errorf("Unexpected error creating subscription in %T (wanted %+v): %#+v\n", store, ErrStripeCustomerAlreadyExists, err)
    1.88  		}
    1.89  		sub.StripeCustomer = "stripeCustomer2"
    1.90  		err = store.createSubscription(sub)
    1.91 @@ -120,27 +127,25 @@
    1.92  func TestUpdateSubscription(t *testing.T) {
    1.93  	variations := 1 << 7
    1.94  	sub := Subscription{
    1.95 -		ID:             uuid.NewID(),
    1.96  		UserID:         uuid.NewID(),
    1.97  		StripeCustomer: "default",
    1.98  		Amount:         -1,
    1.99  		Period:         MonthlyPeriod,
   1.100 -		Created:        time.Now().Add(time.Hour * -24),
   1.101 -		BeginCharging:  time.Now().Add(time.Hour * -24),
   1.102 -		LastCharged:    time.Now().Add(time.Hour * -24),
   1.103 -		LastNotified:   time.Now().Add(time.Hour * -24),
   1.104 +		Created:        time.Now().Round(time.Millisecond).Add(time.Hour * -24),
   1.105 +		BeginCharging:  time.Now().Round(time.Millisecond).Add(time.Hour * -24),
   1.106 +		LastCharged:    time.Now().Round(time.Millisecond).Add(time.Hour * -24),
   1.107 +		LastNotified:   time.Now().Round(time.Millisecond).Add(time.Hour * -24),
   1.108  		InLockout:      true,
   1.109  	}
   1.110  	sub2 := Subscription{
   1.111 -		ID:             uuid.NewID(),
   1.112  		UserID:         uuid.NewID(),
   1.113  		StripeCustomer: "stripeCustomer2",
   1.114  		Amount:         -2,
   1.115  		Period:         MonthlyPeriod,
   1.116 -		Created:        time.Now(),
   1.117 -		BeginCharging:  time.Now(),
   1.118 -		LastCharged:    time.Now(),
   1.119 -		LastNotified:   time.Now(),
   1.120 +		Created:        time.Now().Round(time.Millisecond),
   1.121 +		BeginCharging:  time.Now().Round(time.Millisecond),
   1.122 +		LastCharged:    time.Now().Round(time.Millisecond),
   1.123 +		LastNotified:   time.Now().Round(time.Millisecond),
   1.124  		InLockout:      false,
   1.125  	}
   1.126  
   1.127 @@ -179,19 +184,19 @@
   1.128  		}
   1.129  
   1.130  		if i&subscriptionChangeBeginCharging != 0 {
   1.131 -			beginCharging = time.Now().Add(time.Hour * time.Duration(i))
   1.132 +			beginCharging = time.Now().Round(time.Millisecond).Add(time.Hour * time.Duration(i))
   1.133  			change.BeginCharging = &beginCharging
   1.134  			expectation.BeginCharging = beginCharging
   1.135  		}
   1.136  
   1.137  		if i&subscriptionChangeLastCharged != 0 {
   1.138 -			lastCharged = time.Now().Add(time.Hour * time.Duration(i))
   1.139 +			lastCharged = time.Now().Round(time.Millisecond).Add(time.Hour * time.Duration(i))
   1.140  			change.LastCharged = &lastCharged
   1.141  			expectation.LastCharged = lastCharged
   1.142  		}
   1.143  
   1.144  		if i&subscriptionChangeLastNotified != 0 {
   1.145 -			lastNotified = time.Now().Add(time.Hour * time.Duration(i))
   1.146 +			lastNotified = time.Now().Round(time.Millisecond).Add(time.Hour * time.Duration(i))
   1.147  			change.LastNotified = &lastNotified
   1.148  			expectation.LastNotified = lastNotified
   1.149  		}
   1.150 @@ -221,19 +226,19 @@
   1.151  			if err != nil {
   1.152  				t.Fatalf("Error saving subscription in %T: %s\n", store, err)
   1.153  			}
   1.154 -			err = store.updateSubscription(sub.ID, change)
   1.155 +			err = store.updateSubscription(sub.UserID, change)
   1.156  			if err != nil {
   1.157  				t.Errorf("Error updating subscription in %T: %s\n", store, err)
   1.158  			}
   1.159 -			retrieved, err := store.getSubscriptions([]uuid.ID{sub.ID})
   1.160 +			retrieved, err := store.getSubscriptions([]uuid.ID{sub.UserID})
   1.161  			if err != nil {
   1.162  				t.Errorf("Error getting subscription from %T: %s\n", store, err)
   1.163  			}
   1.164  			ok, missing := subscriptionMapContains(retrieved, sub)
   1.165  			if !ok {
   1.166 -				t.Errorf("Expected to retrieve %s from %T, but missing was %+v\n", sub.ID.String(), store, missing)
   1.167 +				t.Errorf("Expected to retrieve %s from %T, but missing was %+v\n", sub.UserID.String(), store, missing)
   1.168  			}
   1.169 -			match, field, expected, got = compareSubscriptions(expectation, retrieved[sub.ID.String()])
   1.170 +			match, field, expected, got = compareSubscriptions(expectation, retrieved[sub.UserID.String()])
   1.171  			if !match {
   1.172  				t.Errorf("Expected field `%s` to be `%v`, got `%v` from %T\n", field, expected, got, store)
   1.173  			}
   1.174 @@ -253,7 +258,7 @@
   1.175  			t.Fatalf("Error saving subscription in %T: %+v\n", store, err)
   1.176  		}
   1.177  		change := SubscriptionChange{}
   1.178 -		err = store.updateSubscription(sub.ID, change)
   1.179 +		err = store.updateSubscription(sub.UserID, change)
   1.180  		if err != ErrSubscriptionChangeEmpty {
   1.181  			t.Errorf("Expected err to be %+v, but got %+v from %T\n", ErrSubscriptionChangeEmpty, err, store)
   1.182  		}
   1.183 @@ -263,7 +268,7 @@
   1.184  		if err != ErrSubscriptionNotFound {
   1.185  			t.Errorf("Expected err to be %+v, but got %+v from %T\n", ErrSubscriptionNotFound, err, store)
   1.186  		}
   1.187 -		err = store.updateSubscription(sub.ID, change)
   1.188 +		err = store.updateSubscription(sub.UserID, change)
   1.189  		if err != ErrStripeCustomerAlreadyExists {
   1.190  			t.Errorf("Expected err to be %+v, but got %+v from %T\n", ErrStripeCustomerAlreadyExists, err, store)
   1.191  		}
   1.192 @@ -277,12 +282,10 @@
   1.193  			t.Fatalf("Error resetting %T: %+v\n", store, err)
   1.194  		}
   1.195  		sub1 := Subscription{
   1.196 -			ID:             uuid.NewID(),
   1.197  			UserID:         uuid.NewID(),
   1.198  			StripeCustomer: "stripeCustomer1",
   1.199  		}
   1.200  		sub2 := Subscription{
   1.201 -			ID:             uuid.NewID(),
   1.202  			UserID:         uuid.NewID(),
   1.203  			StripeCustomer: "stripeCustomer2",
   1.204  		}
   1.205 @@ -294,27 +297,23 @@
   1.206  		if err != nil {
   1.207  			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
   1.208  		}
   1.209 -		err = store.deleteSubscription(sub1.ID)
   1.210 +		err = store.deleteSubscription(sub1.UserID)
   1.211  		if err != nil {
   1.212  			t.Fatalf("Error deleting %+v in %T: %+v\n", sub1, store, err)
   1.213  		}
   1.214 -		retrieved, err := store.getSubscriptions([]uuid.ID{sub1.ID, sub2.ID})
   1.215 +		retrieved, err := store.getSubscriptions([]uuid.ID{sub1.UserID, sub2.UserID})
   1.216  		if err != nil {
   1.217  			t.Errorf("Error retrieving subscriptions from %T: %+v\n", store, err)
   1.218  		}
   1.219  		ok, missing := subscriptionMapContains(retrieved, sub1)
   1.220  		if ok {
   1.221 -			t.Errorf("Expected not to retrieve %s from %T, but missing was %+v\n", sub1.ID.String(), store, missing)
   1.222 +			t.Errorf("Expected not to retrieve %s from %T, but missing was %+v\n", sub1.UserID.String(), store, missing)
   1.223  		}
   1.224  		ok, missing = subscriptionMapContains(retrieved, sub2)
   1.225  		if !ok {
   1.226 -			t.Errorf("Expected to retrieve %s from %T, but missing was %+v\n", sub2.ID.String(), store, missing)
   1.227 +			t.Errorf("Expected to retrieve %s from %T, but missing was %+v\n", sub2.UserID.String(), store, missing)
   1.228  		}
   1.229 -		_, err = store.getSubscriptionByUser(sub1.UserID)
   1.230 -		if err != ErrSubscriptionNotFound {
   1.231 -			t.Errorf("Expected err to be %+v, but got %+v from %T\n", ErrSubscriptionNotFound, err, store)
   1.232 -		}
   1.233 -		err = store.deleteSubscription(sub1.ID)
   1.234 +		err = store.deleteSubscription(sub1.UserID)
   1.235  		if err != ErrSubscriptionNotFound {
   1.236  			t.Errorf("Expected err to be %+v, but got %+v from %T\n", ErrSubscriptionNotFound, err, store)
   1.237  		}
   1.238 @@ -328,33 +327,30 @@
   1.239  			t.Fatalf("Error resetting %T: %+v\n", store, err)
   1.240  		}
   1.241  		sub1 := Subscription{
   1.242 -			ID:             uuid.NewID(),
   1.243  			UserID:         uuid.NewID(),
   1.244  			StripeCustomer: "stripeCustomer1",
   1.245  			Amount:         200,
   1.246  			Period:         MonthlyPeriod,
   1.247 -			Created:        time.Now().Add(time.Hour * -24 * 32),
   1.248 -			BeginCharging:  time.Now().Add(time.Hour * -24),
   1.249 -			LastCharged:    time.Now().Add(time.Hour * -24),
   1.250 +			Created:        time.Now().Round(time.Millisecond).Add(time.Hour * -24 * 32),
   1.251 +			BeginCharging:  time.Now().Round(time.Millisecond).Add(time.Hour * -24),
   1.252 +			LastCharged:    time.Now().Round(time.Millisecond).Add(time.Hour * -24),
   1.253  		}
   1.254  		sub2 := Subscription{
   1.255 -			ID:             uuid.NewID(),
   1.256  			UserID:         uuid.NewID(),
   1.257  			StripeCustomer: "stripeCustomer2",
   1.258  			Amount:         300,
   1.259  			Period:         MonthlyPeriod,
   1.260 -			Created:        time.Now().Add(time.Hour * -24 * 61),
   1.261 -			BeginCharging:  time.Now().Add(time.Hour * -24 * 31),
   1.262 -			LastCharged:    time.Now().Add(time.Hour * -24 * 31),
   1.263 +			Created:        time.Now().Round(time.Millisecond).Add(time.Hour * -24 * 61),
   1.264 +			BeginCharging:  time.Now().Round(time.Millisecond).Add(time.Hour * -24 * 31),
   1.265 +			LastCharged:    time.Now().Round(time.Millisecond).Add(time.Hour * -24 * 31),
   1.266  		}
   1.267  		sub3 := Subscription{
   1.268 -			ID:             uuid.NewID(),
   1.269  			UserID:         uuid.NewID(),
   1.270  			StripeCustomer: "stripeCustomer3",
   1.271  			Amount:         100,
   1.272  			Period:         MonthlyPeriod,
   1.273 -			Created:        time.Now().Add(time.Hour * -1),
   1.274 -			BeginCharging:  time.Now().Add(time.Hour * 31),
   1.275 +			Created:        time.Now().Round(time.Millisecond).Add(time.Hour * -1),
   1.276 +			BeginCharging:  time.Now().Round(time.Millisecond).Add(time.Hour * 31),
   1.277  			LastCharged:    time.Time{},
   1.278  		}
   1.279  		err = store.createSubscription(sub1)
   1.280 @@ -374,7 +370,7 @@
   1.281  		t.Logf("sub3: %+v\n", sub3)
   1.282  		// subscriptions last charged before right now
   1.283  		// should be sub1, sub2, and sub3
   1.284 -		results, err := store.listSubscriptionsLastChargedBefore(time.Now())
   1.285 +		results, err := store.listSubscriptionsLastChargedBefore(time.Now().Round(time.Millisecond))
   1.286  		if err != nil {
   1.287  			t.Errorf("Unexpected error listing subscriptions in %T: %+v\n", store, err)
   1.288  		}
   1.289 @@ -395,7 +391,7 @@
   1.290  		}
   1.291  		// subscriptions last charged before a week ago
   1.292  		// should be sub2, sub3
   1.293 -		results, err = store.listSubscriptionsLastChargedBefore(time.Now().Add(time.Hour * -24 * 7))
   1.294 +		results, err = store.listSubscriptionsLastChargedBefore(time.Now().Round(time.Millisecond).Add(time.Hour * -24 * 7))
   1.295  		if err != nil {
   1.296  			t.Errorf("Unexpected error listing subscriptions in %T: %+v\n", store, err)
   1.297  		}
   1.298 @@ -412,7 +408,7 @@
   1.299  		}
   1.300  		// subscriptions last charged before 32 days ago
   1.301  		// should be sub3
   1.302 -		results, err = store.listSubscriptionsLastChargedBefore(time.Now().Add(time.Hour * -24 * 32))
   1.303 +		results, err = store.listSubscriptionsLastChargedBefore(time.Now().Round(time.Millisecond).Add(time.Hour * -24 * 32))
   1.304  		if err != nil {
   1.305  			t.Errorf("Unexpected error listing subscriptions in %T: %+v\n", store, err)
   1.306  		}
   1.307 @@ -433,33 +429,30 @@
   1.308  			t.Fatalf("Error resetting %T: %+v\n", store, err)
   1.309  		}
   1.310  		sub1 := Subscription{
   1.311 -			ID:             uuid.NewID(),
   1.312  			UserID:         uuid.NewID(),
   1.313  			StripeCustomer: "stripeCustomer1",
   1.314  			Amount:         200,
   1.315  			Period:         MonthlyPeriod,
   1.316 -			Created:        time.Now(),
   1.317 -			BeginCharging:  time.Now().Add(time.Hour),
   1.318 +			Created:        time.Now().Round(time.Millisecond),
   1.319 +			BeginCharging:  time.Now().Round(time.Millisecond).Add(time.Hour),
   1.320  		}
   1.321  		sub2 := Subscription{
   1.322 -			ID:             uuid.NewID(),
   1.323  			UserID:         uuid.NewID(),
   1.324  			StripeCustomer: "stripeCustomer2",
   1.325  			Amount:         300,
   1.326  			Period:         MonthlyPeriod,
   1.327 -			Created:        time.Now().Add(time.Hour * -720),
   1.328 -			BeginCharging:  time.Now().Add(time.Hour*-720 + time.Hour*2),
   1.329 -			LastCharged:    time.Now(),
   1.330 +			Created:        time.Now().Round(time.Millisecond).Add(time.Hour * -720),
   1.331 +			BeginCharging:  time.Now().Round(time.Millisecond).Add(time.Hour*-720 + time.Hour*2),
   1.332 +			LastCharged:    time.Now().Round(time.Millisecond),
   1.333  		}
   1.334  		sub3 := Subscription{
   1.335 -			ID:             uuid.NewID(),
   1.336  			UserID:         uuid.NewID(),
   1.337  			StripeCustomer: "stripeCustomer3",
   1.338  			Amount:         100,
   1.339  			Period:         MonthlyPeriod,
   1.340 -			Created:        time.Now().Add(time.Hour * -1440),
   1.341 -			BeginCharging:  time.Now().Add(time.Hour * -1440),
   1.342 -			LastNotified:   time.Now().Add(time.Hour * -720),
   1.343 +			Created:        time.Now().Round(time.Millisecond).Add(time.Hour * -1440),
   1.344 +			BeginCharging:  time.Now().Round(time.Millisecond).Add(time.Hour * -1440),
   1.345 +			LastNotified:   time.Now().Round(time.Millisecond).Add(time.Hour * -720),
   1.346  			InLockout:      true,
   1.347  		}
   1.348  		err = store.createSubscription(sub1)
   1.349 @@ -478,63 +471,63 @@
   1.350  		if err != ErrNoSubscriptionID {
   1.351  			t.Errorf("Error retrieving no subscriptions from %T. Expected %+v, got %+v\n", store, ErrNoSubscriptionID, err)
   1.352  		}
   1.353 -		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.ID})
   1.354 +		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.UserID})
   1.355  		if err != nil {
   1.356 -			t.Errorf("Error retrieving %s from %T: %+v\n", sub1.ID, store, err)
   1.357 +			t.Errorf("Error retrieving %s from %T: %+v\n", sub1.UserID, store, err)
   1.358  		}
   1.359  		ok, missing := subscriptionMapContains(retrieved, sub1)
   1.360  		if !ok {
   1.361  			t.Logf("Results: %+v\n", retrieved)
   1.362  			t.Errorf("Expected %+v to be in the results, was not for %T.\n", missing, store)
   1.363  		}
   1.364 -		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.ID, sub2.ID})
   1.365 +		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.UserID, sub2.UserID})
   1.366  		if err != nil {
   1.367 -			t.Errorf("Error retrieving %s and %s from %T: %+v\n", sub1.ID, sub2.ID, store, err)
   1.368 +			t.Errorf("Error retrieving %s and %s from %T: %+v\n", sub1.UserID, sub2.UserID, store, err)
   1.369  		}
   1.370  		ok, missing = subscriptionMapContains(retrieved, sub1, sub2)
   1.371  		if !ok {
   1.372  			t.Logf("Results: %+v\n", retrieved)
   1.373  			t.Errorf("Expected %+v to be in the results, was not for %T.\n", missing, store)
   1.374  		}
   1.375 -		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.ID, sub3.ID})
   1.376 +		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.UserID, sub3.UserID})
   1.377  		if err != nil {
   1.378 -			t.Errorf("Error retrieving %s and %s from %T: %+v\n", sub1.ID, sub3.ID, store, err)
   1.379 +			t.Errorf("Error retrieving %s and %s from %T: %+v\n", sub1.UserID, sub3.UserID, store, err)
   1.380  		}
   1.381  		ok, missing = subscriptionMapContains(retrieved, sub1, sub3)
   1.382  		if !ok {
   1.383  			t.Logf("Results: %+v\n", retrieved)
   1.384  			t.Errorf("Expected %+v to be in the results, was not for %T.\n", missing, store)
   1.385  		}
   1.386 -		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.ID, sub2.ID, sub3.ID})
   1.387 +		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.UserID, sub2.UserID, sub3.UserID})
   1.388  		if err != nil {
   1.389 -			t.Errorf("Error retrieving %s, %s, and %s from %T: %+v\n", sub1.ID, sub2.ID, sub3.ID, store, err)
   1.390 +			t.Errorf("Error retrieving %s, %s, and %s from %T: %+v\n", sub1.UserID, sub2.UserID, sub3.UserID, store, err)
   1.391  		}
   1.392  		ok, missing = subscriptionMapContains(retrieved, sub1, sub2, sub3)
   1.393  		if !ok {
   1.394  			t.Logf("Results: %+v\n", retrieved)
   1.395  			t.Errorf("Expected %+v to be in the results, was not for %T.\n", missing, store)
   1.396  		}
   1.397 -		retrieved, err = store.getSubscriptions([]uuid.ID{sub2.ID})
   1.398 +		retrieved, err = store.getSubscriptions([]uuid.ID{sub2.UserID})
   1.399  		if err != nil {
   1.400 -			t.Errorf("Error retrieving %s from %T: %+v\n", sub2.ID, store, err)
   1.401 +			t.Errorf("Error retrieving %s from %T: %+v\n", sub2.UserID, store, err)
   1.402  		}
   1.403  		ok, missing = subscriptionMapContains(retrieved, sub2)
   1.404  		if !ok {
   1.405  			t.Logf("Results: %+v\n", retrieved)
   1.406  			t.Errorf("Expected %+v to be in the results, was not for %T.\n", missing, store)
   1.407  		}
   1.408 -		retrieved, err = store.getSubscriptions([]uuid.ID{sub2.ID, sub3.ID})
   1.409 +		retrieved, err = store.getSubscriptions([]uuid.ID{sub2.UserID, sub3.UserID})
   1.410  		if err != nil {
   1.411 -			t.Errorf("Error retrieving %s and %s from %T: %+v\n", sub2.ID, sub3.ID, store, err)
   1.412 +			t.Errorf("Error retrieving %s and %s from %T: %+v\n", sub2.UserID, sub3.UserID, store, err)
   1.413  		}
   1.414  		ok, missing = subscriptionMapContains(retrieved, sub2, sub3)
   1.415  		if !ok {
   1.416  			t.Logf("Results: %+v\n", retrieved)
   1.417  			t.Errorf("Expected %+v to be in the results, was not for %T.\n", missing, store)
   1.418  		}
   1.419 -		retrieved, err = store.getSubscriptions([]uuid.ID{sub3.ID})
   1.420 +		retrieved, err = store.getSubscriptions([]uuid.ID{sub3.UserID})
   1.421  		if err != nil {
   1.422 -			t.Errorf("Error retrieving %s from %T: %+v\n", sub3.ID, store, err)
   1.423 +			t.Errorf("Error retrieving %s from %T: %+v\n", sub3.UserID, store, err)
   1.424  		}
   1.425  		ok, missing = subscriptionMapContains(retrieved, sub3)
   1.426  		if !ok {
   1.427 @@ -548,7 +541,7 @@
   1.428  		if len(retrieved) != 0 {
   1.429  			t.Errorf("Expected no results, %T returned %+v\n", store, retrieved)
   1.430  		}
   1.431 -		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.ID, sub2.ID, uuid.NewID(), sub3.ID})
   1.432 +		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.UserID, sub2.UserID, uuid.NewID(), sub3.UserID})
   1.433  		if err != nil {
   1.434  			t.Errorf("Error retrieving non-existent ID from %T: %+v\n", store, err)
   1.435  		}
   1.436 @@ -562,67 +555,3 @@
   1.437  		}
   1.438  	}
   1.439  }
   1.440 -
   1.441 -func TestGetSubscriptionByUser(t *testing.T) {
   1.442 -	for _, store := range testSubscriptionStores {
   1.443 -		err := store.reset()
   1.444 -		if err != nil {
   1.445 -			t.Fatalf("Error resetting %T: %+v\n", store, err)
   1.446 -		}
   1.447 -		sub1 := Subscription{
   1.448 -			ID:             uuid.NewID(),
   1.449 -			UserID:         uuid.NewID(),
   1.450 -			StripeCustomer: "stripeCustomer1",
   1.451 -		}
   1.452 -		sub2 := Subscription{
   1.453 -			ID:             uuid.NewID(),
   1.454 -			UserID:         uuid.NewID(),
   1.455 -			StripeCustomer: "stripeCustomer2",
   1.456 -		}
   1.457 -		sub3 := Subscription{
   1.458 -			ID:             uuid.NewID(),
   1.459 -			UserID:         uuid.NewID(),
   1.460 -			StripeCustomer: "stripeCustomer3",
   1.461 -		}
   1.462 -		err = store.createSubscription(sub1)
   1.463 -		if err != nil {
   1.464 -			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
   1.465 -		}
   1.466 -		err = store.createSubscription(sub2)
   1.467 -		if err != nil {
   1.468 -			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
   1.469 -		}
   1.470 -		err = store.createSubscription(sub3)
   1.471 -		if err != nil {
   1.472 -			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
   1.473 -		}
   1.474 -		retrieved, err := store.getSubscriptionByUser(sub1.UserID)
   1.475 -		if err != nil {
   1.476 -			t.Errorf("Error retrieving subscription %+v from %T: %+v\n", sub1, store, err)
   1.477 -		}
   1.478 -		ok, field, expected, result := compareSubscriptions(sub1, retrieved)
   1.479 -		if !ok {
   1.480 -			t.Errorf("Expected %s to be %+v, but was %+v in %T\n", field, expected, result, store)
   1.481 -		}
   1.482 -		retrieved, err = store.getSubscriptionByUser(sub2.UserID)
   1.483 -		if err != nil {
   1.484 -			t.Errorf("Error retrieving subscription %+v from %T: %+v\n", sub2, store, err)
   1.485 -		}
   1.486 -		ok, field, expected, result = compareSubscriptions(sub2, retrieved)
   1.487 -		if !ok {
   1.488 -			t.Errorf("Expected %s to be %+v, but was %+v in %T\n", field, expected, result, store)
   1.489 -		}
   1.490 -		retrieved, err = store.getSubscriptionByUser(sub3.UserID)
   1.491 -		if err != nil {
   1.492 -			t.Errorf("Error retrieving subscription %+v from %T: %+v\n", sub3, store, err)
   1.493 -		}
   1.494 -		ok, field, expected, result = compareSubscriptions(sub3, retrieved)
   1.495 -		if !ok {
   1.496 -			t.Errorf("Expected %s to be %+v, but was %+v in %T\n", field, expected, result, store)
   1.497 -		}
   1.498 -		retrieved, err = store.getSubscriptionByUser(uuid.NewID())
   1.499 -		if err != ErrSubscriptionNotFound {
   1.500 -			t.Errorf("Expected err to be %+v, got %+v from %T\n", ErrSubscriptionNotFound, err, store)
   1.501 -		}
   1.502 -	}
   1.503 -}