-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommon_test.go
66 lines (58 loc) · 2.14 KB
/
common_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
package prana_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/phogolabs/prana"
)
var _ = Describe("ParseURL", func() {
It("parses the SQLite connection string successfully", func() {
driver, source, err := prana.ParseURL("sqlite3://./prana.db")
Expect(err).NotTo(HaveOccurred())
Expect(driver).To(Equal("sqlite3"))
Expect(source).To(Equal("./prana.db"))
})
Describe("MySQL", func() {
It("parses the MySQL connection string successfully", func() {
driver, source, err := prana.ParseURL("mysql://root@/prana")
Expect(err).NotTo(HaveOccurred())
Expect(driver).To(Equal("mysql"))
Expect(source).To(Equal("root@tcp(127.0.0.1:3306)/prana?parseTime=true"))
})
It("parses the MySQL connection string with custom port successfully", func() {
driver, source, err := prana.ParseURL("mysql://root:password@tcp(127.0.0.1:13306)/prana")
Expect(err).NotTo(HaveOccurred())
Expect(driver).To(Equal("mysql"))
Expect(source).To(Equal("root:password@tcp(127.0.0.1:13306)/prana?parseTime=true"))
})
Context("when the DSN is invalid", func() {
It("returns the error", func() {
driver, source, err := prana.ParseURL("mysql://@net(addr/")
Expect(err).To(MatchError("invalid DSN: network address not terminated (missing closing brace)"))
Expect(driver).To(BeEmpty())
Expect(source).To(BeEmpty())
})
})
})
It("parses the PostgreSQL connection string successfully", func() {
driver, source, err := prana.ParseURL("postgres://localhost/prana?sslmode=disable")
Expect(err).NotTo(HaveOccurred())
Expect(driver).To(Equal("postgres"))
Expect(source).To(Equal("postgres://localhost/prana?sslmode=disable"))
})
Context("when the URL is empty", func() {
It("returns an error", func() {
driver, source, err := prana.ParseURL("")
Expect(driver).To(BeEmpty())
Expect(source).To(BeEmpty())
Expect(err).To(MatchError("url cannot be empty"))
})
})
Context("when the URL is invalid", func() {
It("returns an error", func() {
driver, source, err := prana.ParseURL("::")
Expect(driver).To(BeEmpty())
Expect(source).To(BeEmpty())
Expect(err).To(MatchError("invalid dsn"))
})
})
})