diff options
-rw-r--r-- | integrations/api_repo_test.go | 2 | ||||
-rw-r--r-- | models/access_test.go | 2 | ||||
-rw-r--r-- | models/fixture_access_test.go | 52 | ||||
-rw-r--r-- | models/fixtures/access.yml | 109 | ||||
-rw-r--r-- | models/fixtures/collaboration.yml | 24 | ||||
-rw-r--r-- | models/fixtures/repo_unit.yml | 37 |
6 files changed, 187 insertions, 39 deletions
diff --git a/integrations/api_repo_test.go b/integrations/api_repo_test.go index 715fc629aa..ff59fac5cb 100644 --- a/integrations/api_repo_test.go +++ b/integrations/api_repo_test.go @@ -231,7 +231,7 @@ func TestAPIOrgRepos(t *testing.T) { includesPrivate bool }{ nil: {count: 1}, - user: {count: 2, includesPrivate: true}, + user: {count: 3, includesPrivate: true}, user2: {count: 3, includesPrivate: true}, user3: {count: 1}, } diff --git a/models/access_test.go b/models/access_test.go index 103fe3a688..c134ab98d8 100644 --- a/models/access_test.go +++ b/models/access_test.go @@ -112,7 +112,7 @@ func TestUser_GetAccessibleRepositories(t *testing.T) { user2 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) repos, err = user2.GetAccessibleRepositories(0) assert.NoError(t, err) - assert.Len(t, repos, 1) + assert.Len(t, repos, 4) user29 := AssertExistsAndLoadBean(t, &User{ID: 29}).(*User) repos, err = user29.GetAccessibleRepositories(0) diff --git a/models/fixture_access_test.go b/models/fixture_access_test.go new file mode 100644 index 0000000000..9a50d24d7c --- /dev/null +++ b/models/fixture_access_test.go @@ -0,0 +1,52 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +// +build access_fixtures + +package models + +// This file is excluded from build and tests, and is intended for assisting +// in keeping access.yml in sync with the other .yml files. + +// To use it, do: +// cd models +// go test -tags "access_fixtures sqlite sqlite_unlock_notify" -run TestBuildAccessFixturesYaml + +import ( + "bufio" + "fmt" + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestBuildAccessFixturesYaml(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + + repos := make([]*Repository, 0, 50) + assert.NoError(t, x.Find(&repos)) + for _, repo := range repos { + repo.MustOwner() + assert.NoError(t, repo.RecalculateAccesses()) + } + + f, err := os.Create("fixtures/access.yml") + assert.NoError(t, err) + w := bufio.NewWriter(f) + + accesses := make([]*Access, 0, 200) + assert.NoError(t, x.OrderBy("user_id, repo_id").Find(&accesses)) + for i, a := range accesses { + fmt.Fprintf(w, "-\n") + fmt.Fprintf(w, " id: %d\n", i+1) + fmt.Fprintf(w, " user_id: %d\n", a.UserID) + fmt.Fprintf(w, " repo_id: %d\n", a.RepoID) + fmt.Fprintf(w, " mode: %d\n", a.Mode) + fmt.Fprintf(w, "\n") + } + + w.Flush() + f.Close() +} diff --git a/models/fixtures/access.yml b/models/fixtures/access.yml index 811720c8e4..4027e5fe92 100644 --- a/models/fixtures/access.yml +++ b/models/fixtures/access.yml @@ -2,88 +2,125 @@ id: 1 user_id: 2 repo_id: 3 - mode: 2 # write + mode: 4 - id: 2 - user_id: 4 - repo_id: 4 - mode: 2 # write + user_id: 2 + repo_id: 5 + mode: 4 - id: 3 - user_id: 4 - repo_id: 3 - mode: 2 # write + user_id: 2 + repo_id: 24 + mode: 2 - id: 4 - user_id: 15 - repo_id: 22 - mode: 2 # write + user_id: 2 + repo_id: 32 + mode: 4 - id: 5 + user_id: 4 + repo_id: 3 + mode: 2 + +- + id: 6 + user_id: 4 + repo_id: 4 + mode: 2 + +- + id: 7 + user_id: 4 + repo_id: 40 + mode: 2 + +- + id: 8 user_id: 15 repo_id: 21 - mode: 2 # write + mode: 2 - - id: 6 + id: 9 + user_id: 15 + repo_id: 22 + mode: 2 + +- + id: 10 user_id: 15 repo_id: 23 - mode: 4 # owner + mode: 4 - - id: 7 + id: 11 user_id: 15 repo_id: 24 - mode: 4 # owner + mode: 4 - - id: 8 - user_id: 18 - repo_id: 23 - mode: 4 # owner + id: 12 + user_id: 15 + repo_id: 32 + mode: 2 - - id: 9 + id: 13 user_id: 18 - repo_id: 24 - mode: 4 # owner + repo_id: 21 + mode: 2 - - id: 10 + id: 14 user_id: 18 repo_id: 22 - mode: 2 # write + mode: 2 - - id: 11 + id: 15 user_id: 18 - repo_id: 21 - mode: 2 # write + repo_id: 23 + mode: 4 - - id: 12 + id: 16 + user_id: 18 + repo_id: 24 + mode: 4 + +- + id: 17 + user_id: 20 + repo_id: 24 + mode: 1 + +- + id: 18 user_id: 20 repo_id: 27 - mode: 4 # owner - + mode: 4 + - - id: 13 + id: 19 user_id: 20 repo_id: 28 - mode: 4 # owner + mode: 4 - - id: 14 + id: 20 user_id: 29 repo_id: 4 - mode: 2 # write (collaborator) + mode: 2 - - id: 15 + id: 21 user_id: 29 repo_id: 24 - mode: 1 # read + mode: 1 + diff --git a/models/fixtures/collaboration.yml b/models/fixtures/collaboration.yml index 82d46f38f0..ef77d22b24 100644 --- a/models/fixtures/collaboration.yml +++ b/models/fixtures/collaboration.yml @@ -21,3 +21,27 @@ repo_id: 4 user_id: 29 mode: 2 # write + +- + id: 5 + repo_id: 21 + user_id: 15 + mode: 2 # write + +- + id: 6 + repo_id: 21 + user_id: 18 + mode: 2 # write + +- + id: 7 + repo_id: 22 + user_id: 15 + mode: 2 # write + +- + id: 8 + repo_id: 22 + user_id: 18 + mode: 2 # write diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml index 5ced38b003..35b9b92b79 100644 --- a/models/fixtures/repo_unit.yml +++ b/models/fixtures/repo_unit.yml @@ -478,4 +478,39 @@ repo_id: 2 type: 2 config: "{}" - created_unix: 946684810
\ No newline at end of file + created_unix: 946684810 + +- + id: 70 + repo_id: 5 + type: 4 + config: "{}" + created_unix: 946684810 + +- + id: 71 + repo_id: 5 + type: 5 + config: "{}" + created_unix: 946684810 + +- + id: 72 + repo_id: 5 + type: 1 + config: "{}" + created_unix: 946684810 + +- + id: 73 + repo_id: 5 + type: 2 + config: "{\"EnableTimetracker\":true,\"AllowOnlyContributorsToTrackTime\":true}" + created_unix: 946684810 + +- + id: 74 + repo_id: 5 + type: 3 + config: "{\"IgnoreWhitespaceConflicts\":false,\"AllowMerge\":true,\"AllowRebase\":true,\"AllowRebaseMerge\":true,\"AllowSquash\":true}" + created_unix: 946684810 |