func TestSyncPutAndDelete(t *testing.T) { test.RunTestServer(func(ts *test.TestServer) { assert := wcg.NewAssert(t) d := NewDriver(ts.Context, "testSyncStruct", wcg.NewLogger(nil)) key := d.NewKey("foo", 0, nil) tss := &testSyncStruct{} var tss1 testSyncStruct key, err := d.SyncPut(key, tss) assert.Nil(err, "Driver#PutSync should not return an error") d.Get(key, &tss1) assert.Ok(!wcg.IsZero(tss1.Timestamp), "Driver#SyncPut should update timestamp") err = d.SyncDelete(key) assert.Nil(err, "Driver#SyncDelete should not return an error") err = d.Get(key, &tss1) assert.Ok(err == ErrNoSuchEntity, "Driver#SyncDelete should delete the entity") }) }
return nil } } // ValidationFunc represents function to validate. // `Fun` should be a function which returns true only when the validation is passed. // `Message` should be a error message when validation is failed. type ValidationFunc func(v interface{}) *FieldValidationError type ValidationRegistrar struct { funcs []ValidationFunc } var requiredError = NewFieldValidationError("must be required.", nil) var required = func(v interface{}) *FieldValidationError { if wcg.IsZero(v) || wcg.IsNil(v) { return requiredError } return nil } var min = func(n int) ValidationFunc { var minError = NewFieldValidationError( "must be more than or equal to {{.Min}}", map[string]interface{}{ "Min": n, }, ) return func(v interface{}) *FieldValidationError { if szInt(v) >= n {