-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
51 lines (40 loc) · 1.13 KB
/
main_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
package dbmux
import (
"database/sql"
"testing"
"github.com/pcpratheesh/dbmux/entity"
)
func TestAddToPool(t *testing.T) {
// Create a new MultiConn instance
multi := &MultiConn{
conns: make(entity.Pool),
}
// Create a new mock database connection to add to the pool
db := &sql.DB{}
// Create a new Params struct to use as input
params := entity.Options{
Name: "test_db",
Driver: "sqlite3",
// URL: "file::memory:?cache=shared",
}
// Call AddToPool with the input params and database
err := multi.AddToPool(params, db)
// Check that there was no error returned
if err != nil {
t.Errorf("unexpected error: %v", err)
}
// Check that the database was added to the pool
if _, ok := multi.conns[params.Name]; !ok {
t.Errorf("expected database to be added to the pool")
}
// Call AddToPool again with the same input params and database
err = multi.AddToPool(params, db)
// Check that an error was returned indicating the name is already taken
if err == nil {
t.Errorf("expected error due to name already existing in the pool")
}
}
type Person struct {
Name string `bson:"name"`
Age int `bson:"age"`
}