Adding initial code for adding a new poll on the backend

This commit is contained in:
2025-11-04 16:39:10 -05:00
parent 3e2efae4ce
commit 5e8b4e2b61
8 changed files with 147 additions and 51 deletions

View File

@@ -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()