auth

Paddy 2014-09-01 Child:607708cd8829

31:88523dab00a5 Go to Latest

auth/client_test.go

Implement ClientStore in Memstore. Add the ClientStore interface implementation to Memstore. Change the ClientStore interface's UpdateClient function to take a new type, ClientChange, rather than enumerating the arguments in the function signature, which is a much cleaner interface. Add tests for the successful (works-as-intended) scenarios involving ClientStores. Ignore UpdateClient for now--I want to do tests that test every combination of ClientUpdate attributes being specified, to be sure that only the attributes specified are updated and that all the attributes specified are updated.

History
paddy@31 1 package auth
paddy@31 2
paddy@31 3 import (
paddy@31 4 "testing"
paddy@31 5
paddy@31 6 "secondbit.org/uuid"
paddy@31 7 )
paddy@31 8
paddy@31 9 var clientStores = []ClientStore{NewMemstore()}
paddy@31 10
paddy@31 11 func TestClientStoreSuccess(t *testing.T) {
paddy@31 12 client := Client{
paddy@31 13 ID: uuid.NewID(),
paddy@31 14 Secret: "secret",
paddy@31 15 RedirectURI: "redirectURI",
paddy@31 16 OwnerID: uuid.NewID(),
paddy@31 17 Name: "name",
paddy@31 18 Logo: "logo",
paddy@31 19 Website: "website",
paddy@31 20 }
paddy@31 21 for _, store := range clientStores {
paddy@31 22 err := store.SaveClient(client)
paddy@31 23 if err != nil {
paddy@31 24 t.Errorf("Error saving client to %T: %s", store, err)
paddy@31 25 }
paddy@31 26 retrieved, err := store.GetClient(client.ID)
paddy@31 27 if err != nil {
paddy@31 28 t.Errorf("Error retrieving client from %T: %s", store, err)
paddy@31 29 }
paddy@31 30 t.Log(retrieved)
paddy@31 31 // TODO: compare retrieved to client
paddy@31 32 clients, err := store.ListClientsByOwner(client.OwnerID, 25, 0)
paddy@31 33 if err != nil {
paddy@31 34 t.Errorf("Error retrieving clients by owner from %T: %s", store, err)
paddy@31 35 }
paddy@31 36 if len(clients) != 1 {
paddy@31 37 t.Errorf("Expected 1 client in response from %T, got %+v", store, clients)
paddy@31 38 }
paddy@31 39 // TODO: compare clients[0] to client
paddy@31 40 err = store.DeleteClient(client.ID)
paddy@31 41 if err != nil {
paddy@31 42 t.Errorf("Error deleting client from %T: %s", store, err)
paddy@31 43 }
paddy@31 44 retrieved, err = store.GetClient(client.ID)
paddy@31 45 if err != ErrClientNotFound {
paddy@31 46 t.Errorf("Expected ErrClientNotFound from %T, got %+v and %s", store, retrieved, err)
paddy@31 47 }
paddy@31 48 clients, err = store.ListClientsByOwner(client.OwnerID, 25, 0)
paddy@31 49 if err != nil {
paddy@31 50 t.Errorf("Error listing clients by owner from %T: %s", store, err)
paddy@31 51 }
paddy@31 52 if len(clients) != 0 {
paddy@31 53 t.Errorf("Expected 0 clients in response from %T, got %+v", store, clients)
paddy@31 54 }
paddy@31 55 }
paddy@31 56 }