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"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -28,15 +29,22 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
source.Assets()
|
||||
utils.InitLogs()
|
||||
source.Assets()
|
||||
dir = utils.Directory
|
||||
core.New("test")
|
||||
}
|
||||
|
||||
func TestFailedHTTPServer(t *testing.T) {
|
||||
err := RunHTTPServer("missinghost", 0)
|
||||
assert.Error(t, err)
|
||||
var err error
|
||||
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) {
|
||||
|
|
|
@ -11,7 +11,6 @@ func (c *Checkin) BeforeCreate() error {
|
|||
|
||||
func (c *Checkin) AfterCreate() error {
|
||||
c.Start()
|
||||
go c.CheckinRoutine()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ func (c *Checkin) Grace() time.Duration {
|
|||
// Start will create a channel for the checkin checking go routine
|
||||
func (c *Checkin) Start() {
|
||||
c.Running = make(chan bool)
|
||||
go c.checkinRoutine()
|
||||
}
|
||||
|
||||
// Close will stop the checkin routine
|
||||
|
|
|
@ -23,8 +23,8 @@ func (c *Checkin) RecheckCheckinFailure(guard chan struct{}) {
|
|||
<-guard
|
||||
}
|
||||
|
||||
// Routine for checking if the last Checkin was within its interval
|
||||
func (c *Checkin) CheckinRoutine() {
|
||||
// checkinRoutine for checking if the last Checkin was within its interval
|
||||
func (c *Checkin) checkinRoutine() {
|
||||
lastHit := c.LastHit()
|
||||
if lastHit == nil {
|
||||
return
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
func CheckinProcess(s *Service) {
|
||||
for _, c := range s.Checkins() {
|
||||
c.Start()
|
||||
go c.CheckinRoutine()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -165,6 +165,8 @@ func TestStartExampleEndpoints(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestServices(t *testing.T) {
|
||||
err := utils.InitLogs()
|
||||
require.Nil(t, err)
|
||||
db, err := database.OpenTester()
|
||||
require.Nil(t, err)
|
||||
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"`
|
||||
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"`
|
||||
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"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at" yaml:"-"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" yaml:"-"`
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
)
|
||||
|
||||
func TestCreateLog(t *testing.T) {
|
||||
Directory = os.Getenv("STATPING_DIR")
|
||||
err := createLog(Directory)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
@ -20,7 +21,7 @@ func TestReplaceValue(t *testing.T) {
|
|||
assert.Equal(t, true, replaceVal(true))
|
||||
assert.Equal(t, 42, replaceVal(42))
|
||||
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) {
|
||||
|
@ -176,8 +177,8 @@ func TestHttpRequest(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConfigLoad(t *testing.T) {
|
||||
initCLI()
|
||||
setDefaults()
|
||||
InitLogs()
|
||||
initEnvs()
|
||||
|
||||
s := Params.GetString
|
||||
b := Params.GetBool
|
||||
|
|
Loading…
Reference in New Issue