27 lines
468 B
Go
27 lines
468 B
Go
|
package bd
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func Testdb(t *testing.T, databaseurl string) (*Bd, func(...string)) {
|
||
|
t.Helper()
|
||
|
config := NewConfig()
|
||
|
config.BaseUrlBd = databaseurl
|
||
|
s := New(config)
|
||
|
|
||
|
if err := s.Open(); err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
return s, func(tables ...string) {
|
||
|
if len(tables) > 0 {
|
||
|
if _, err := s.db.Exec(fmt.Sprintf("TRUNCATE %s CASCADE", strings.Join(tables, ", "))); err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
}
|
||
|
s.Close()
|
||
|
}
|
||
|
}
|