-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase_test.go
60 lines (45 loc) · 1.09 KB
/
database_test.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package database
import (
"context"
"log"
"testing"
"github.com/softika/gopherizer/config"
"github.com/softika/gopherizer/pkg/testinfra"
)
var dbCfg config.DatabaseConfig
func TestMain(m *testing.M) {
postgres, err := testinfra.RunPostgres()
if err != nil {
log.Fatalf("could not start postgres container: %v", err)
}
dbCfg = postgres.Config
m.Run()
if err = postgres.Shutdown(); err != nil {
log.Fatalf("could not teardown postgres container: %v", err)
}
}
func TestNew(t *testing.T) {
srv := New(dbCfg)
if srv == nil {
t.Fatal("New() returned nil")
}
}
func TestHealth(t *testing.T) {
srv := New(dbCfg)
stats := srv.Health(context.Background())
if stats["status"] != "up" {
t.Fatalf("expected status to be up, got %s", stats["status"])
}
if _, ok := stats["error"]; ok {
t.Fatalf("expected error not to be present")
}
if stats["message"] != "It's healthy" {
t.Fatalf("expected message to be 'It's healthy', got %s", stats["message"])
}
}
func TestClose(t *testing.T) {
srv := New(dbCfg)
if srv.Close() != nil {
t.Fatalf("expected Close() to return nil")
}
}