You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fixture_access_test.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. // +build access_fixtures
  5. package models
  6. // This file is excluded from build and tests, and is intended for assisting
  7. // in keeping access.yml in sync with the other .yml files.
  8. // To use it, do:
  9. // cd models
  10. // go test -tags "access_fixtures sqlite sqlite_unlock_notify" -run TestBuildAccessFixturesYaml
  11. import (
  12. "bufio"
  13. "fmt"
  14. "os"
  15. "testing"
  16. "github.com/stretchr/testify/assert"
  17. )
  18. func TestBuildAccessFixturesYaml(t *testing.T) {
  19. assert.NoError(t, PrepareTestDatabase())
  20. repos := make([]*Repository, 0, 50)
  21. assert.NoError(t, x.Find(&repos))
  22. for _, repo := range repos {
  23. repo.MustOwner()
  24. assert.NoError(t, repo.RecalculateAccesses())
  25. }
  26. f, err := os.Create("fixtures/access.yml")
  27. assert.NoError(t, err)
  28. w := bufio.NewWriter(f)
  29. accesses := make([]*Access, 0, 200)
  30. assert.NoError(t, x.OrderBy("user_id, repo_id").Find(&accesses))
  31. for i, a := range accesses {
  32. fmt.Fprintf(w, "-\n")
  33. fmt.Fprintf(w, " id: %d\n", i+1)
  34. fmt.Fprintf(w, " user_id: %d\n", a.UserID)
  35. fmt.Fprintf(w, " repo_id: %d\n", a.RepoID)
  36. fmt.Fprintf(w, " mode: %d\n", a.Mode)
  37. fmt.Fprintf(w, "\n")
  38. }
  39. w.Flush()
  40. f.Close()
  41. }