db_config_test.go 912 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package dbconf
  2. import (
  3. "testing"
  4. _ "github.com/mattn/go-sqlite3" // import just to initialize SQLite testing
  5. )
  6. func TestLoadFile(t *testing.T) {
  7. config, err := LoadFile("testdata/db-config.json")
  8. if err != nil || config == nil {
  9. t.Fatal("Failed to load test db-config file ", err)
  10. }
  11. config, err = LoadFile("nonexistent")
  12. if err == nil || config != nil {
  13. t.Fatal("Expected failure loading nonexistent configuration file")
  14. }
  15. }
  16. func TestDBFromConfig(t *testing.T) {
  17. db, err := DBFromConfig("testdata/db-config.json")
  18. if err != nil || db == nil {
  19. t.Fatal("Failed to open db from test db-config file")
  20. }
  21. db, err = DBFromConfig("testdata/bad-db-config.json")
  22. if err == nil || db != nil {
  23. t.Fatal("Expected failure opening invalid db")
  24. }
  25. db, err = DBFromConfig("testdata/unreachable-db-config.json")
  26. if err == nil || db != nil {
  27. t.Fatal("Expected failure opening unreachable db")
  28. }
  29. }