Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-29 05:06:11 +01:00

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>
This commit is contained in:
guillep2k 2020-02-15 01:29:06 -03:00 committed by GitHub
parent a97fe76950
commit 62a1322cf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 193 additions and 45 deletions

View file

@ -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},
}

View file

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

View file

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

View file

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

View file

@ -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

View file

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