{"action":"created","comment":{"url":"https://api.github.com/repos/ory-am/ladon/pulls/comments/52722968","id":52722968,"diff_hunk":"@@ -0,0 +1,129 @@\n+package rethinkdb\n+\n+import (\n+\t\"time\"\n+\n+\trdb \"github.com/dancannon/gorethink\"\n+\n+\t\"log\"\n+\t\"os\"\n+\t\"testing\"\n+\n+\t\"github.com/ory-am/common/pkg\"\n+\t\"github.com/ory-am/ladon/policy\"\n+\t\"github.com/pborman/uuid\"\n+\t\"github.com/stretchr/testify/assert\"\n+\t\"github.com/stretchr/testify/require\"\n+\t\"gopkg.in/ory-am/dockertest.v2\"\n+)\n+\n+var session *rdb.Session\n+var s *Store\n+\n+var conditions = []policy.DefaultCondition{\n+\t{Operator: \"foo\", Extra: map[string]interface{}{\"bar\": \"baz\"}},\n+\t{Operator: \"bar\", Extra: map[string]interface{}{\"foo\": \"baz\"}},\n+}\n+\n+var cases = []*policy.DefaultPolicy{\n+\t{uuid.New(), \"description\", []string{\"user\", \"anonymous\"}, policy.AllowAccess, []string{\"article\", \"user\"}, []string{\"create\", \"update\"}, conditions},\n+\t{uuid.New(), \"description\", []string{}, policy.AllowAccess, []string{\"<article|user>\"}, []string{\"view\"}, nil},\n+\t{uuid.New(), \"description\", []string{\"<peter|max>\"}, policy.DenyAccess, []string{\"article\", \"user\"}, []string{\"view\"}, conditions},\n+\t{uuid.New(), \"description\", []string{\"<user|max|anonymous>\", \"peter\"}, policy.DenyAccess, []string{\".*\"}, []string{\"disable\"}, conditions},\n+\t{uuid.New(), \"description\", []string{\"<.*>\"}, policy.AllowAccess, []string{\"<article|user>\"}, []string{\"view\"}, conditions},\n+\t{uuid.New(), \"description\", []string{\"<us[er]+>\"}, policy.AllowAccess, []string{\"<article|user>\"}, []string{\"view\"}, conditions},\n+}\n+\n+func TestMain(m *testing.M) {\n+\tc, err := dockertest.ConnectToRethinkDB(20, time.Second, func(url string) bool {\n+\t\trdbSession, err := rdb.Connect(rdb.ConnectOpts{\n+\t\t\tAddress:  url,\n+\t\t\tDatabase: \"hydra\"})\n+\t\tif err != nil {\n+\t\t\treturn false\n+\t\t}\n+\n+\t\t_, err = rdb.DBCreate(\"hydra\").RunWrite(rdbSession)\n+\t\tif err != nil {\n+\t\t\treturn false\n+\t\t}\n+\n+\t\ts = New(rdbSession)\n+\n+\t\tif err := s.CreateTables(); err != nil {\n+\t\t\treturn false\n+\t\t}\n+\n+\t\tsession = rdbSession\n+\n+\t\treturn true\n+\t})\n+\n+\tif err != nil {\n+\t\tlog.Fatalf(\"Could not connect to database: %s\", err)\n+\t}\n+\n+\tretCode := m.Run()\n+\n+\t// force teardown\n+\ttearDown(session, c)\n+\n+\tos.Exit(retCode)\n+}\n+\n+func tearDown(session *rdb.Session, c dockertest.ContainerID) {\n+\tdefer session.Close()\n+\tc.KillRemove()\n+}\n+\n+func TestCreateErrors(t *testing.T) {\n+\tassert.NotNil(t, &policy.DefaultPolicy{ID: \"invalid-format\"})\n+}\n+\n+func TestGetErrors(t *testing.T) {\n+\t_, err := s.Get(uuid.New())\n+\tassert.Equal(t, pkg.ErrNotFound, err)\n+\t_, err = s.Get(\"asdf\")\n+\tassert.NotNil(t, err)\n+}\n+\n+func TestCreateGetDelete(t *testing.T) {\n+\tfor _, c := range cases {\n+\t\terr := s.Create(c)\n+\t\tassert.Nil(t, err)\n+\n+\t\tget, err := s.Get(c.GetID())\n+\t\tassert.Nil(t, err)\n+\t\tpkg.AssertObjectKeysEqual(t, c, get, \"Description\", \"Subjects\", \"Resources\", \"Effect\", \"Permissions\")\n+\t\tassert.Equal(t, len(c.Conditions), len(get.GetConditions()))\n+\t\t//assert.True(t, reflect.DeepEqual(c, get), \"%v does not equal %v\", c, get)\n+\t}\n+\n+\tfor _, c := range cases {\n+\t\tassert.Nil(t, s.Delete(c.GetID()))\n+\t\t_, err := s.Get(c.GetID())\n+\t\tassert.NotNil(t, err)\n+\t}\n+}\n+\n+func TestFindPoliciesForSubject(t *testing.T) {\n+\tfor _, c := range cases {\n+\t\trequire.Nil(t, s.Create(c))\n+\t}\n+\n+\tpolicies, err := s.FindPoliciesForSubject(\"user\")\n+\tassert.Nil(t, err)\n+\tassert.Equal(t, 5, len(policies))\n+\n+\tpolicies, err = s.FindPoliciesForSubject(\"USER\")","path":"policy/rethinkdb/rethinkdb_test.go","position":117,"original_position":118,"commit_id":"3610bfc9ceebacb6cb73670ba50e6f44a63be309","original_commit_id":"10602f665f76199e1a2aafe6138731ee907da101","user":{"login":"arekkas","id":3372410,"avatar_url":"https://avatars.githubusercontent.com/u/3372410?v=3","gravatar_id":"","url":"https://api.github.com/users/arekkas","html_url":"https://github.com/arekkas","followers_url":"https://api.github.com/users/arekkas/followers","following_url":"https://api.github.com/users/arekkas/following{/other_user}","gists_url":"https://api.github.com/users/arekkas/gists{/gist_id}","starred_url":"https://api.github.com/users/arekkas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arekkas/subscriptions","organizations_url":"https://api.github.com/users/arekkas/orgs","repos_url":"https://api.github.com/users/arekkas/repos","events_url":"https://api.github.com/users/arekkas/events{/privacy}","received_events_url":"https://api.github.com/users/arekkas/received_events","type":"User","site_admin":false},"body":":tada: ","created_at":"2016-02-12T10:01:49Z","updated_at":"2016-02-12T10:01:49Z","html_url":"https://github.com/ory-am/ladon/pull/10#discussion_r52722968","pull_request_url":"https://api.github.com/repos/ory-am/ladon/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/ory-am/ladon/pulls/comments/52722968"},"html":{"href":"https://github.com/ory-am/ladon/pull/10#discussion_r52722968"},"pull_request":{"href":"https://api.github.com/repos/ory-am/ladon/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/ory-am/ladon/pulls/10","id":58998533,"html_url":"https://github.com/ory-am/ladon/pull/10","diff_url":"https://github.com/ory-am/ladon/pull/10.diff","patch_url":"https://github.com/ory-am/ladon/pull/10.patch","issue_url":"https://api.github.com/repos/ory-am/ladon/issues/10","number":10,"state":"open","locked":false,"title":"Rethinkdb added :)","user":{"login":"leetal","id":1221839,"avatar_url":"https://avatars.githubusercontent.com/u/1221839?v=3","gravatar_id":"","url":"https://api.github.com/users/leetal","html_url":"https://github.com/leetal","followers_url":"https://api.github.com/users/leetal/followers","following_url":"https://api.github.com/users/leetal/following{/other_user}","gists_url":"https://api.github.com/users/leetal/gists{/gist_id}","starred_url":"https://api.github.com/users/leetal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leetal/subscriptions","organizations_url":"https://api.github.com/users/leetal/orgs","repos_url":"https://api.github.com/users/leetal/repos","events_url":"https://api.github.com/users/leetal/events{/privacy}","received_events_url":"https://api.github.com/users/leetal/received_events","type":"User","site_admin":false},"body":"@arekkas All tests pass and I've more or less ripped the tests you had for Postgres ;)","created_at":"2016-02-11T07:27:40Z","updated_at":"2016-02-12T10:01:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"294d0c798b38627f51f42bf25ee4d856b9806182","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ory-am/ladon/pulls/10/commits","review_comments_url":"https://api.github.com/repos/ory-am/ladon/pulls/10/comments","review_comment_url":"https://api.github.com/repos/ory-am/ladon/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ory-am/ladon/issues/10/comments","statuses_url":"https://api.github.com/repos/ory-am/ladon/statuses/3610bfc9ceebacb6cb73670ba50e6f44a63be309","head":{"label":"leetal:rethinkdb","ref":"rethinkdb","sha":"3610bfc9ceebacb6cb73670ba50e6f44a63be309","user":{"login":"leetal","id":1221839,"avatar_url":"https://avatars.githubusercontent.com/u/1221839?v=3","gravatar_id":"","url":"https://api.github.com/users/leetal","html_url":"https://github.com/leetal","followers_url":"https://api.github.com/users/leetal/followers","following_url":"https://api.github.com/users/leetal/following{/other_user}","gists_url":"https://api.github.com/users/leetal/gists{/gist_id}","starred_url":"https://api.github.com/users/leetal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leetal/subscriptions","organizations_url":"https://api.github.com/users/leetal/orgs","repos_url":"https://api.github.com/users/leetal/repos","events_url":"https://api.github.com/users/leetal/events{/privacy}","received_events_url":"https://api.github.com/users/leetal/received_events","type":"User","site_admin":false},"repo":{"id":51317919,"name":"ladon","full_name":"leetal/ladon","owner":{"login":"leetal","id":1221839,"avatar_url":"https://avatars.githubusercontent.com/u/1221839?v=3","gravatar_id":"","url":"https://api.github.com/users/leetal","html_url":"https://github.com/leetal","followers_url":"https://api.github.com/users/leetal/followers","following_url":"https://api.github.com/users/leetal/following{/other_user}","gists_url":"https://api.github.com/users/leetal/gists{/gist_id}","starred_url":"https://api.github.com/users/leetal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leetal/subscriptions","organizations_url":"https://api.github.com/users/leetal/orgs","repos_url":"https://api.github.com/users/leetal/repos","events_url":"https://api.github.com/users/leetal/events{/privacy}","received_events_url":"https://api.github.com/users/leetal/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/leetal/ladon","description":"Ladon guards your resources.  A twelve-factor (12factor) Policy Decision Point with management capabilities written in Go. Backed by PostgreSQL","fork":true,"url":"https://api.github.com/repos/leetal/ladon","forks_url":"https://api.github.com/repos/leetal/ladon/forks","keys_url":"https://api.github.com/repos/leetal/ladon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/leetal/ladon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/leetal/ladon/teams","hooks_url":"https://api.github.com/repos/leetal/ladon/hooks","issue_events_url":"https://api.github.com/repos/leetal/ladon/issues/events{/number}","events_url":"https://api.github.com/repos/leetal/ladon/events","assignees_url":"https://api.github.com/repos/leetal/ladon/assignees{/user}","branches_url":"https://api.github.com/repos/leetal/ladon/branches{/branch}","tags_url":"https://api.github.com/repos/leetal/ladon/tags","blobs_url":"https://api.github.com/repos/leetal/ladon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/leetal/ladon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/leetal/ladon/git/refs{/sha}","trees_url":"https://api.github.com/repos/leetal/ladon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/leetal/ladon/statuses/{sha}","languages_url":"https://api.github.com/repos/leetal/ladon/languages","stargazers_url":"https://api.github.com/repos/leetal/ladon/stargazers","contributors_url":"https://api.github.com/repos/leetal/ladon/contributors","subscribers_url":"https://api.github.com/repos/leetal/ladon/subscribers","subscription_url":"https://api.github.com/repos/leetal/ladon/subscription","commits_url":"https://api.github.com/repos/leetal/ladon/commits{/sha}","git_commits_url":"https://api.github.com/repos/leetal/ladon/git/commits{/sha}","comments_url":"https://api.github.com/repos/leetal/ladon/comments{/number}","issue_comment_url":"https://api.github.com/repos/leetal/ladon/issues/comments{/number}","contents_url":"https://api.github.com/repos/leetal/ladon/contents/{+path}","compare_url":"https://api.github.com/repos/leetal/ladon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/leetal/ladon/merges","archive_url":"https://api.github.com/repos/leetal/ladon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/leetal/ladon/downloads","issues_url":"https://api.github.com/repos/leetal/ladon/issues{/number}","pulls_url":"https://api.github.com/repos/leetal/ladon/pulls{/number}","milestones_url":"https://api.github.com/repos/leetal/ladon/milestones{/number}","notifications_url":"https://api.github.com/repos/leetal/ladon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/leetal/ladon/labels{/name}","releases_url":"https://api.github.com/repos/leetal/ladon/releases{/id}","deployments_url":"https://api.github.com/repos/leetal/ladon/deployments","created_at":"2016-02-08T18:40:48Z","updated_at":"2016-02-08T18:40:49Z","pushed_at":"2016-02-12T09:55:46Z","git_url":"git://github.com/leetal/ladon.git","ssh_url":"git@github.com:leetal/ladon.git","clone_url":"https://github.com/leetal/ladon.git","svn_url":"https://github.com/leetal/ladon","homepage":"https://ory.am","size":41,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ory-am:master","ref":"master","sha":"62f32d97b748d99af1a18797462ac09253901f89","user":{"login":"ory-am","id":10667373,"avatar_url":"https://avatars.githubusercontent.com/u/10667373?v=3","gravatar_id":"","url":"https://api.github.com/users/ory-am","html_url":"https://github.com/ory-am","followers_url":"https://api.github.com/users/ory-am/followers","following_url":"https://api.github.com/users/ory-am/following{/other_user}","gists_url":"https://api.github.com/users/ory-am/gists{/gist_id}","starred_url":"https://api.github.com/users/ory-am/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ory-am/subscriptions","organizations_url":"https://api.github.com/users/ory-am/orgs","repos_url":"https://api.github.com/users/ory-am/repos","events_url":"https://api.github.com/users/ory-am/events{/privacy}","received_events_url":"https://api.github.com/users/ory-am/received_events","type":"Organization","site_admin":false},"repo":{"id":44393602,"name":"ladon","full_name":"ory-am/ladon","owner":{"login":"ory-am","id":10667373,"avatar_url":"https://avatars.githubusercontent.com/u/10667373?v=3","gravatar_id":"","url":"https://api.github.com/users/ory-am","html_url":"https://github.com/ory-am","followers_url":"https://api.github.com/users/ory-am/followers","following_url":"https://api.github.com/users/ory-am/following{/other_user}","gists_url":"https://api.github.com/users/ory-am/gists{/gist_id}","starred_url":"https://api.github.com/users/ory-am/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ory-am/subscriptions","organizations_url":"https://api.github.com/users/ory-am/orgs","repos_url":"https://api.github.com/users/ory-am/repos","events_url":"https://api.github.com/users/ory-am/events{/privacy}","received_events_url":"https://api.github.com/users/ory-am/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ory-am/ladon","description":"Ladon guards your resources.  A twelve-factor (12factor) Policy Decision Point with management capabilities written in Go. Backed by PostgreSQL","fork":false,"url":"https://api.github.com/repos/ory-am/ladon","forks_url":"https://api.github.com/repos/ory-am/ladon/forks","keys_url":"https://api.github.com/repos/ory-am/ladon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ory-am/ladon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ory-am/ladon/teams","hooks_url":"https://api.github.com/repos/ory-am/ladon/hooks","issue_events_url":"https://api.github.com/repos/ory-am/ladon/issues/events{/number}","events_url":"https://api.github.com/repos/ory-am/ladon/events","assignees_url":"https://api.github.com/repos/ory-am/ladon/assignees{/user}","branches_url":"https://api.github.com/repos/ory-am/ladon/branches{/branch}","tags_url":"https://api.github.com/repos/ory-am/ladon/tags","blobs_url":"https://api.github.com/repos/ory-am/ladon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ory-am/ladon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ory-am/ladon/git/refs{/sha}","trees_url":"https://api.github.com/repos/ory-am/ladon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ory-am/ladon/statuses/{sha}","languages_url":"https://api.github.com/repos/ory-am/ladon/languages","stargazers_url":"https://api.github.com/repos/ory-am/ladon/stargazers","contributors_url":"https://api.github.com/repos/ory-am/ladon/contributors","subscribers_url":"https://api.github.com/repos/ory-am/ladon/subscribers","subscription_url":"https://api.github.com/repos/ory-am/ladon/subscription","commits_url":"https://api.github.com/repos/ory-am/ladon/commits{/sha}","git_commits_url":"https://api.github.com/repos/ory-am/ladon/git/commits{/sha}","comments_url":"https://api.github.com/repos/ory-am/ladon/comments{/number}","issue_comment_url":"https://api.github.com/repos/ory-am/ladon/issues/comments{/number}","contents_url":"https://api.github.com/repos/ory-am/ladon/contents/{+path}","compare_url":"https://api.github.com/repos/ory-am/ladon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ory-am/ladon/merges","archive_url":"https://api.github.com/repos/ory-am/ladon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ory-am/ladon/downloads","issues_url":"https://api.github.com/repos/ory-am/ladon/issues{/number}","pulls_url":"https://api.github.com/repos/ory-am/ladon/pulls{/number}","milestones_url":"https://api.github.com/repos/ory-am/ladon/milestones{/number}","notifications_url":"https://api.github.com/repos/ory-am/ladon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ory-am/ladon/labels{/name}","releases_url":"https://api.github.com/repos/ory-am/ladon/releases{/id}","deployments_url":"https://api.github.com/repos/ory-am/ladon/deployments","created_at":"2015-10-16T15:21:28Z","updated_at":"2016-02-04T05:23:27Z","pushed_at":"2016-02-12T09:55:46Z","git_url":"git://github.com/ory-am/ladon.git","ssh_url":"git@github.com:ory-am/ladon.git","clone_url":"https://github.com/ory-am/ladon.git","svn_url":"https://github.com/ory-am/ladon","homepage":"https://ory.am","size":24,"stargazers_count":43,"watchers_count":43,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":1,"forks":6,"open_issues":1,"watchers":43,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ory-am/ladon/pulls/10"},"html":{"href":"https://github.com/ory-am/ladon/pull/10"},"issue":{"href":"https://api.github.com/repos/ory-am/ladon/issues/10"},"comments":{"href":"https://api.github.com/repos/ory-am/ladon/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/ory-am/ladon/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/ory-am/ladon/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ory-am/ladon/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/ory-am/ladon/statuses/3610bfc9ceebacb6cb73670ba50e6f44a63be309"}}}}