-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
46 lines (39 loc) · 907 Bytes
/
main_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
package main
import (
"os"
"os/user"
"testing"
"github.com/joho/godotenv"
"github.com/nathenapse/learning-blockchain/app"
)
var a app.App
var usr, err = user.Current()
func Test_main(t *testing.T) {
tests := []struct {
name string
}{
// TODO: Add test cases.
{"noenv"},
{"test"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.name != "noenv" {
godotenv.Load()
}
a = app.App{}
testDb, found := os.LookupEnv("TEST_DB")
if found == false && tt.name != "noenv" {
t.Fatal("no env found")
} else {
a.Initialize(testDb)
if _, err := os.Stat(usr.HomeDir + "/.blockchain"); os.IsNotExist(err) {
t.Errorf("Initialize not creating directory at %v", err)
}
if _, err := os.Stat(usr.HomeDir + "/.blockchain/" + testDb); os.IsNotExist(err) {
t.Errorf("Initialize not creating db file at %v", err)
}
}
})
}
}