File: db_config_test.go

package info (click to toggle)
golang-github-cloudflare-cfssl 1.6.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,220 kB
  • sloc: asm: 1,936; javascript: 652; makefile: 94; sql: 89; sh: 64; python: 11
file content (36 lines) | stat: -rw-r--r-- 912 bytes parent folder | download
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
package dbconf

import (
	"testing"

	_ "github.com/mattn/go-sqlite3" // import just to initialize SQLite testing
)

func TestLoadFile(t *testing.T) {
	config, err := LoadFile("testdata/db-config.json")
	if err != nil || config == nil {
		t.Fatal("Failed to load test db-config file ", err)
	}

	config, err = LoadFile("nonexistent")
	if err == nil || config != nil {
		t.Fatal("Expected failure loading nonexistent configuration file")
	}
}

func TestDBFromConfig(t *testing.T) {
	db, err := DBFromConfig("testdata/db-config.json")
	if err != nil || db == nil {
		t.Fatal("Failed to open db from test db-config file")
	}

	db, err = DBFromConfig("testdata/bad-db-config.json")
	if err == nil || db != nil {
		t.Fatal("Expected failure opening invalid db")
	}

	db, err = DBFromConfig("testdata/unreachable-db-config.json")
	if err == nil || db != nil {
		t.Fatal("Expected failure opening unreachable db")
	}
}