Skip to content

Commit c7a9c56

Browse files
committed
Add user_repo_unit to yaml generation
1 parent 5a8474d commit c7a9c56

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

contrib/fixtures/fixture_generation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var (
2323
}{
2424
{
2525
models.GetYamlFixturesAccess, "access",
26+
models.GetYamlFixturesUserRepoUnit, "user_repo_unit",
2627
},
2728
}
2829
fixturesDir string

models/fixture_generation.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,30 @@ func GetYamlFixturesAccess() (string, error) {
4343

4444
return b.String(), nil
4545
}
46+
47+
// GetYamlFixturesUserRepoUnit returns a string containing the contents for the
48+
// user_repo_unit table, as recalculated using repo.RebuildAllUserRepoUnits()
49+
func GetYamlFixturesUserRepoUnit() (string, error) {
50+
51+
if err := RebuildAllUserRepoUnits(x); err != nil {
52+
return "", err
53+
}
54+
55+
var b strings.Builder
56+
57+
units := make([]*UserRepoUnit, 0, 200)
58+
if err := x.OrderBy("user_id, repo_id").Find(&units); err != nil {
59+
return "", err
60+
}
61+
62+
for _, u := range units {
63+
fmt.Fprintf(&b, "-\n")
64+
fmt.Fprintf(&b, " user_id: %d\n", u.UserID)
65+
fmt.Fprintf(&b, " repo_id: %d\n", u.RepoID)
66+
fmt.Fprintf(&b, " type: %d\n", u.Type)
67+
fmt.Fprintf(&b, " mode: %d\n", u.Mode)
68+
fmt.Fprintf(&b, "\n")
69+
}
70+
71+
return b.String(), nil
72+
}

models/fixture_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ func TestFixtureGeneration(t *testing.T) {
3131
}
3232

3333
test(GetYamlFixturesAccess, "access")
34+
test(GetYamlFixturesUserRepoUnit, "user_repo_unit")
3435
}

0 commit comments

Comments
 (0)