forked from memcachier/mc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_test.go
More file actions
90 lines (80 loc) · 2.13 KB
/
utils_test.go
File metadata and controls
90 lines (80 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package mc
import (
"bytes"
"compress/zlib"
"io"
"reflect"
"strings"
"testing"
)
// start connection
func testInitCompress(t *testing.T) *Client {
config := DefaultConfig()
config.Compression.compress = func(value string) (string, error) {
var compressedValue bytes.Buffer
zw, err := zlib.NewWriterLevel(&compressedValue, -1)
if err != nil {
return value, err
}
if _, err = zw.Write([]byte(value)); err != nil {
return value, err
}
zw.Close()
return compressedValue.String(), nil
}
config.Compression.decompress = func(value string) (string, error) {
if value == "" {
return value, nil
}
zr, err := zlib.NewReader(strings.NewReader(value))
if err != nil {
return value, err
}
defer zr.Close()
var unCompressedValue bytes.Buffer
_, err = io.Copy(&unCompressedValue, zr)
if err != nil {
return value, err
}
return unCompressedValue.String(), nil
}
c := NewMCwithConfig(mcAddr, user, pass, config)
err := c.Flush(0)
assertEqualf(t, nil, err, "unexpected error during initial flush: %v", err)
return c
}
// start connection
func testInit(t *testing.T) *Client {
c := NewMC(mcAddr, user, pass)
err := c.Flush(0)
assertEqualf(t, nil, err, "unexpected error during initial flush: %v", err)
return c
}
// start connection
func testInitMultiNode(t *testing.T, servers, username, password string) *Client {
c := NewMC(servers, user, pass)
err := c.Flush(0)
assertEqualf(t, nil, err, "unexpected error during initial flush: %v", err)
return c
}
// TODO: asserts gives just the location of FailNow, more of a stack trace would be nice
func assertEqualf(t *testing.T, exp, got interface{}, format string, args ...interface{}) {
if !reflect.DeepEqual(exp, got) {
t.Errorf(format, args...)
t.Errorf("expected: %v", exp)
t.Errorf("got: %v", got)
t.FailNow()
}
}
func assertNotEqualf(t *testing.T, exp, got interface{}, format string, args ...interface{}) {
if reflect.DeepEqual(exp, got) {
t.Errorf(format, args...)
t.Errorf("did not expect: %v", exp)
t.FailNow()
}
}
func assertTruef(t *testing.T, res bool, format string, args ...interface{}) {
if !res {
t.Fatalf(format, args...)
}
}