This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
/
driver_test.go
95 lines (67 loc) · 2.12 KB
/
driver_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package migration_test
import (
"io/ioutil"
"strings"
"github.com/concourse/atc/db/migration"
"github.com/concourse/atc/db/migration/migrationfakes"
"github.com/mattes/migrate/database"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Driver", func() {
var (
driver database.Driver
fakedriver *migrationfakes.FakeDriver
fakemigrations *migrationfakes.FakeMigrations
)
BeforeEach(func() {
fakedriver = new(migrationfakes.FakeDriver)
fakemigrations = new(migrationfakes.FakeMigrations)
driver = migration.NewDriverForMigrations(fakedriver, fakemigrations)
})
Context("Run", func() {
Context("golang", func() {
It("fails if migration does not contain function", func() {
contents := `package migrations`
reader := strings.NewReader(contents)
err := driver.Run(reader)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("No migration found"))
})
It("fails if migration does not contain function matching up/down pattern", func() {
contents := `package migrations
func (self *migrations) Sideways_1234567890() error {
return nil
}
`
reader := strings.NewReader(contents)
err := driver.Run(reader)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("No migration found"))
})
It("parses the migration name from the reader contents", func() {
contents := `package migrations
func (self *migrations) Up_1234567890() error {
return nil
}
`
reader := strings.NewReader(contents)
err := driver.Run(reader)
Expect(err).NotTo(HaveOccurred())
Expect(fakemigrations.RunArgsForCall(0)).To(Equal("Up_1234567890"))
})
})
Context("psql", func() {
It("delegates to the embedded postgres driver", func() {
contents := "CREATE TABLE blah(id SERIAL)"
reader := strings.NewReader(contents)
err := driver.Run(reader)
Expect(err).NotTo(HaveOccurred())
calledReader := fakedriver.RunArgsForCall(0)
calledContents, err := ioutil.ReadAll(calledReader)
Expect(err).NotTo(HaveOccurred())
Expect(string(calledContents)).To(Equal(contents))
})
})
})
})