auth
auth/profile_test.go
Update uuid import path, test for multiple profile updates. Test updating multiple profiles in one request (e.g., when profiles become compromised.) Update the uuid import path to use the new code.secondbit.org/uuid import path.
1.1 --- a/profile_test.go Fri Sep 19 00:05:35 2014 -0400 1.2 +++ b/profile_test.go Sat Sep 27 20:51:19 2014 -0400 1.3 @@ -5,7 +5,7 @@ 1.4 "testing" 1.5 "time" 1.6 1.7 - "secondbit.org/uuid" 1.8 + "code.secondbit.org/uuid" 1.9 ) 1.10 1.11 const ( 1.12 @@ -221,3 +221,63 @@ 1.13 } 1.14 } 1.15 } 1.16 + 1.17 +func TestProfilesUpdates(t *testing.T) { 1.18 + profile1 := Profile{ 1.19 + ID: uuid.NewID(), 1.20 + } 1.21 + profile2 := Profile{ 1.22 + ID: uuid.NewID(), 1.23 + } 1.24 + profile3 := Profile{ 1.25 + ID: uuid.NewID(), 1.26 + } 1.27 + truth := true 1.28 + change := BulkProfileChange{ 1.29 + Compromised: &truth, 1.30 + } 1.31 + for _, store := range profileStores { 1.32 + err := store.SaveProfile(profile1) 1.33 + if err != nil { 1.34 + t.Errorf("Error saving profile in %T: %s", store, err) 1.35 + } 1.36 + err = store.SaveProfile(profile2) 1.37 + if err != nil { 1.38 + t.Errorf("Error saving profile in %T: %s", store, err) 1.39 + } 1.40 + err = store.SaveProfile(profile3) 1.41 + if err != nil { 1.42 + t.Errorf("Error saving profile in %T: %s", store, err) 1.43 + } 1.44 + err = store.UpdateProfiles([]uuid.ID{profile1.ID, profile3.ID}, change) 1.45 + if err != nil { 1.46 + t.Errorf("Error updating profile in %T: %s", store, err) 1.47 + } 1.48 + profile1.Compromised = truth 1.49 + profile3.Compromised = truth 1.50 + retrieved, err := store.GetProfileByID(profile1.ID) 1.51 + if err != nil { 1.52 + t.Errorf("Error getting profile from %T: %s", store, err) 1.53 + } 1.54 + match, field, expected, got := compareProfiles(profile1, retrieved) 1.55 + if !match { 1.56 + t.Errorf("Expected field `%s` to be `%v`, got `%v` from %T", field, expected, got, store) 1.57 + } 1.58 + retrieved, err = store.GetProfileByID(profile2.ID) 1.59 + if err != nil { 1.60 + t.Errorf("Error getting profile from %T: %s", store, err) 1.61 + } 1.62 + match, field, expected, got = compareProfiles(profile2, retrieved) 1.63 + if !match { 1.64 + t.Errorf("Expected field `%s` to be `%v`, got `%v` from %T", field, expected, got, store) 1.65 + } 1.66 + retrieved, err = store.GetProfileByID(profile3.ID) 1.67 + if err != nil { 1.68 + t.Errorf("Error getting profile from %T: %s", store, err) 1.69 + } 1.70 + match, field, expected, got = compareProfiles(profile3, retrieved) 1.71 + if !match { 1.72 + t.Errorf("Expected field `%s` to be `%v`, got `%v` from %T", field, expected, got, store) 1.73 + } 1.74 + } 1.75 +}