(t *testing.T, c *Client)
| 169 | } |
| 170 | |
| 171 | func 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 | } |
no test coverage detected
searching dependent graphs…