MCPcopy
hub / github.com/bradfitz/gomemcache / testWithClient

Function testWithClient

memcache/memcache_test.go:171–349  ·  view source on GitHub ↗
(t *testing.T, c *Client)

Source from the content-addressed store, hash-verified

169}
170
171func testWithClient(t *testing.T, c *Client) {
172 checkErr := func(err error, format string, args ...interface{}) {
173 t.Helper()
174 if err != nil {
175 t.Fatalf(format, args...)
176 }
177 }
178 mustSet := mustSetF(t, c)
179
180 // Set
181 foo := &Item{Key: "foo", Value: []byte("fooval-fromset"), Flags: 123}
182 err := c.Set(foo)
183 checkErr(err, "first set(foo): %v", err)
184 err = c.Set(foo)
185 checkErr(err, "second set(foo): %v", err)
186
187 // CompareAndSwap
188 it, err := c.Get("foo")
189 checkErr(err, "get(foo): %v", err)
190 if string(it.Value) != "fooval-fromset" {
191 t.Errorf("get(foo) Value = %q, want fooval-romset", it.Value)
192 }
193 it0, err := c.Get("foo") // another get, to fail our CAS later
194 checkErr(err, "get(foo): %v", err)
195 it.Value = []byte("fooval")
196 err = c.CompareAndSwap(it)
197 checkErr(err, "cas(foo): %v", err)
198 it0.Value = []byte("should-fail")
199 if err := c.CompareAndSwap(it0); err != ErrCASConflict {
200 t.Fatalf("cas(foo) error = %v; want ErrCASConflict", err)
201 }
202
203 // Get
204 it, err = c.Get("foo")
205 checkErr(err, "get(foo): %v", err)
206 if it.Key != "foo" {
207 t.Errorf("get(foo) Key = %q, want foo", it.Key)
208 }
209 if string(it.Value) != "fooval" {
210 t.Errorf("get(foo) Value = %q, want fooval", it.Value)
211 }
212 if it.Flags != 123 {
213 t.Errorf("get(foo) Flags = %v, want 123", it.Flags)
214 }
215
216 // Get and set a unicode key
217 quxKey := "Hello_世界"
218 qux := &Item{Key: quxKey, Value: []byte("hello world")}
219 err = c.Set(qux)
220 checkErr(err, "first set(Hello_世界): %v", err)
221 it, err = c.Get(quxKey)
222 checkErr(err, "get(Hello_世界): %v", err)
223 if it.Key != quxKey {
224 t.Errorf("get(Hello_世界) Key = %q, want Hello_世界", it.Key)
225 }
226 if string(it.Value) != "hello world" {
227 t.Errorf("get(Hello_世界) Value = %q, want hello world", string(it.Value))
228 }

Callers 4

TestLocalhostFunction · 0.85
TestUnixSocketFunction · 0.85
TestFakeServerFunction · 0.85
TestTLSFunction · 0.85

Calls 15

mustSetFFunction · 0.85
testTouchWithClientFunction · 0.85
SetMethod · 0.80
GetMethod · 0.80
CompareAndSwapMethod · 0.80
AddMethod · 0.80
AppendMethod · 0.80
PrependMethod · 0.80
ReplaceMethod · 0.80
GetMultiMethod · 0.80
DeleteMethod · 0.80
IncrementMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…