Adding initial code for adding a new poll on the backend
This commit is contained in:
@@ -3,21 +3,26 @@ package db
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-sjles-pta-vote/server/config"
|
||||
)
|
||||
|
||||
func TestConnect(t *testing.T) {
|
||||
tmp_db, err := os.CreateTemp("", "vote_test.*.db")
|
||||
tmp_db_name := tmp_db.Name()
|
||||
tmp_db.Close()
|
||||
|
||||
defer os.Remove(tmp_db_name)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf(`Failed to create temporary db: %v`, err)
|
||||
t.Errorf(`Failed to create temporary db file: %v`, err)
|
||||
}
|
||||
|
||||
if err := Connect(tmp_db_name); err != nil {
|
||||
t.Errorf(`Failed to create the database at %s: %v`, tmp_db_name, err)
|
||||
init_conf := &config.Config{
|
||||
DBPath: string(tmp_db.Name()),
|
||||
}
|
||||
config.SetConfig(init_conf)
|
||||
|
||||
defer os.Remove(tmp_db.Name())
|
||||
tmp_db.Close()
|
||||
|
||||
if _, err := Connect(); err != nil {
|
||||
t.Errorf(`Failed to create the database: %v`, err)
|
||||
}
|
||||
|
||||
defer Close()
|
||||
|
||||
Reference in New Issue
Block a user