func ReadFile(filename string) string { env := application.NewEnvironment() root := env.RootPath fileContents, err := ioutil.ReadFile(root + filename) if err != nil { panic(err) } return string(fileContents) }
func (s Notifications) MigrateDatabase() { env := application.NewEnvironment() database, gobbleDB := fetchDatabases() migrator := v1models.DatabaseMigrator{} migrator.Migrate(database.RawConnection(), env.ModelMigrationsPath) gobbleDB.Migrate(env.GobbleMigrationsPath) }
func fetchDatabases() (*db.DB, *gobble.DB) { env := application.NewEnvironment() sqlDB, err := sql.Open("mysql", env.DatabaseURL) if err != nil { ginkgo.Fail(err.Error(), 1) } database := db.NewDatabase(sqlDB, db.Config{DefaultTemplatePath: path.Join(env.RootPath, "templates", "default.json")}) gobbleDB := gobble.NewDatabase(sqlDB) return database, gobbleDB }
func (s Notifications) ResetDatabase() { env := application.NewEnvironment() database, gobbleDB := fetchDatabases() v1models.Setup(database) v2models.Setup(database) database.Connection().(*db.Connection).TruncateTables() migrator := v1models.DatabaseMigrator{} migrator.Seed(database, path.Join(env.RootPath, "templates", "default.json")) gobbleDB.Connection.TruncateTables() }
func TruncateTables(database *db.DB) { env := application.NewEnvironment() dbMigrator := v1models.DatabaseMigrator{} dbMigrator.Migrate(database.RawConnection(), env.ModelMigrationsPath) v1models.Setup(database) v2models.Setup(database) connection := database.Connection().(*db.Connection) err := connection.TruncateTables() if err != nil { panic(err) } }
By("confirming the messages were sent", func() { Eventually(func() int { return len(Servers.SMTP.Deliveries) }, 1*time.Second).Should(Equal(2)) recipients := []string{Servers.SMTP.Deliveries[0].Recipients[0], Servers.SMTP.Deliveries[1].Recipients[0]} Expect(recipients).To(ConsistOf([]string{"*****@*****.**", "*****@*****.**"})) var recipientIndex int if Servers.SMTP.Deliveries[0].Recipients[0] == "*****@*****.**" { recipientIndex = 0 } else { recipientIndex = 1 } env := application.NewEnvironment() delivery := Servers.SMTP.Deliveries[recipientIndex] Expect(delivery.Sender).To(Equal(env.Sender)) data := strings.Split(string(delivery.Data), "\n") Expect(data).To(ContainElement("X-CF-Client-ID: notifications-sender")) Expect(data).To(ContainElement("X-CF-Notification-ID: " + indexedResponses["091b6583-0933-4d17-a5b6-66e54666c88e"].NotificationID)) Expect(data).To(ContainElement("Subject: Genetics gone awry")) Expect(data).To(ContainElement("\t\t<h1>T-Rex</h1><p>this is an acceptance-test</p><b>This message was sent to=")) Expect(data).To(ContainElement(" everyone.</b>")) Expect(data).To(ContainElement("T-Rex")) Expect(data).To(ContainElement("oh no!")) Expect(data).To(ContainElement("This message was sent to everyone.")) }) }) })
func NewNotifications() Notifications { return Notifications{ env: application.NewEnvironment(), } }