statping/core/core_test.go

112 lines
2.6 KiB
Go
Raw Normal View History

2018-08-16 06:22:20 +00:00
// Statup
// Copyright (C) 2018. Hunter Long and the project contributors
// Written by Hunter Long <info@socialeck.com> and the project contributors
//
// https://github.com/hunterlong/statup
//
// The licenses for most software and other practical works are designed
// to take away your freedom to share and change the works. By contrast,
// the GNU General Public License is intended to guarantee your freedom to
// share and change all versions of a program--to make sure it remains free
// software for all its users.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package core
import (
2018-08-10 04:38:54 +00:00
"github.com/hunterlong/statup/source"
2018-07-27 04:45:42 +00:00
"github.com/hunterlong/statup/utils"
"github.com/stretchr/testify/assert"
"testing"
)
var (
dir string
)
2018-07-27 04:45:42 +00:00
func init() {
2018-08-10 04:38:54 +00:00
dir = utils.Directory
2018-07-27 04:45:42 +00:00
utils.InitLogs()
2018-08-10 04:38:54 +00:00
source.Assets()
2018-07-27 04:45:42 +00:00
}
func TestNewCore(t *testing.T) {
utils.DeleteFile(dir + "/config.yml")
utils.DeleteFile(dir + "/statup.db")
CoreApp = NewCore()
assert.NotNil(t, CoreApp)
CoreApp.Name = "Tester"
2018-07-27 04:45:42 +00:00
}
func TestDbConfig_Save(t *testing.T) {
var err error
2018-09-27 05:31:39 +00:00
Configs = &DbConfig{
2018-07-27 04:45:42 +00:00
DbConn: "sqlite",
Project: "Tester",
2018-08-10 04:38:54 +00:00
Location: dir,
2018-09-27 05:31:39 +00:00
}
Configs, err = Configs.Save()
assert.Nil(t, err)
assert.Equal(t, "sqlite", Configs.DbConn)
assert.NotEmpty(t, Configs.ApiKey)
assert.NotEmpty(t, Configs.ApiSecret)
}
func TestLoadDbConfig(t *testing.T) {
Configs, err := LoadConfig(dir)
2018-07-27 04:45:42 +00:00
assert.Nil(t, err)
assert.Equal(t, "sqlite", Configs.DbConn)
2018-07-27 04:45:42 +00:00
}
func TestDbConnection(t *testing.T) {
err := Configs.Connect(false, dir)
2018-07-27 04:45:42 +00:00
assert.Nil(t, err)
}
func TestDropDatabase(t *testing.T) {
err := Configs.DropDatabase()
assert.Nil(t, err)
}
func TestSeedSchemaDatabase(t *testing.T) {
err := Configs.CreateDatabase()
assert.Nil(t, err)
}
func TestMigrateDatabase(t *testing.T) {
err := Configs.MigrateDatabase()
2018-07-27 04:45:42 +00:00
assert.Nil(t, err)
}
func TestSeedDatabase(t *testing.T) {
err := InsertLargeSampleData()
2018-07-27 04:45:42 +00:00
assert.Nil(t, err)
}
func TestReLoadDbConfig(t *testing.T) {
err := Configs.Connect(false, dir)
2018-07-27 04:45:42 +00:00
assert.Nil(t, err)
assert.Equal(t, "sqlite", Configs.DbConn)
2018-07-27 04:45:42 +00:00
}
func TestSelectCore(t *testing.T) {
core, err := SelectCore()
2018-07-27 04:45:42 +00:00
assert.Nil(t, err)
assert.Equal(t, "Statup Sample Data", core.Name)
2018-07-27 04:45:42 +00:00
}
func TestInsertNotifierDB(t *testing.T) {
2018-09-12 04:14:22 +00:00
err := insertNotifierDB()
2018-07-27 04:45:42 +00:00
assert.Nil(t, err)
}
func TestExportStaticHTML(t *testing.T) {
2018-08-21 06:54:39 +00:00
t.SkipNow()
data := ExportIndexHTML()
assert.Contains(t, data, "Statup made with ❤️")
assert.Contains(t, data, "</body>")
assert.Contains(t, data, "</html>")
}