MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestConfig

Function TestConfig

client/config_test.go:25–103  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestConfig(t *testing.T) {
26 Convey("test config without additional options", t, func() {
27 cfg, err := ParseDSN("covenantsql://db")
28 So(err, ShouldBeNil)
29 So(cfg, ShouldResemble, &Config{
30 DatabaseID: "db",
31 UseLeader: true,
32 UseFollower: false,
33 })
34
35 recoveredCfg, err := ParseDSN(cfg.FormatDSN())
36 So(err, ShouldBeNil)
37 So(cfg, ShouldResemble, recoveredCfg)
38 })
39
40 Convey("test invalid config", t, func() {
41 cfg, err := ParseDSN("invalid dsn")
42 So(err, ShouldNotBeNil)
43 So(cfg, ShouldBeNil)
44 })
45
46 Convey("test dsn with only database id", t, func() {
47 dbIDStr := "00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9"
48 cfg, err := ParseDSN(dbIDStr)
49 So(err, ShouldBeNil)
50 So(cfg, ShouldResemble, &Config{
51 DatabaseID: dbIDStr,
52 UseLeader: true,
53 UseFollower: false,
54 })
55
56 recoveredCfg, err := ParseDSN(cfg.FormatDSN())
57 So(err, ShouldBeNil)
58 So(cfg, ShouldResemble, recoveredCfg)
59 })
60
61 Convey("test dsn with additional options", t, func() {
62 cfg, err := ParseDSN("covenantsql://db?use_leader=0&use_follower=true")
63 So(err, ShouldBeNil)
64 So(cfg, ShouldResemble, &Config{
65 DatabaseID: "db",
66 UseLeader: false,
67 UseFollower: true,
68 })
69
70 recoveredCfg, err := ParseDSN(cfg.FormatDSN())
71 So(err, ShouldBeNil)
72 So(cfg, ShouldResemble, recoveredCfg)
73 })
74
75 Convey("test dsn with use all kinds of options", t, func(c C) {
76 testFormatAndParse := func(cfg *Config) {
77 newCfg, err := ParseDSN(cfg.FormatDSN())
78 c.So(err, ShouldBeNil)
79 c.So(newCfg, ShouldResemble, cfg)
80 }
81 testFormatAndParse(&Config{
82 UseLeader: true,

Callers

nothing calls this directly

Calls 2

ParseDSNFunction · 0.85
FormatDSNMethod · 0.80

Tested by

no test coverage detected