Skip to content

Commit ad7c5ac

Browse files
committed
Merge branch 'master' into fix-access-test-exp
2 parents b2f04f4 + 62a1322 commit ad7c5ac

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

models/fixture_access_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build access_fixtures
6+
7+
package models
8+
9+
// This file is excluded from build and tests, and is intended for assisting
10+
// in keeping access.yml in sync with the other .yml files.
11+
12+
// To use it, do:
13+
// cd models
14+
// go test -tags "access_fixtures sqlite sqlite_unlock_notify" -run TestBuildAccessFixturesYaml
15+
16+
import (
17+
"bufio"
18+
"fmt"
19+
"os"
20+
"testing"
21+
22+
"github.com/stretchr/testify/assert"
23+
)
24+
25+
func TestBuildAccessFixturesYaml(t *testing.T) {
26+
assert.NoError(t, PrepareTestDatabase())
27+
28+
repos := make([]*Repository, 0, 50)
29+
assert.NoError(t, x.Find(&repos))
30+
for _, repo := range repos {
31+
repo.MustOwner()
32+
assert.NoError(t, repo.RecalculateAccesses())
33+
}
34+
35+
f, err := os.Create("fixtures/access.yml")
36+
assert.NoError(t, err)
37+
w := bufio.NewWriter(f)
38+
39+
accesses := make([]*Access, 0, 200)
40+
assert.NoError(t, x.OrderBy("user_id, repo_id").Find(&accesses))
41+
for i, a := range accesses {
42+
fmt.Fprintf(w, "-\n")
43+
fmt.Fprintf(w, " id: %d\n", i+1)
44+
fmt.Fprintf(w, " user_id: %d\n", a.UserID)
45+
fmt.Fprintf(w, " repo_id: %d\n", a.RepoID)
46+
fmt.Fprintf(w, " mode: %d\n", a.Mode)
47+
fmt.Fprintf(w, "\n")
48+
}
49+
50+
w.Flush()
51+
f.Close()
52+
}

0 commit comments

Comments
 (0)