aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorguillep2k <18600385+guillep2k@users.noreply.github.com>2020-02-15 05:59:43 -0300
committerGitHub <noreply@github.com>2020-02-15 10:59:43 +0200
commit7e920703f94c4f2782860a72cc6beca5671736f5 (patch)
treebbc652b204f28e7d8b2cff22eed44c021ae684cf /contrib
parent62a1322cf9940daa987ca16053f5081d7da54298 (diff)
downloadgitea-7e920703f94c4f2782860a72cc6beca5671736f5.tar.gz
gitea-7e920703f94c4f2782860a72cc6beca5671736f5.zip
Move fixture generation to contrib and add test (#10277)
* Add fixture gen tool and fix "access" test * Close file before exiting * Add missing repo_unit for repo id: 5 * Fix count on TestAPIOrgRepos * Generate access fixture from contrib and add test * Remove old access fixture generation * Fix lint Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'contrib')
-rw-r--r--contrib/fixtures/fixture_generation.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/contrib/fixtures/fixture_generation.go b/contrib/fixtures/fixture_generation.go
new file mode 100644
index 0000000000..802a2ca30c
--- /dev/null
+++ b/contrib/fixtures/fixture_generation.go
@@ -0,0 +1,76 @@
+// 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.
+
+package main
+
+import (
+ "fmt"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+
+ "code.gitea.io/gitea/models"
+)
+
+// To generate derivative fixtures, execute the following from Gitea's repository base dir:
+// go run -tags 'sqlite sqlite_unlock_notify' contrib/fixtures/fixture_generation.go [fixture...]
+
+var (
+ generators = []struct {
+ gen func() (string, error)
+ name string
+ }{
+ {
+ models.GetYamlFixturesAccess, "access",
+ },
+ }
+ fixturesDir string
+)
+
+func main() {
+ pathToGiteaRoot := "."
+ fixturesDir = filepath.Join(pathToGiteaRoot, "models", "fixtures")
+ if err := models.CreateTestEngine(fixturesDir); err != nil {
+ fmt.Printf("CreateTestEngine: %+v", err)
+ os.Exit(1)
+ }
+ if err := models.PrepareTestDatabase(); err != nil {
+ fmt.Printf("PrepareTestDatabase: %+v\n", err)
+ os.Exit(1)
+ }
+ if len(os.Args) == 0 {
+ for _, r := range os.Args {
+ if err := generate(r); err != nil {
+ fmt.Printf("generate '%s': %+v\n", r, err)
+ os.Exit(1)
+ }
+ }
+ } else {
+ for _, g := range generators {
+ if err := generate(g.name); err != nil {
+ fmt.Printf("generate '%s': %+v\n", g.name, err)
+ os.Exit(1)
+ }
+ }
+ }
+}
+
+func generate(name string) error {
+ for _, g := range generators {
+ if g.name == name {
+ data, err := g.gen()
+ if err != nil {
+ return err
+ }
+ path := filepath.Join(fixturesDir, name+".yml")
+ if err := ioutil.WriteFile(path, []byte(data), 0644); err != nil {
+ return fmt.Errorf("%s: %+v", path, err)
+ }
+ fmt.Printf("%s created.\n", path)
+ return nil
+ }
+ }
+
+ return fmt.Errorf("generator not found")
+}