fixed unit testing

pull/50/head
Hunter Long 2018-08-19 20:48:28 -07:00
parent df98c36853
commit 625b5d4b18
7 changed files with 15 additions and 18 deletions

View File

@ -132,7 +132,7 @@ func RunOnce() {
if err != nil {
utils.Log(4, "config.yml file not found")
}
err = core.DbConnection(core.Configs.Connection, false, ".")
err = core.DbConnection(core.Configs.Connection, false, utils.Directory)
if err != nil {
utils.Log(4, err)
}

View File

@ -95,7 +95,7 @@ func LoadDotEnvs() error {
func mainProcess() {
var err error
err = core.DbConnection(core.Configs.Connection, false, ".")
err = core.DbConnection(core.Configs.Connection, false, utils.Directory)
if err != nil {
utils.Log(4, fmt.Sprintf("could not connect to database: %v", err))
}

View File

@ -32,7 +32,7 @@ func LoadConfig() (*types.Config, error) {
return LoadUsingEnv()
}
Configs = new(types.Config)
file, err := ioutil.ReadFile("config.yml")
file, err := ioutil.ReadFile(utils.Directory + "/config.yml")
if err != nil {
return nil, errors.New("config.yml file not found - starting in setup mode")
}

View File

@ -72,7 +72,7 @@ func InitApp() {
func InsertNotifierDB() error {
if DbSession == nil {
err := DbConnection(CoreApp.DbConnection, false, ".")
err := DbConnection(CoreApp.DbConnection, false, utils.Directory)
if err != nil {
return errors.New("database connection has not been created")
}

View File

@ -104,7 +104,7 @@ func DbConnection(dbType string, retry bool, location string) error {
func waitForDb(dbType string) error {
time.Sleep(5 * time.Second)
return DbConnection(dbType, true, ".")
return DbConnection(dbType, true, utils.Directory)
}
func DatabaseMaintence() {
@ -126,7 +126,7 @@ func DeleteAllSince(table string, date time.Time) {
func (c *DbConfig) Save() error {
var err error
config, err := os.Create("config.yml")
config, err := os.Create(utils.Directory + "/config.yml")
if err != nil {
utils.Log(4, err)
return err

View File

@ -114,7 +114,7 @@ func ProcessSetupHandler(w http.ResponseWriter, r *http.Request) {
return
}
err = core.DbConnection(core.Configs.Connection, false, ".")
err = core.DbConnection(core.Configs.Connection, false, utils.Directory)
if err != nil {
utils.Log(3, err)
core.DeleteConfig()

View File

@ -20,14 +20,13 @@ import (
"github.com/hunterlong/statup/utils"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"os"
"testing"
"upper.io/db.v3/sqlite"
)
var (
testNotifier *Tester
testDatabase string
dir string
)
//
@ -63,15 +62,13 @@ func (n *Tester) Test() error {
}
func init() {
testDatabase = os.Getenv("GOPATH")
testDatabase += "/src/github.com/hunterlong/statup"
dir = utils.Directory
utils.InitLogs()
}
func injectDatabase() {
sqliteDb := sqlite.ConnectionURL{
Database: testDatabase + "/statup.db",
Database: dir + "/statup.db",
}
dbSession, _ := sqlite.Open(sqliteDb)
Collections = dbSession.Collection("communication")
@ -87,11 +84,11 @@ func TestInit(t *testing.T) {
func TestAdd(t *testing.T) {
testNotifier = &Tester{&Notification{
Id: 1,
Id: 999999,
Method: "tester",
Host: "0.0.0.0",
Form: []NotificationForm{{
Id: 1,
Id: 999999,
Type: "text",
Title: "Incoming Webhook Url",
Placeholder: "Insert your Slack webhook URL here.",
@ -119,14 +116,14 @@ func TestInsertDatabase(t *testing.T) {
}
func TestSelectNotification(t *testing.T) {
notifier, err := SelectNotification(1)
notifier, err := SelectNotification(999999)
assert.Nil(t, err)
assert.Equal(t, "tester", notifier.Method)
assert.False(t, notifier.Enabled)
}
func TestNotification_Update(t *testing.T) {
notifier, err := SelectNotification(1)
notifier, err := SelectNotification(999999)
assert.Nil(t, err)
notifier.Method = "updatedName"
notifier.Enabled = true
@ -139,7 +136,7 @@ func TestNotification_Update(t *testing.T) {
}
func TestNotification_GetValue(t *testing.T) {
notifier, err := SelectNotification(1)
notifier, err := SelectNotification(999999)
assert.Nil(t, err)
val := notifier.GetValue("Host")
assert.Equal(t, "0.0.0.0", val)