mirror of https://github.com/statping/statping
removing unused code, tests
parent
0d9f6f19b2
commit
949747be70
2
Makefile
2
Makefile
|
@ -353,5 +353,5 @@ buildx-base: multiarch
|
||||||
multiarch:
|
multiarch:
|
||||||
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
|
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
|
||||||
|
|
||||||
.PHONY: all build multiarch build-all buildx-base buildx-dev buildx-latest build-alpine test-all test test-api docker frontend up down print_details lite sentry-release snapcraft build-linux build-mac build-win build-all postman
|
.PHONY: all build certs multiarch build-all buildx-base buildx-dev buildx-latest build-alpine test-all test test-api docker frontend up down print_details lite sentry-release snapcraft build-linux build-mac build-win build-all postman
|
||||||
.SILENT: travis_s3_creds
|
.SILENT: travis_s3_creds
|
||||||
|
|
|
@ -110,7 +110,6 @@ A:HOVER {
|
||||||
padding-bottom: 25px;
|
padding-bottom: 25px;
|
||||||
max-width: $max-width;
|
max-width: $max-width;
|
||||||
box-shadow: 0 .5rem 1rem rgba(0, 0, 0, 0.15) !important;
|
box-shadow: 0 .5rem 1rem rgba(0, 0, 0, 0.15) !important;
|
||||||
min-height: 98vh;
|
|
||||||
background-color: $container-color;
|
background-color: $container-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
var (
|
var (
|
||||||
log = utils.Log.WithField("type", "source")
|
log = utils.Log.WithField("type", "source")
|
||||||
TmplBox *rice.Box // HTML and other small files from the 'source/tmpl' directory, this will be loaded into '/assets'
|
TmplBox *rice.Box // HTML and other small files from the 'source/tmpl' directory, this will be loaded into '/assets'
|
||||||
DefaultScss = []string{"scss/main.scss", "scss/base.scss", "scss/mobile.scss"}
|
DefaultScss = []string{"scss/base.scss", "scss/layout.scss", "scss/main.scss", "scss/mixin.scss", "scss/mobile.scss", "scss/variables.scss"}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assets will load the Rice boxes containing the CSS, SCSS, JS, and HTML files.
|
// Assets will load the Rice boxes containing the CSS, SCSS, JS, and HTML files.
|
||||||
|
|
|
@ -38,10 +38,12 @@ func TestInit(t *testing.T) {
|
||||||
db, err := database.OpenTester()
|
db, err := database.OpenTester()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
SetDB(db)
|
SetDB(db)
|
||||||
|
failures.SetDB(db)
|
||||||
db.AutoMigrate(&Checkin{}, &CheckinHit{}, &failures.Failure{})
|
db.AutoMigrate(&Checkin{}, &CheckinHit{}, &failures.Failure{})
|
||||||
db.Create(&testCheckin)
|
db.Create(&testCheckin)
|
||||||
for _, v := range testCheckinHits {
|
for _, v := range testCheckinHits {
|
||||||
db.Create(&v)
|
err := db.Create(&v).Error()
|
||||||
|
require.Nil(t, err)
|
||||||
}
|
}
|
||||||
assert.True(t, db.HasTable(&Checkin{}))
|
assert.True(t, db.HasTable(&Checkin{}))
|
||||||
assert.True(t, db.HasTable(&CheckinHit{}))
|
assert.True(t, db.HasTable(&CheckinHit{}))
|
||||||
|
|
|
@ -16,7 +16,7 @@ func SetDB(database database.Database) {
|
||||||
|
|
||||||
func (c *Checkin) AfterFind() {
|
func (c *Checkin) AfterFind() {
|
||||||
c.AllHits = c.Hits()
|
c.AllHits = c.Hits()
|
||||||
c.AllFailures = c.Failures().LastAmount(64)
|
c.AllFailures = c.Failures().LastAmount(32)
|
||||||
if last := c.LastHit(); last != nil {
|
if last := c.LastHit(); last != nil {
|
||||||
c.LastHitTime = last.CreatedAt
|
c.LastHitTime = last.CreatedAt
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,12 +43,3 @@ func (c *Checkin) IsRunning() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// String will return a Checkin API string
|
|
||||||
func (c *Checkin) String() string {
|
|
||||||
return c.ApiKey
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Checkin) Link() string {
|
|
||||||
return fmt.Sprintf("%v/checkin/%v", "DOMAINHERE", c.ApiKey)
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,20 +9,6 @@ import (
|
||||||
|
|
||||||
var log = utils.Log.WithField("type", "checkin")
|
var log = utils.Log.WithField("type", "checkin")
|
||||||
|
|
||||||
// RecheckCheckinFailure will check if a Service Checkin has been reported yet
|
|
||||||
func (c *Checkin) RecheckCheckinFailure(guard chan struct{}) {
|
|
||||||
between := utils.Now().Sub(utils.Now()).Seconds()
|
|
||||||
if between > float64(c.Interval) {
|
|
||||||
fmt.Println("rechecking every 15 seconds!")
|
|
||||||
time.Sleep(15 * time.Second)
|
|
||||||
guard <- struct{}{}
|
|
||||||
c.RecheckCheckinFailure(guard)
|
|
||||||
} else {
|
|
||||||
fmt.Println("i recovered!!")
|
|
||||||
}
|
|
||||||
<-guard
|
|
||||||
}
|
|
||||||
|
|
||||||
// checkinRoutine 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() {
|
||||||
reCheck := c.Period()
|
reCheck := c.Period()
|
||||||
|
|
|
@ -503,6 +503,62 @@ func TestServices(t *testing.T) {
|
||||||
assert.Len(t, all, 1)
|
assert.Len(t, all, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Test Load services.yml", func(t *testing.T) {
|
||||||
|
|
||||||
|
file := `x-tcpservice: &tcpservice
|
||||||
|
type: tcp
|
||||||
|
check_interval: 60
|
||||||
|
timeout: 15
|
||||||
|
allow_notifications: true
|
||||||
|
notify_after: 0
|
||||||
|
notify_all_changes: true
|
||||||
|
public: true
|
||||||
|
redirect: true
|
||||||
|
|
||||||
|
x-httpservice: &httpservice
|
||||||
|
type: http
|
||||||
|
method: GET
|
||||||
|
check_interval: 45
|
||||||
|
timeout: 10
|
||||||
|
expected_status: 200
|
||||||
|
allow_notifications: true
|
||||||
|
notify_after: 2
|
||||||
|
notify_all_changes: true
|
||||||
|
public: true
|
||||||
|
redirect: true
|
||||||
|
|
||||||
|
services:
|
||||||
|
|
||||||
|
- name: Statping Demo
|
||||||
|
domain: https://demo.statping.com
|
||||||
|
<<: *httpservice
|
||||||
|
|
||||||
|
- name: Portainer
|
||||||
|
domain: portainer
|
||||||
|
port: 9000
|
||||||
|
<<: *tcpservice
|
||||||
|
|
||||||
|
- name: Statping Github
|
||||||
|
domain: https://github.com/statping/statping
|
||||||
|
<<: *httpservice`
|
||||||
|
|
||||||
|
err := utils.SaveFile(utils.Directory+"/services.yml", []byte(file))
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
assert.FileExists(t, utils.Directory+"/services.yml")
|
||||||
|
|
||||||
|
srvs, err := LoadServicesYaml()
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.Equal(t, 3, len(srvs.Services))
|
||||||
|
|
||||||
|
assert.Equal(t, "Statping Demo", srvs.Services[0].Name)
|
||||||
|
assert.Equal(t, 45, srvs.Services[0].Interval)
|
||||||
|
assert.Equal(t, "https://demo.statping.com", srvs.Services[0].Domain)
|
||||||
|
|
||||||
|
err = utils.DeleteFile(utils.Directory + "/services.yml")
|
||||||
|
require.Nil(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("Test Close", func(t *testing.T) {
|
t.Run("Test Close", func(t *testing.T) {
|
||||||
assert.Nil(t, db.Close())
|
assert.Nil(t, db.Close())
|
||||||
})
|
})
|
||||||
|
|
|
@ -22,7 +22,3 @@ func (d Duration) Human() string {
|
||||||
func FormatDuration(d time.Duration) string {
|
func FormatDuration(d time.Duration) string {
|
||||||
return durafmt.ParseShort(d).LimitFirstN(3).String()
|
return durafmt.ParseShort(d).LimitFirstN(3).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func rev(f float64) float64 {
|
|
||||||
return f * -1
|
|
||||||
}
|
|
||||||
|
|
|
@ -129,7 +129,14 @@ func TestTimestamp_Ago(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHashPassword(t *testing.T) {
|
func TestHashPassword(t *testing.T) {
|
||||||
assert.Equal(t, 60, len(HashPassword("password123")))
|
pass := HashPassword("password123")
|
||||||
|
assert.Equal(t, 60, len(pass))
|
||||||
|
assert.True(t, CheckHash("password123", pass))
|
||||||
|
assert.False(t, CheckHash("wrongpasswd", pass))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSha256Hash(t *testing.T) {
|
||||||
|
assert.Equal(t, "ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f", Sha256Hash("password123"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewSHA1Hash(t *testing.T) {
|
func TestNewSHA1Hash(t *testing.T) {
|
||||||
|
@ -190,3 +197,12 @@ func TestConfigLoad(t *testing.T) {
|
||||||
assert.True(t, b("SAMPLE_DATA"))
|
assert.True(t, b("SAMPLE_DATA"))
|
||||||
assert.True(t, b("ALLOW_REPORTS"))
|
assert.True(t, b("ALLOW_REPORTS"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPerlin(t *testing.T) {
|
||||||
|
p := NewPerlin(2, 2, 5, Now().UnixNano())
|
||||||
|
require.NotNil(t, p)
|
||||||
|
|
||||||
|
for hi := 1.; hi <= 100.; hi++ {
|
||||||
|
assert.NotZero(t, p.Noise1D(hi/500))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue