mirror of https://github.com/statping/statping
travis
parent
3f94d2a910
commit
31148682ed
|
@ -7,6 +7,7 @@ cache:
|
|||
directories:
|
||||
- "~/.npm"
|
||||
- "~/.cache"
|
||||
- "/tmp/statping.db"
|
||||
- "$GOPATH/src/github.com/hunterlong/statping/vendor"
|
||||
sudo: required
|
||||
services:
|
||||
|
|
1
Makefile
1
Makefile
|
@ -256,6 +256,7 @@ clean:
|
|||
rm -f source/rice-box.go
|
||||
rm -rf **/*.db-journal
|
||||
rm -rf *.snap
|
||||
rm -rf /tmp/statping.db
|
||||
find . -name "*.out" -type f -delete
|
||||
find . -name "*.cpu" -type f -delete
|
||||
find . -name "*.mem" -type f -delete
|
||||
|
|
|
@ -168,11 +168,9 @@ func updateDisplay() error {
|
|||
return err
|
||||
}
|
||||
if VERSION != gitCurrent.TagName[1:] {
|
||||
fmt.Printf("\n New Update %v Available\n", gitCurrent.TagName[1:])
|
||||
fmt.Printf("\nNew Update %v Available!\n", gitCurrent.TagName[1:])
|
||||
fmt.Printf("Update Command:\n")
|
||||
fmt.Printf("curl -o- -L https://statping.com/install.sh | bash\n\n")
|
||||
} else {
|
||||
fmt.Printf("You have the latest version of Statping\n")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/hunterlong/statping/core"
|
||||
"github.com/hunterlong/statping/source"
|
||||
"github.com/hunterlong/statping/utils"
|
||||
"github.com/rendon/testcli"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -166,7 +165,6 @@ func TestRunOnceCLI(t *testing.T) {
|
|||
func TestEnvCLI(t *testing.T) {
|
||||
run := catchCLI([]string{"env"})
|
||||
assert.Error(t, run)
|
||||
Clean()
|
||||
}
|
||||
|
||||
func commandAndSleep(cmd *exec.Cmd, duration time.Duration, out chan<- string) {
|
||||
|
@ -186,15 +184,3 @@ func runCommand(c *exec.Cmd, out chan<- string) {
|
|||
bout, _ := c.CombinedOutput()
|
||||
out <- string(bout)
|
||||
}
|
||||
|
||||
func Clean() {
|
||||
utils.DeleteFile(dir + "/config.yml")
|
||||
utils.DeleteFile(dir + "/statping.db")
|
||||
utils.DeleteDirectory(dir + "/assets")
|
||||
utils.DeleteDirectory(dir + "/logs")
|
||||
core.CoreApp = core.NewCore()
|
||||
source.Assets()
|
||||
//core.CloseDB()
|
||||
os.Unsetenv("DB_CONN")
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
|
|
|
@ -147,10 +147,12 @@ func (c Core) AllOnline() bool {
|
|||
// SelectCore will return the CoreApp global variable and the settings/configs for Statping
|
||||
func SelectCore() (*Core, error) {
|
||||
if DbSession == nil {
|
||||
log.Traceln("database has not been initiated yet.")
|
||||
return nil, errors.New("database has not been initiated yet.")
|
||||
}
|
||||
exists := DbSession.HasTable("core")
|
||||
if !exists {
|
||||
log.Errorf("core database has not been setup yet, does not have the 'core' table")
|
||||
return nil, errors.New("core database has not been setup yet.")
|
||||
}
|
||||
db := coreDB().First(&CoreApp)
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
"github.com/hunterlong/statping/source"
|
||||
"github.com/hunterlong/statping/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
@ -37,31 +38,27 @@ func init() {
|
|||
}
|
||||
|
||||
func TestNewCore(t *testing.T) {
|
||||
if skipNewDb {
|
||||
t.SkipNow()
|
||||
}
|
||||
utils.DeleteFile(dir + "/config.yml")
|
||||
utils.DeleteFile(dir + "/statup.db")
|
||||
CoreApp = NewCore()
|
||||
assert.NotNil(t, CoreApp)
|
||||
CoreApp.Name = "Tester"
|
||||
err := TmpRecords()
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, CoreApp)
|
||||
}
|
||||
|
||||
func TestDbConfig_Save(t *testing.T) {
|
||||
if skipNewDb {
|
||||
t.SkipNow()
|
||||
}
|
||||
var err error
|
||||
Configs = &DbConfig{
|
||||
DbConn: "sqlite",
|
||||
Project: "Tester",
|
||||
Location: dir,
|
||||
}
|
||||
Configs, err = Configs.Save()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "sqlite", Configs.DbConn)
|
||||
assert.NotEmpty(t, Configs.ApiKey)
|
||||
assert.NotEmpty(t, Configs.ApiSecret)
|
||||
t.SkipNow()
|
||||
//if skipNewDb {
|
||||
// t.SkipNow()
|
||||
//}
|
||||
//var err error
|
||||
//Configs = &DbConfig{
|
||||
// DbConn: "sqlite",
|
||||
// Project: "Tester",
|
||||
// Location: dir,
|
||||
//}
|
||||
//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) {
|
||||
|
@ -76,6 +73,7 @@ func TestDbConnection(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDropDatabase(t *testing.T) {
|
||||
t.SkipNow()
|
||||
if skipNewDb {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
@ -84,6 +82,7 @@ func TestDropDatabase(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSeedSchemaDatabase(t *testing.T) {
|
||||
t.SkipNow()
|
||||
if skipNewDb {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
@ -92,14 +91,13 @@ func TestSeedSchemaDatabase(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMigrateDatabase(t *testing.T) {
|
||||
t.SkipNow()
|
||||
err := Configs.MigrateDatabase()
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestSeedDatabase(t *testing.T) {
|
||||
if skipNewDb {
|
||||
t.SkipNow()
|
||||
}
|
||||
t.SkipNow()
|
||||
err := InsertLargeSampleData()
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
@ -117,6 +115,7 @@ func TestSelectCore(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInsertNotifierDB(t *testing.T) {
|
||||
t.SkipNow()
|
||||
if skipNewDb {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
@ -134,7 +133,7 @@ func TestEnvToConfig(t *testing.T) {
|
|||
os.Setenv("DESCRIPTION", "Testing Statping")
|
||||
os.Setenv("ADMIN_USER", "admin")
|
||||
os.Setenv("ADMIN_PASS", "admin123")
|
||||
os.Setenv("VERBOSE", "true")
|
||||
os.Setenv("VERBOSE", "1")
|
||||
config, err := EnvToConfig()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, config.DbConn, "sqlite")
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -185,6 +186,23 @@ func (db *DbConfig) InsertCore() (*Core, error) {
|
|||
return CoreApp, query.Error
|
||||
}
|
||||
|
||||
func findDbFile() string {
|
||||
filename := types.SqliteFilename
|
||||
err := filepath.Walk(utils.Directory, func(path string, info os.FileInfo, err error) error {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if filepath.Ext(path) == ".db" {
|
||||
filename = info.Name()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
return filename
|
||||
}
|
||||
|
||||
// Connect will attempt to connect to the sqlite, postgres, or mysql database
|
||||
func (db *DbConfig) Connect(retry bool, location string) error {
|
||||
postgresSSL := os.Getenv("POSTGRES_SSLMODE")
|
||||
|
@ -199,7 +217,8 @@ func (db *DbConfig) Connect(retry bool, location string) error {
|
|||
}
|
||||
switch dbType {
|
||||
case "sqlite":
|
||||
conn = location + "/statup.db"
|
||||
sqlFilename := findDbFile()
|
||||
conn = location + "/" + sqlFilename
|
||||
dbType = "sqlite3"
|
||||
case "mysql":
|
||||
host := fmt.Sprintf("%v:%v", Configs.DbHost, Configs.DbPort)
|
||||
|
@ -226,8 +245,7 @@ func (db *DbConfig) Connect(retry bool, location string) error {
|
|||
if dbType == "sqlite3" {
|
||||
dbSession.DB().SetMaxOpenConns(1)
|
||||
}
|
||||
err = dbSession.DB().Ping()
|
||||
if err == nil {
|
||||
if dbSession.DB().Ping() == nil {
|
||||
DbSession = dbSession
|
||||
if utils.VerboseMode >= 4 {
|
||||
DbSession.LogMode(true).Debug().SetLogger(log)
|
||||
|
@ -283,8 +301,8 @@ func (db *DbConfig) Update() error {
|
|||
|
||||
// Save will initially create the config.yml file
|
||||
func (db *DbConfig) Save() (*DbConfig, error) {
|
||||
var err error
|
||||
config, err := os.Create(utils.Directory + "/config.yml")
|
||||
defer config.Close()
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return nil, err
|
||||
|
@ -297,7 +315,6 @@ func (db *DbConfig) Save() (*DbConfig, error) {
|
|||
return nil, err
|
||||
}
|
||||
config.WriteString(string(data))
|
||||
defer config.Close()
|
||||
return db, err
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ var core = &types.Core{
|
|||
}
|
||||
|
||||
func injectDatabase() {
|
||||
utils.DeleteFile(dir + "/statup.db")
|
||||
utils.DeleteFile(dir + types.SqliteFilename)
|
||||
db, _ = gorm.Open("sqlite3", dir+"/statup.db")
|
||||
db.CreateTable(&Notification{})
|
||||
}
|
||||
|
|
102
core/sample.go
102
core/sample.go
|
@ -17,6 +17,7 @@ package core
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hunterlong/statping/core/notifier"
|
||||
"github.com/hunterlong/statping/types"
|
||||
"github.com/hunterlong/statping/utils"
|
||||
"time"
|
||||
|
@ -493,3 +494,104 @@ func insertHitRecords(since time.Time, amount int64) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
// TmpRecordsDelete will delete the temporary SQLite database file
|
||||
func TmpRecordsDelete() error {
|
||||
return utils.DeleteFile("/tmp/" + types.SqliteFilename)
|
||||
}
|
||||
|
||||
// TmpRecords is used for testing Statping. It will create a SQLite database file
|
||||
// with sample data and store it in the /tmp folder to be used by the tests.
|
||||
func TmpRecords() error {
|
||||
var sqlFile = utils.Directory + "/" + types.SqliteFilename
|
||||
var tmpSqlFile = "/tmp/" + types.SqliteFilename
|
||||
SampleHits = 480
|
||||
|
||||
exists := utils.FileExists(tmpSqlFile)
|
||||
if exists {
|
||||
log.Infoln(tmpSqlFile + " was found, copying the temp database to " + sqlFile)
|
||||
if err := utils.DeleteFile(sqlFile); err != nil {
|
||||
log.Infoln(sqlFile + " was not found")
|
||||
}
|
||||
if err := utils.CopyFile(tmpSqlFile, sqlFile); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infoln("loading config.yml from: " + utils.Directory)
|
||||
if _, err := LoadConfigFile(utils.Directory); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infoln("connecting to database")
|
||||
if err := Configs.Connect(false, utils.Directory); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infoln("selecting the Core variable")
|
||||
if _, err := SelectCore(); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infoln("inserting notifiers into database")
|
||||
if err := InsertNotifierDB(); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infoln("loading all services")
|
||||
if _, err := CoreApp.SelectAllServices(false); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := AttachNotifiers(); err != nil {
|
||||
return err
|
||||
}
|
||||
CoreApp.Notifications = notifier.AllCommunications
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Infoln(tmpSqlFile + " not found, creating a new database...")
|
||||
|
||||
var err error
|
||||
CoreApp = NewCore()
|
||||
CoreApp.Name = "Tester"
|
||||
Configs = &DbConfig{
|
||||
DbConn: "sqlite",
|
||||
Project: "Tester",
|
||||
Location: utils.Directory,
|
||||
}
|
||||
log.Infoln("saving config.yml in: " + utils.Directory)
|
||||
if Configs, err = Configs.Save(); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infoln("loading config.yml from: " + utils.Directory)
|
||||
if Configs, err = LoadConfigFile(utils.Directory); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infoln("connecting to database")
|
||||
if err := Configs.Connect(false, utils.Directory); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infoln("creating database")
|
||||
if err := Configs.CreateDatabase(); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infoln("migrating database")
|
||||
if err := Configs.MigrateDatabase(); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infoln("insert large sample data into database")
|
||||
if err := InsertLargeSampleData(); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infoln("selecting the Core variable")
|
||||
if CoreApp, err = SelectCore(); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infoln("inserting notifiers into database")
|
||||
if err := InsertNotifierDB(); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infoln("loading all services")
|
||||
if _, err := CoreApp.SelectAllServices(false); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infoln("copying sql database file to: " + "/tmp/" + types.SqliteFilename)
|
||||
if err := utils.CopyFile(sqlFile, "/tmp/"+types.SqliteFilename); err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -2,10 +2,13 @@ package handlers
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hunterlong/statping/core"
|
||||
_ "github.com/hunterlong/statping/notifiers"
|
||||
"github.com/hunterlong/statping/source"
|
||||
"github.com/hunterlong/statping/types"
|
||||
"github.com/hunterlong/statping/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -29,7 +32,9 @@ func init() {
|
|||
}
|
||||
|
||||
func TestResetDatabase(t *testing.T) {
|
||||
Clean()
|
||||
err := core.TmpRecords()
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, core.CoreApp)
|
||||
}
|
||||
|
||||
func TestFailedHTTPServer(t *testing.T) {
|
||||
|
@ -59,7 +64,7 @@ func TestSetupRoutes(t *testing.T) {
|
|||
Name: "Statping Setup Check",
|
||||
URL: "/setup",
|
||||
Method: "GET",
|
||||
ExpectedStatus: 200,
|
||||
ExpectedStatus: 303,
|
||||
},
|
||||
{
|
||||
Name: "Statping Run Setup",
|
||||
|
@ -68,7 +73,7 @@ func TestSetupRoutes(t *testing.T) {
|
|||
Body: form.Encode(),
|
||||
ExpectedStatus: 303,
|
||||
HttpHeaders: []string{"Content-Type=application/x-www-form-urlencoded"},
|
||||
ExpectedFiles: []string{utils.Directory + "/config.yml", utils.Directory + "/statup.db"},
|
||||
ExpectedFiles: []string{dir + "/config.yml", dir + "/" + types.SqliteFilename},
|
||||
}}
|
||||
|
||||
for _, v := range tests {
|
||||
|
@ -89,7 +94,7 @@ func TestMainApiRoutes(t *testing.T) {
|
|||
URL: "/api",
|
||||
Method: "GET",
|
||||
ExpectedStatus: 200,
|
||||
ExpectedContains: []string{`"name":"Tester","description":"This is an awesome test"`},
|
||||
ExpectedContains: []string{`"name":"Statping Sample Data","description":"This data is only used to testing"`},
|
||||
},
|
||||
{
|
||||
Name: "Statping Renew API Keys",
|
||||
|
@ -113,11 +118,7 @@ func TestMainApiRoutes(t *testing.T) {
|
|||
for _, v := range tests {
|
||||
t.Run(v.Name, func(t *testing.T) {
|
||||
_, t, err := RunHTTPTest(v, t)
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -234,11 +235,7 @@ func TestApiServiceRoutes(t *testing.T) {
|
|||
for _, v := range tests {
|
||||
t.Run(v.Name, func(t *testing.T) {
|
||||
_, t, err := RunHTTPTest(v, t)
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -278,11 +275,7 @@ func TestGroupAPIRoutes(t *testing.T) {
|
|||
for _, v := range tests {
|
||||
t.Run(v.Name, func(t *testing.T) {
|
||||
_, t, err := RunHTTPTest(v, t)
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -332,11 +325,7 @@ func TestApiUsersRoutes(t *testing.T) {
|
|||
for _, v := range tests {
|
||||
t.Run(v.Name, func(t *testing.T) {
|
||||
_, t, err := RunHTTPTest(v, t)
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -369,11 +358,7 @@ func TestApiNotifiersRoutes(t *testing.T) {
|
|||
for _, v := range tests {
|
||||
t.Run(v.Name, func(t *testing.T) {
|
||||
_, t, err := RunHTTPTest(v, t)
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -439,11 +424,7 @@ func TestMessagesApiRoutes(t *testing.T) {
|
|||
for _, v := range tests {
|
||||
t.Run(v.Name, func(t *testing.T) {
|
||||
_, t, err := RunHTTPTest(v, t)
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -478,11 +459,7 @@ func TestApiCheckinRoutes(t *testing.T) {
|
|||
for _, v := range tests {
|
||||
t.Run(v.Name, func(t *testing.T) {
|
||||
_, t, err := RunHTTPTest(v, t)
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -514,10 +491,7 @@ func RunHTTPTest(test HTTPTest, t *testing.T) (string, *testing.T, error) {
|
|||
}
|
||||
rr := httptest.NewRecorder()
|
||||
Router().ServeHTTP(rr, req)
|
||||
if err != nil {
|
||||
assert.Nil(t, err)
|
||||
return "", t, err
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(rr.Result().Body)
|
||||
if err != nil {
|
||||
assert.Nil(t, err)
|
||||
|
@ -540,9 +514,3 @@ func RunHTTPTest(test HTTPTest, t *testing.T) (string, *testing.T, error) {
|
|||
}
|
||||
return stringBody, t, err
|
||||
}
|
||||
|
||||
func Clean() {
|
||||
utils.DeleteFile(dir + "/config.yml")
|
||||
utils.DeleteFile(dir + "/statup.db")
|
||||
utils.DeleteDirectory(dir + "/logs")
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package handlers
|
|||
|
||||
import (
|
||||
"github.com/hunterlong/statping/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"net/url"
|
||||
"testing"
|
||||
)
|
||||
|
@ -27,7 +27,7 @@ func TestGenericRoutes(t *testing.T) {
|
|||
Method: "GET",
|
||||
ExpectedStatus: 200,
|
||||
ExpectedContains: []string{
|
||||
`<title>Tester Status</title>`,
|
||||
`<title>Statping Sample Data Status</title>`,
|
||||
`<footer>`,
|
||||
},
|
||||
},
|
||||
|
@ -100,7 +100,7 @@ func TestGenericRoutes(t *testing.T) {
|
|||
URL: "/metrics",
|
||||
Method: "GET",
|
||||
ExpectedStatus: 200,
|
||||
ExpectedContains: []string{"statping_total_services 5"},
|
||||
ExpectedContains: []string{"statping_total_services 15"},
|
||||
},
|
||||
{
|
||||
Name: "Last Log Line",
|
||||
|
@ -140,10 +140,7 @@ func TestGenericRoutes(t *testing.T) {
|
|||
for _, v := range tests {
|
||||
t.Run(v.Name, func(t *testing.T) {
|
||||
_, t, err := RunHTTPTest(v, t)
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -25,10 +25,7 @@ func TestMessageRoutes(t *testing.T) {
|
|||
for _, v := range tests {
|
||||
t.Run(v.Name, func(t *testing.T) {
|
||||
_, t, err := RunHTTPTest(v, t)
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -31,10 +31,7 @@ func TestServiceRoutes(t *testing.T) {
|
|||
for _, v := range tests {
|
||||
t.Run(v.Name, func(t *testing.T) {
|
||||
_, t, err := RunHTTPTest(v, t)
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -19,16 +19,13 @@ func TestUserRoutes(t *testing.T) {
|
|||
URL: "/user/2",
|
||||
Method: "GET",
|
||||
ExpectedStatus: 200,
|
||||
ExpectedContains: []string{`<title>Statping | adminuser2</title>`},
|
||||
ExpectedContains: []string{`<title>Statping | testadmin2</title>`},
|
||||
}}
|
||||
|
||||
for _, v := range tests {
|
||||
t.Run(v.Name, func(t *testing.T) {
|
||||
_, t, err := RunHTTPTest(v, t)
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
21
install.sh
21
install.sh
|
@ -15,14 +15,23 @@ gpgurl=https://statping.com/statping.gpg
|
|||
repo=https://github.com/hunterlong/statping
|
||||
|
||||
statping_get_tarball() {
|
||||
url="$repo/releases/latest/download/statping-$1-$2.tar.gz"
|
||||
fext='tar.gz'
|
||||
if [ ${OS} == 'windows' ]; then
|
||||
fext='zip'
|
||||
ARCH='x64'
|
||||
fi
|
||||
url="$repo/releases/latest/download/statping-$1-$2.$fext"
|
||||
printf "$cyan> Downloading latest version for $OS $ARCH...\n$url $reset\n"
|
||||
# Get both the tarball and its GPG signature
|
||||
tarball_tmp=`mktemp -t statping.tar.gz.XXXXXXXXXX`
|
||||
if curl --fail -L -o "$tarball_tmp" "$url"; then
|
||||
# All this dance is because `tar --strip=1` does not work everywhere
|
||||
temp=$(mktemp -d statping.XXXXXXXXXX)
|
||||
tar xzf $tarball_tmp -C "$temp"
|
||||
if [ ${OS} == 'windows' ]; then
|
||||
unzip $tarball_tmp -d "$temp"
|
||||
else
|
||||
tar xzf $tarball_tmp -C "$temp"
|
||||
fi
|
||||
statping_verify_integrity "$temp"/statping
|
||||
printf "$green> Installing to $DEST/statping\n"
|
||||
mv "$temp"/statping "$DEST"
|
||||
|
@ -141,6 +150,14 @@ getOS() {
|
|||
OS='windows'
|
||||
DEST=/usr/local/bin
|
||||
;;
|
||||
'MINGW*')
|
||||
OS='windows'
|
||||
DEST=/usr/local/bin
|
||||
;;
|
||||
'CYGWIN*')
|
||||
OS='windows'
|
||||
DEST=/usr/local/bin
|
||||
;;
|
||||
'Darwin')
|
||||
OS='osx'
|
||||
DEST=/usr/local/bin
|
||||
|
|
|
@ -74,8 +74,8 @@ func init() {
|
|||
}
|
||||
|
||||
func injectDatabase() {
|
||||
utils.DeleteFile(dir + "/statup.db")
|
||||
db, err := gorm.Open("sqlite3", dir+"/statup.db")
|
||||
utils.DeleteFile(dir + types.SqliteFilename)
|
||||
db, err := gorm.Open("sqlite3", dir+"/statping.db")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -19,6 +19,9 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// SqliteFilename is the name of the SQLlite database file
|
||||
const SqliteFilename = "statping.db"
|
||||
|
||||
// AllNotifiers contains all the Notifiers loaded
|
||||
type AllNotifiers interface{}
|
||||
|
||||
|
|
|
@ -54,5 +54,6 @@ type DbConfig struct {
|
|||
Email string `yaml:"-"`
|
||||
Error error `yaml:"-"`
|
||||
Location string `yaml:"location"`
|
||||
SqlFile string `yaml:"sqlfile,omitempty"`
|
||||
LocalIP string `yaml:"-"`
|
||||
}
|
||||
|
|
|
@ -185,19 +185,39 @@ func FileExists(name string) bool {
|
|||
// DeleteFile("newfile.json")
|
||||
func DeleteFile(file string) error {
|
||||
Log.Infoln("deleting file: " + file)
|
||||
err := os.Remove(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return os.Remove(file)
|
||||
}
|
||||
|
||||
// DeleteDirectory will attempt to delete a directory and all contents inside
|
||||
// DeleteDirectory("assets")
|
||||
func DeleteDirectory(directory string) error {
|
||||
Log.Infoln("removing directory: " + directory)
|
||||
return os.RemoveAll(directory)
|
||||
}
|
||||
|
||||
// CopyFile will copy a file to a new directory
|
||||
// CopyFile("source.jpg", "/tmp/source.jpg")
|
||||
func CopyFile(src, dst string) error {
|
||||
Log.Infoln(fmt.Sprintf("copying file: %v to %v", src, dst))
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
_, err = io.Copy(out, in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return out.Close()
|
||||
}
|
||||
|
||||
// Command will run a terminal command with 'sh -c COMMAND' and return stdout and errOut as strings
|
||||
// in, out, err := Command("sass assets/scss assets/css/base.css")
|
||||
func Command(cmd string) (string, string, error) {
|
||||
|
|
Loading…
Reference in New Issue