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

Function TestDSN

storage/dsn_test.go:23–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21)
22
23func TestDSN(t *testing.T) {
24 testStrings := []string{
25 "",
26 "file:test.db",
27 "file::memory:?cache=shared&mode=memory",
28 "file:test.db?p1=v1&p2=v2&p1=v3",
29 }
30
31 for _, s := range testStrings {
32 dsn, err := NewDSN(s)
33
34 if err != nil {
35 t.Errorf("error occurred: %v", err)
36 continue
37 }
38
39 t.Logf("Test format: string = %s, formatted = %s", s, dsn.Format())
40
41 dsn.SetFileName("file:/dev/null")
42 t.Logf("Test set file name: formatted = %s", dsn.Format())
43
44 dsn.AddParam("key", "value")
45 t.Logf("Test set add param: formatted = %s", dsn.Format())
46
47 dsn.AddParam("key", "")
48 t.Logf("Test delete param by set empty to add param: formatted = %s", dsn.Format())
49 if _, ok := dsn.GetParam("key"); ok {
50 t.Errorf("Should not have deleted key")
51 }
52 }
53
54 invalidString1 := "file:test.db?p1"
55 dsn, err := NewDSN(invalidString1)
56 if err == nil {
57 t.Errorf("Should occurred unrecognized parameter error: %v", dsn)
58 }
59
60 dsn = &DSN{}
61 dsn.AddParam("clone", "true")
62 clone := dsn.Clone()
63 if _, ok := clone.GetParam("clone"); !ok {
64 t.Errorf("Should cloned params")
65 }
66}

Callers

nothing calls this directly

Calls 7

FormatMethod · 0.95
SetFileNameMethod · 0.95
AddParamMethod · 0.95
GetParamMethod · 0.95
CloneMethod · 0.95
NewDSNFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected