Beispiel #1
0
	// sql drivers
	_ "github.com/mattn/go-sqlite3"

	. "github.com/starkandwayne/shield/db"
)

var _ = Describe("Database", func() {
	Describe("Connecting to the database", func() {
		Context("With an invalid DSN", func() {
			It("should fail", func() {
				db := &DB{
					Driver: "invalid",
					DSN:    "does-not-matter",
				}

				Ω(db.Connect()).Should(HaveOccurred())
				Ω(db.Connected()).Should(BeFalse())
				Ω(db.Disconnect()).Should(Succeed())
			})
		})

		Context("With an in-memory SQLite database", func() {
			It("should succeed", func() {
				db := &DB{
					Driver: "sqlite3",
					DSN:    ":memory:",
				}

				Ω(db.Connect()).Should(Succeed())
				Ω(db.Connected()).Should(BeTrue())
				Ω(db.Disconnect()).Should(Succeed())
Beispiel #2
0
				tableExists := func(table string) {
					sql := fmt.Sprintf("SELECT * FROM %s", table)
					Ω(db.Exec(sql)).Should(Succeed())
				}

				tableExists("targets")
				tableExists("stores")
				tableExists("schedules")
				tableExists("retention")
				tableExists("jobs")
				tableExists("archives")
				tableExists("tasks")
			})
		})
	})

	Describe("Schema Version Interrogation", func() {
		It("should return an error for a bad database connection", func() {
			db := &DB{
				Driver: "postgres",
				DSN:    "host=127.86.86.86, port=8686",
			}

			db.Connect()
			_, err := db.SchemaVersion()
			Ω(err).Should(HaveOccurred())
		})
	})
})