(t *testing.T)
| 938 | } |
| 939 | |
| 940 | func TestTxn_DeletePrefix(t *testing.T) { |
| 941 | db := testDB(t) |
| 942 | txn := db.Txn(true) |
| 943 | |
| 944 | obj1 := &TestObject{ |
| 945 | ID: "my-object", |
| 946 | Foo: "abc", |
| 947 | Qux: []string{"abc1", "abc1"}, |
| 948 | } |
| 949 | obj2 := &TestObject{ |
| 950 | ID: "my-cool-thing", |
| 951 | Foo: "xyz", |
| 952 | Qux: []string{"xyz1", "xyz2"}, |
| 953 | } |
| 954 | obj3 := &TestObject{ |
| 955 | ID: "my-other-cool-thing", |
| 956 | Foo: "xyz", |
| 957 | Qux: []string{"xyz1", "xyz2"}, |
| 958 | } |
| 959 | |
| 960 | err := txn.Insert("main", obj1) |
| 961 | if err != nil { |
| 962 | t.Fatalf("err: %v", err) |
| 963 | } |
| 964 | err = txn.Insert("main", obj2) |
| 965 | if err != nil { |
| 966 | t.Fatalf("err: %v", err) |
| 967 | } |
| 968 | err = txn.Insert("main", obj3) |
| 969 | if err != nil { |
| 970 | t.Fatalf("err: %v", err) |
| 971 | } |
| 972 | |
| 973 | // Lookup by qux field index |
| 974 | iterator, err := txn.Get("main", "qux", "abc1") |
| 975 | if err != nil { |
| 976 | t.Fatalf("Unexpected error: %v", err) |
| 977 | } |
| 978 | var objects []TestObject |
| 979 | for obj := iterator.Next(); obj != nil; obj = iterator.Next() { |
| 980 | object := obj.(*TestObject) |
| 981 | objects = append(objects, *object) |
| 982 | } |
| 983 | if len(objects) != 1 { |
| 984 | t.Fatalf("Expected exactly one object") |
| 985 | } |
| 986 | expectedID := "my-object" |
| 987 | if objects[0].ID != expectedID { |
| 988 | t.Fatalf("Unexpected id, expected %v, but got %v", expectedID, objects[0].ID) |
| 989 | } |
| 990 | |
| 991 | // Delete a prefix |
| 992 | deleted, err := txn.DeletePrefix("main", "id_prefix", "my-") |
| 993 | if err != nil { |
| 994 | t.Fatalf("Unexpected err: %v", err) |
| 995 | } |
| 996 | if !deleted { |
| 997 | t.Fatalf("Expected DeletePrefix to return true") |
nothing calls this directly
no test coverage detected
searching dependent graphs…