gifs/api

Paddy 2014-10-17 Parent:08ec88016e2f Child:18cb30e077ba

1:d3ba1115bfd0 Go to Latest

gifs/api/datastore_test.go

Remove user functions and logins, fix UpdateCollection. UpdateCollection now takes a CollectionChange argument, rather than overwriting everything. Remove all our user related code, as that's going to be superseded by code.secondbit.org/auth, anyways.

History
1 package api
3 import (
4 "testing"
5 "time"
7 "secondbit.org/uuid"
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 }