mirror of https://github.com/statping/statping
code cleanup, debug mode (pprof), new env vars: DISABLE_HTTP, LOGS_MAX_COUNT, LOGS_MAX_AGE, LOGS_MAX_SIZE, DISABLE_COLORS, fixed DISABLE_LOGS bool env, mobile notifier update to fit the next mobile app update,
parent
c06eba3bc8
commit
6156a55e12
|
@ -21,6 +21,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -28,15 +29,22 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
source.Assets()
|
|
||||||
utils.InitLogs()
|
utils.InitLogs()
|
||||||
|
source.Assets()
|
||||||
dir = utils.Directory
|
dir = utils.Directory
|
||||||
core.New("test")
|
core.New("test")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFailedHTTPServer(t *testing.T) {
|
func TestFailedHTTPServer(t *testing.T) {
|
||||||
err := RunHTTPServer("missinghost", 0)
|
var err error
|
||||||
assert.Error(t, err)
|
go func(err error) {
|
||||||
|
err = RunHTTPServer()
|
||||||
|
}(err)
|
||||||
|
go func() {
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
StopHTTPServer(nil)
|
||||||
|
}()
|
||||||
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetupRoutes(t *testing.T) {
|
func TestSetupRoutes(t *testing.T) {
|
||||||
|
|
|
@ -11,7 +11,6 @@ func (c *Checkin) BeforeCreate() error {
|
||||||
|
|
||||||
func (c *Checkin) AfterCreate() error {
|
func (c *Checkin) AfterCreate() error {
|
||||||
c.Start()
|
c.Start()
|
||||||
go c.CheckinRoutine()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ func (c *Checkin) Grace() time.Duration {
|
||||||
// Start will create a channel for the checkin checking go routine
|
// Start will create a channel for the checkin checking go routine
|
||||||
func (c *Checkin) Start() {
|
func (c *Checkin) Start() {
|
||||||
c.Running = make(chan bool)
|
c.Running = make(chan bool)
|
||||||
|
go c.checkinRoutine()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close will stop the checkin routine
|
// Close will stop the checkin routine
|
||||||
|
|
|
@ -23,8 +23,8 @@ func (c *Checkin) RecheckCheckinFailure(guard chan struct{}) {
|
||||||
<-guard
|
<-guard
|
||||||
}
|
}
|
||||||
|
|
||||||
// Routine for checking if the last Checkin was within its interval
|
// checkinRoutine for checking if the last Checkin was within its interval
|
||||||
func (c *Checkin) CheckinRoutine() {
|
func (c *Checkin) checkinRoutine() {
|
||||||
lastHit := c.LastHit()
|
lastHit := c.LastHit()
|
||||||
if lastHit == nil {
|
if lastHit == nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
func CheckinProcess(s *Service) {
|
func CheckinProcess(s *Service) {
|
||||||
for _, c := range s.Checkins() {
|
for _, c := range s.Checkins() {
|
||||||
c.Start()
|
c.Start()
|
||||||
go c.CheckinRoutine()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,6 +165,8 @@ func TestStartExampleEndpoints(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServices(t *testing.T) {
|
func TestServices(t *testing.T) {
|
||||||
|
err := utils.InitLogs()
|
||||||
|
require.Nil(t, err)
|
||||||
db, err := database.OpenTester()
|
db, err := database.OpenTester()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
db.AutoMigrate(&Service{}, &hits.Hit{}, &checkins.Checkin{}, &checkins.CheckinHit{}, &failures.Failure{})
|
db.AutoMigrate(&Service{}, &hits.Hit{}, &checkins.Checkin{}, &checkins.CheckinHit{}, &failures.Failure{})
|
||||||
|
|
|
@ -28,7 +28,7 @@ type Service struct {
|
||||||
TLSCertKey null.NullString `gorm:"column:tls_cert_key" json:"tls_cert_key" scope:"user,admin" yaml:"tls_cert_key"`
|
TLSCertKey null.NullString `gorm:"column:tls_cert_key" json:"tls_cert_key" scope:"user,admin" yaml:"tls_cert_key"`
|
||||||
TLSCertRoot null.NullString `gorm:"column:tls_cert_root" json:"tls_cert_root" scope:"user,admin" yaml:"tls_cert_root"`
|
TLSCertRoot null.NullString `gorm:"column:tls_cert_root" json:"tls_cert_root" scope:"user,admin" yaml:"tls_cert_root"`
|
||||||
Headers null.NullString `gorm:"column:headers" json:"headers" scope:"user,admin" yaml:"headers"`
|
Headers null.NullString `gorm:"column:headers" json:"headers" scope:"user,admin" yaml:"headers"`
|
||||||
Permalink null.NullString `gorm:"column:permalink;unique;" json:"permalink" yaml:"permalink"`
|
Permalink null.NullString `gorm:"column:permalink" json:"permalink" yaml:"permalink"`
|
||||||
Redirect null.NullBool `gorm:"default:false;column:redirect" json:"redirect" scope:"user,admin" yaml:"redirect"`
|
Redirect null.NullBool `gorm:"default:false;column:redirect" json:"redirect" scope:"user,admin" yaml:"redirect"`
|
||||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at" yaml:"-"`
|
CreatedAt time.Time `gorm:"column:created_at" json:"created_at" yaml:"-"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" yaml:"-"`
|
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" yaml:"-"`
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateLog(t *testing.T) {
|
func TestCreateLog(t *testing.T) {
|
||||||
|
Directory = os.Getenv("STATPING_DIR")
|
||||||
err := createLog(Directory)
|
err := createLog(Directory)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +21,7 @@ func TestReplaceValue(t *testing.T) {
|
||||||
assert.Equal(t, true, replaceVal(true))
|
assert.Equal(t, true, replaceVal(true))
|
||||||
assert.Equal(t, 42, replaceVal(42))
|
assert.Equal(t, 42, replaceVal(42))
|
||||||
assert.Equal(t, "hello world", replaceVal("hello world"))
|
assert.Equal(t, "hello world", replaceVal("hello world"))
|
||||||
assert.Equal(t, "5s", replaceVal(time.Duration(5*time.Second)))
|
assert.Equal(t, "5s", replaceVal(5*time.Second))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInitLogs(t *testing.T) {
|
func TestInitLogs(t *testing.T) {
|
||||||
|
@ -176,8 +177,8 @@ func TestHttpRequest(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConfigLoad(t *testing.T) {
|
func TestConfigLoad(t *testing.T) {
|
||||||
initCLI()
|
InitLogs()
|
||||||
setDefaults()
|
initEnvs()
|
||||||
|
|
||||||
s := Params.GetString
|
s := Params.GetString
|
||||||
b := Params.GetBool
|
b := Params.GetBool
|
||||||
|
|
Loading…
Reference in New Issue