MCPcopy
hub / github.com/grafana/dskit / TestNilCAS

Function TestNilCAS

kv/kv_test.go:78–98  ·  view source on GitHub ↗

TestNilCAS ensures we can return nil from the CAS callback when we don't want to modify the value.

(t *testing.T)

Source from the content-addressed store, hash-verified

76// TestNilCAS ensures we can return nil from the CAS callback when we don't
77// want to modify the value.
78func TestNilCAS(t *testing.T) {
79 withFixtures(t, func(t *testing.T, client Client) {
80 // Blindly set key to "0".
81 err := client.CAS(ctx, key, func(interface{}) (interface{}, bool, error) {
82 return "0", true, nil
83 })
84 require.NoError(t, err)
85
86 // Ensure key is "0" and don't set it.
87 err = client.CAS(ctx, key, func(in interface{}) (interface{}, bool, error) {
88 require.EqualValues(t, "0", in)
89 return nil, false, nil
90 })
91 require.NoError(t, err)
92
93 // Make sure value is still 0.
94 value, err := client.Get(ctx, key)
95 require.NoError(t, err)
96 require.EqualValues(t, "0", value)
97 })
98}
99
100func TestWatchKey(t *testing.T) {
101 const key = "test"

Callers

nothing calls this directly

Calls 3

withFixturesFunction · 0.70
CASMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected