4 "git.curoverse.com/arvados.git/sdk/go/arvados"
5 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
6 check "gopkg.in/check.v1"
9 var _ = check.Suite(&permSuite{})
11 type permSuite struct{}
13 func (s *permSuite) TestCheck(c *check.C) {
14 pc := newPermChecker(*(arvados.NewClientFromEnv())).(*cachingPermChecker)
15 setToken := func(label, token string) {
16 c.Logf("...%s token %q", label, token)
19 wantError := func(uuid string) {
21 ok, err := pc.Check(uuid)
22 c.Check(ok, check.Equals, false)
23 c.Check(err, check.NotNil)
25 wantYes := func(uuid string) {
27 ok, err := pc.Check(uuid)
28 c.Check(ok, check.Equals, true)
29 c.Check(err, check.IsNil)
31 wantNo := func(uuid string) {
33 ok, err := pc.Check(uuid)
34 c.Check(ok, check.Equals, false)
35 c.Check(err, check.IsNil)
39 wantNo(arvadostest.UserAgreementCollection)
40 wantNo(arvadostest.UserAgreementPDH)
41 wantNo(arvadostest.FooBarDirCollection)
43 setToken("anonymous", arvadostest.AnonymousToken)
44 wantYes(arvadostest.UserAgreementCollection)
45 wantYes(arvadostest.UserAgreementPDH)
46 wantNo(arvadostest.FooBarDirCollection)
47 wantNo(arvadostest.FooCollection)
49 setToken("active", arvadostest.ActiveToken)
50 wantYes(arvadostest.UserAgreementCollection)
51 wantYes(arvadostest.UserAgreementPDH)
52 wantYes(arvadostest.FooBarDirCollection)
53 wantYes(arvadostest.FooCollection)
55 setToken("admin", arvadostest.AdminToken)
56 wantYes(arvadostest.UserAgreementCollection)
57 wantYes(arvadostest.UserAgreementPDH)
58 wantYes(arvadostest.FooBarDirCollection)
59 wantYes(arvadostest.FooCollection)
61 // hack to empty the cache
63 pc.SetToken(arvadostest.ActiveToken)
65 c.Log("...network error")
66 pc.Client.APIHost = "127.0.0.1:discard"
67 wantError(arvadostest.UserAgreementCollection)
68 wantError(arvadostest.FooBarDirCollection)
70 c.Logf("%d checks, %d misses, %d invalid, %d cached", pc.nChecks, pc.nMisses, pc.nInvalid, len(pc.cache))