Skip to content

Instantly share code, notes, and snippets.

@crosbymichael
Created September 24, 2013 23:47
Show Gist options
  • Save crosbymichael/6692953 to your computer and use it in GitHub Desktop.
Save crosbymichael/6692953 to your computer and use it in GitHub Desktop.
func TestUniqueIndexSave(t *testing.T) {
s := NewStore()
key := func(v interface{}) string {
ts := v.(*test)
return fmt.Sprintf("%s:%d", ts.Name, ts.Age)
}
if err := s.AddIndex("name", key); err != nil {
t.Fatal(err)
}
if err := s.Save("1", &test{"Bob", 30}); err != nil {
t.Fatal(err)
}
if err := s.Save("2", &test{"Bob", 29}); err != nil {
t.Fatal(err)
}
if err := s.Save("3", &test{"Bob", 29}); err == nil {
t.Log("err should not be nil")
t.Fail()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment