Example #1
0
func fooShouldHave(ds datastore.Interface) func(interface{}, ...interface{}) string {
	return func(id interface{}, values ...interface{}) string {
		f := &Foo{ID: toInt64(id)}
		err := ds.Get(f)
		if len(values) == 0 {
			return ShouldEqual(err, datastore.ErrNoSuchEntity)
		}

		ret := ShouldBeNil(err)
		if ret == "" {
			if data, ok := values[0].([]byte); ok {
				ret = ShouldResemble(f.ValueNI, data)
			} else {
				ret = ShouldResemble(f.Value, toIntSlice(values))
			}
		}
		return ret
	}
}
Example #2
0
func fooSetTo(ds datastore.Interface) func(interface{}, ...interface{}) string {
	return func(id interface{}, values ...interface{}) string {
		f := &Foo{ID: toInt64(id)}
		if len(values) == 0 {
			return ShouldBeNil(ds.Delete(ds.KeyForObj(f)))
		}
		if data, ok := values[0].([]byte); ok {
			f.ValueNI = data
		} else {
			f.Value = toIntSlice(values)
		}
		return ShouldBeNil(ds.Put(f))
	}
}