Fix "access" fixtures and tests (#10247)

* Add fixture gen tool and fix "access" test

* Close file before exiting

* Add missing repo_unit for repo id: 5

* Fix count on TestAPIOrgRepos

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
tokarchuk/v1.17
guillep2k 5 years ago committed by GitHub
parent a97fe76950
commit 62a1322cf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      integrations/api_repo_test.go
  2. 2
      models/access_test.go
  3. 52
      models/fixture_access_test.go
  4. 107
      models/fixtures/access.yml
  5. 24
      models/fixtures/collaboration.yml
  6. 35
      models/fixtures/repo_unit.yml

@ -231,7 +231,7 @@ func TestAPIOrgRepos(t *testing.T) {
includesPrivate bool includesPrivate bool
}{ }{
nil: {count: 1}, nil: {count: 1},
user: {count: 2, includesPrivate: true}, user: {count: 3, includesPrivate: true},
user2: {count: 3, includesPrivate: true}, user2: {count: 3, includesPrivate: true},
user3: {count: 1}, user3: {count: 1},
} }

@ -112,7 +112,7 @@ func TestUser_GetAccessibleRepositories(t *testing.T) {
user2 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) user2 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
repos, err = user2.GetAccessibleRepositories(0) repos, err = user2.GetAccessibleRepositories(0)
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, repos, 1) assert.Len(t, repos, 4)
user29 := AssertExistsAndLoadBean(t, &User{ID: 29}).(*User) user29 := AssertExistsAndLoadBean(t, &User{ID: 29}).(*User)
repos, err = user29.GetAccessibleRepositories(0) repos, err = user29.GetAccessibleRepositories(0)

@ -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()
}

@ -2,88 +2,125 @@
id: 1 id: 1
user_id: 2 user_id: 2
repo_id: 3 repo_id: 3
mode: 2 # write mode: 4
- -
id: 2 id: 2
user_id: 4 user_id: 2
repo_id: 4 repo_id: 5
mode: 2 # write mode: 4
- -
id: 3 id: 3
user_id: 4 user_id: 2
repo_id: 3 repo_id: 24
mode: 2 # write mode: 2
- -
id: 4 id: 4
user_id: 15 user_id: 2
repo_id: 22 repo_id: 32
mode: 2 # write mode: 4
- -
id: 5 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 user_id: 15
repo_id: 21 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 user_id: 15
repo_id: 23 repo_id: 23
mode: 4 # owner mode: 4
- -
id: 7 id: 11
user_id: 15 user_id: 15
repo_id: 24 repo_id: 24
mode: 4 # owner mode: 4
- -
id: 8 id: 12
user_id: 18 user_id: 15
repo_id: 23 repo_id: 32
mode: 4 # owner mode: 2
- -
id: 9 id: 13
user_id: 18 user_id: 18
repo_id: 24 repo_id: 21
mode: 4 # owner mode: 2
- -
id: 10 id: 14
user_id: 18 user_id: 18
repo_id: 22 repo_id: 22
mode: 2 # write mode: 2
- -
id: 11 id: 15
user_id: 18 user_id: 18
repo_id: 21 repo_id: 23
mode: 2 # write 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 user_id: 20
repo_id: 27 repo_id: 27
mode: 4 # owner mode: 4
- -
id: 13 id: 19
user_id: 20 user_id: 20
repo_id: 28 repo_id: 28
mode: 4 # owner mode: 4
- -
id: 14 id: 20
user_id: 29 user_id: 29
repo_id: 4 repo_id: 4
mode: 2 # write (collaborator) mode: 2
- -
id: 15 id: 21
user_id: 29 user_id: 29
repo_id: 24 repo_id: 24
mode: 1 # read mode: 1

@ -21,3 +21,27 @@
repo_id: 4 repo_id: 4
user_id: 29 user_id: 29
mode: 2 # write 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

@ -479,3 +479,38 @@
type: 2 type: 2
config: "{}" config: "{}"
created_unix: 946684810 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

Loading…
Cancel
Save