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