gifs/api
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.
| paddy@0 | 1 package api |
| paddy@0 | 2 |
| paddy@0 | 3 import ( |
| paddy@0 | 4 "testing" |
| paddy@0 | 5 "time" |
| paddy@0 | 6 |
| paddy@0 | 7 "secondbit.org/uuid" |
| paddy@0 | 8 ) |
| paddy@0 | 9 |
| paddy@0 | 10 var datastores = []Datastore{NewMemstore()} |
| paddy@0 | 11 |
| paddy@0 | 12 func compareCollections(expectation, result Collection) (field string, expected, got interface{}) { |
| paddy@0 | 13 if !expectation.ID.Equal(result.ID) { |
| paddy@0 | 14 return "ID", expectation.ID, result.ID |
| paddy@0 | 15 } |
| paddy@0 | 16 if expectation.Name != result.Name { |
| paddy@0 | 17 return "name", expectation.Name, result.Name |
| paddy@0 | 18 } |
| paddy@0 | 19 if !expectation.Owner.Equal(result.Owner) { |
| paddy@0 | 20 return "owner", expectation.Owner, result.Owner |
| paddy@0 | 21 } |
| paddy@0 | 22 if !expectation.Created.Equal(result.Created) { |
| paddy@0 | 23 return "created", expectation.Created, result.Created |
| paddy@0 | 24 } |
| paddy@0 | 25 return "", nil, nil |
| paddy@0 | 26 } |
| paddy@0 | 27 |
| paddy@0 | 28 func TestCreateCollection(t *testing.T) { |
| paddy@0 | 29 for pos, datastore := range datastores { |
| paddy@0 | 30 expectation := Collection{ |
| paddy@0 | 31 ID: uuid.NewID(), |
| paddy@0 | 32 Name: "Test Collection", |
| paddy@0 | 33 Owner: uuid.NewID(), |
| paddy@0 | 34 Created: time.Now(), |
| paddy@0 | 35 } |
| paddy@0 | 36 err := datastore.CreateCollection(expectation) |
| paddy@0 | 37 if err != nil { |
| paddy@0 | 38 t.Errorf("Error creating collection in datastore %d: %s\n", pos, err) |
| paddy@0 | 39 } |
| paddy@0 | 40 result, err := datastore.GetCollectionByID(expectation.ID) |
| paddy@0 | 41 if err != nil { |
| paddy@0 | 42 t.Errorf("Error retrieving collection in datastore %d: %s\n", pos, err) |
| paddy@0 | 43 } |
| paddy@0 | 44 field, exp, got := compareCollections(expectation, result) |
| paddy@0 | 45 if field != "" { |
| paddy@0 | 46 t.Errorf("Collection did not meet expectations for datastore %d. Expected %v for %s, got %v.", pos, exp, field, got) |
| paddy@0 | 47 } |
| paddy@0 | 48 } |
| paddy@0 | 49 } |