Example #1
0
// This function is called from main.go and from the tests
// to create a new application.
func NewApp(root string) *App {

	CheckEnv()

	// Use negroni for middleware
	ne := negroni.New()

	// Use gorilla/mux for routing
	ro := mux.NewRouter()

	// Use Render for template. Pass in path to templates folder
	// as well as asset helper functions.
	re := render.New(render.Options{
		IndentJSON:    true,
		StreamingJSON: true,
	})

	// Establish connection to DB as specified in database.go
	db := NewDB()
	models.New(db)

	// Add middleware to the stack
	ne.Use(negroni.NewRecovery())
	ne.Use(negroni.NewLogger())
	ne.UseHandler(ro)

	// Return a new App struct with all these things.
	return &App{ne, ro, re}
}
func TestMain(m *testing.M) {
	flag.Parse()
	os.RemoveAll("tmp")
	// Load test ENV variables
	godotenv.Load("../../.env.test")
	db = config.NewDB()
	models.New(db)
	if err := gofer.LoadAndPerform("db:empty", "--env=../../.env.test"); err != nil {
		panic(fmt.Sprintf("Unable to empty database %v", err))
	}

	if err := gofer.LoadAndPerform("db:migrate", "--env=../../.env.test"); err != nil {
		panic(fmt.Sprintf("Unable to migrate database %v", err))
	}
	os.Exit(m.Run())
}
func SetupSpec() (db *gorm.DB) {
	godotenv.Load("../../.env.test")
	config.CheckEnv()
	db = config.NewDB()
	cmd.RegisterDb(db)

	cmd.RootCmd.SetArgs([]string{"db:empty", "--env=../../.env.test"})
	if err := cmd.RootCmd.Execute(); err != nil {
		panic(fmt.Sprintf("Unable to empty database %v", err))
	}

	cmd.RootCmd.SetArgs([]string{"db:migrate", "--env=../../.env.test"})
	if err := cmd.RootCmd.Execute(); err != nil {
		panic(fmt.Sprintf("Unable to migrate database %v", err))
	}

	models.New(db)
	return
}
// Up is executed when this migration is applied
func Up_20151127032902(txn *sql.Tx) {
	gdb := config.NewDB()
	models.New(gdb)
	defer gdb.Close()

	pts := models.PatternParts{
		models.PatternPart{Key: "lecturer", Value: `rav|norav`},
		models.PatternPart{Key: "lang", Value: `[[:lower:]]{3,4}`},
		models.PatternPart{Key: "name", Value: `[a-z\-\d]+`},
		models.PatternPart{Key: "content_type", Value: `[[:lower:]]+`},
		models.PatternPart{Key: "line", Value: `[a-z\-\d]+`},
		models.PatternPart{Key: "ot", Value: `o|t`},
		models.PatternPart{Key: "date", Value: `\d{4}-\d{2}-\d{2}`},
		models.PatternPart{Key: "cam", Value: `cam\d*_\d|xdcam\d*_\d{2,3}|cam\d*|xdcam\d*`},
		models.PatternPart{Key: "archive_type", Value: `kabbalah|arvut|ligdol`},
		models.PatternPart{Key: "index", Value: `n\d`},
	}

	for _, pt := range pts {
		if err := pt.Save(); err != nil {
			log.Panicln(stacktrace.Propagate(err, "Unable to save pattern", pt))
		}
	}
}