(t *testing.T)
| 50 | ) |
| 51 | |
| 52 | func TestCAS(t *testing.T) { |
| 53 | withFixtures(t, func(t *testing.T, client Client) { |
| 54 | // Blindly set key to "0". |
| 55 | err := client.CAS(ctx, key, func(interface{}) (interface{}, bool, error) { |
| 56 | return "0", true, nil |
| 57 | }) |
| 58 | require.NoError(t, err) |
| 59 | |
| 60 | // Swap key to i+1 iff its i. |
| 61 | for i := 0; i < 10; i++ { |
| 62 | err = client.CAS(ctx, key, func(in interface{}) (interface{}, bool, error) { |
| 63 | require.EqualValues(t, strconv.Itoa(i), in) |
| 64 | return strconv.Itoa(i + 1), true, nil |
| 65 | }) |
| 66 | require.NoError(t, err) |
| 67 | } |
| 68 | |
| 69 | // Make sure the CASes left the right value - "10". |
| 70 | value, err := client.Get(ctx, key) |
| 71 | require.NoError(t, err) |
| 72 | require.EqualValues(t, "10", value) |
| 73 | }) |
| 74 | } |
| 75 | |
| 76 | // TestNilCAS ensures we can return nil from the CAS callback when we don't |
| 77 | // want to modify the value. |
nothing calls this directly
no test coverage detected