gifs/api

Paddy 2014-10-17 Parent:18cb30e077ba

6:eb450538f079 Go to Latest

gifs/api/datastore_test.go

Make UsageTracker an interface, ditch the channel interface. Stop using channels to track usage. Just call functions. Make UsageTracker an interface, so there can be multiple implementations, and create the in-memory implementation.

History
1 package api
3 import (
4 "testing"
5 "time"
7 "code.secondbit.org/uuid.hg"
8 )
10 var datastores = []Datastore{NewMemstore()}
12 func compareCollections(expectation, result Collection) (field string, expected, got interface{}) {
13 if !expectation.ID.Equal(result.ID) {
14 return "ID", expectation.ID, result.ID
15 }
16 if expectation.Name != result.Name {
17 return "name", expectation.Name, result.Name
18 }
19 if !expectation.Owner.Equal(result.Owner) {
20 return "owner", expectation.Owner, result.Owner
21 }
22 if !expectation.Created.Equal(result.Created) {
23 return "created", expectation.Created, result.Created
24 }
25 return "", nil, nil
26 }
28 func TestCreateCollection(t *testing.T) {
29 for pos, datastore := range datastores {
30 expectation := Collection{
31 ID: uuid.NewID(),
32 Name: "Test Collection",
33 Owner: uuid.NewID(),
34 Created: time.Now(),
35 }
36 err := datastore.CreateCollection(expectation)
37 if err != nil {
38 t.Errorf("Error creating collection in datastore %d: %s\n", pos, err)
39 }
40 result, err := datastore.GetCollectionByID(expectation.ID)
41 if err != nil {
42 t.Errorf("Error retrieving collection in datastore %d: %s\n", pos, err)
43 }
44 field, exp, got := compareCollections(expectation, result)
45 if field != "" {
46 t.Errorf("Collection did not meet expectations for datastore %d. Expected %v for %s, got %v.", pos, exp, field, got)
47 }
48 }
49 }
51 func TestUpdateCollection(t *testing.T) {
52 }
54 func TestUpdateCollectionCollectionNotFound(t *testing.T) {
55 }
57 func TestGetCollectionByDomain(t *testing.T) {
58 }
60 func TestGetCollectionByDomainCollectionNotFound(t *testing.T) {
61 }
63 func TestGetCollectionByID(t *testing.T) {
64 }
66 func TestGetCollectionByIDCollectionNotFound(t *testing.T) {
67 }
69 func TestGetCollectionsByUser(t *testing.T) {
70 }
72 func TestGetCollectionsByUserNoCollections(t *testing.T) {
73 }
75 func TestAddDomainToCollection(t *testing.T) {
76 }
78 func TestAddDomainToCollectionDomainAlreadyExists(t *testing.T) {
79 }
81 func TestAddDomainToCollectionCollectionNotFound(t *testing.T) {
82 }
84 func TestRemoveDomainFromCollection(t *testing.T) {
85 }
87 func TestRemoveDomainFromCollectionDomainNotFound(t *testing.T) {
88 }
90 func TestGetDomainsByCollection(t *testing.T) {
91 }
93 func TestGetDomainsByCollectionNoResults(t *testing.T) {
94 }
96 func TestDeleteCollection(t *testing.T) {
97 }
99 func TestDeleteCollectionCollectionNotFound(t *testing.T) {
100 }
102 func TestGetItemsByCollectionDomain(t *testing.T) {
103 }
105 func TestGetItemsByCollectionDomainCollectionNotFound(t *testing.T) {
106 }
108 func TestGetItemsByCollectionDomainNoResults(t *testing.T) {
109 }
111 func TestGetItemsByCollectionID(t *testing.T) {
112 }
114 func TestGetItemsByCollectionIDCollectionNotFound(t *testing.T) {
115 }
117 func TestGetItemsByCollectionIDNoResults(t *testing.T) {
118 }
120 func TestAddItemToCollection(t *testing.T) {
121 }
123 func TestAddItemToCollectionCollectionNotFound(t *testing.T) {
124 }
126 func TestAddItemToCollectionItemAlreadyExists(t *testing.T) {
127 }
129 func TestGetItemByName(t *testing.T) {
130 }
132 func TestGetItemByNameCollectionNotFound(t *testing.T) {
133 }
135 func TestGetItemByNameItemNotFound(t *testing.T) {
136 }
138 func TestDeleteItem(t *testing.T) {
139 }
141 func TestDeleteItemItemNotFound(t *testing.T) {
142 }