forked from ha/doozerd
/
conn_test.go
41 lines (35 loc) · 1.05 KB
/
conn_test.go
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
package server
import (
"github.com/bmizerany/assert"
"github.com/kr/pretty"
"testing"
)
type grantTest struct {
c *conn
sk string
r bool
w bool
ok bool
}
var grantTests = []grantTest{
// same
{&conn{rosk: "p", rwsk: "p"}, "x", false, false, false},
{&conn{rosk: "p", rwsk: "p"}, "p", true, true, true},
// different
{&conn{rosk: "a", rwsk: "b"}, "x", false, false, false},
{&conn{rosk: "a", rwsk: "b"}, "a", true, false, true},
{&conn{rosk: "a", rwsk: "b"}, "b", true, true, true},
// test blank passwords explicitly; the rules are
// the same as above, but this is a common case
{&conn{rosk: "", rwsk: ""}, "", true, true, true},
{&conn{rosk: "", rwsk: "b"}, "", true, false, true},
{&conn{rosk: "", rwsk: "b"}, "b", true, true, true},
}
func TestConnGrant(t *testing.T) {
for _, tst := range grantTests {
ok := tst.c.grant(tst.sk)
assert.Equalf(t, tst.ok, ok, "%# v", pretty.Formatter(tst))
assert.Equalf(t, tst.r, tst.c.raccess, "%# v", pretty.Formatter(tst))
assert.Equalf(t, tst.w, tst.c.waccess, "%# v", pretty.Formatter(tst))
}
}