From 949747be7065a4ab0e6aa53c28c68339bb561b8f Mon Sep 17 00:00:00 2001 From: hunterlong Date: Sun, 19 Jul 2020 23:07:29 -0700 Subject: [PATCH] removing unused code, tests --- Makefile | 2 +- frontend/src/assets/scss/layout.scss | 1 - source/source.go | 2 +- types/checkins/checkins_test.go | 4 +- types/checkins/database.go | 2 +- types/checkins/methods.go | 9 ----- types/checkins/routine.go | 14 ------- types/services/services_test.go | 56 ++++++++++++++++++++++++++++ utils/time.go | 4 -- utils/utils_test.go | 18 ++++++++- 10 files changed, 79 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index f1058f47..d3af9481 100644 --- a/Makefile +++ b/Makefile @@ -353,5 +353,5 @@ buildx-base: multiarch multiarch: 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 diff --git a/frontend/src/assets/scss/layout.scss b/frontend/src/assets/scss/layout.scss index 1fb837d0..80709572 100644 --- a/frontend/src/assets/scss/layout.scss +++ b/frontend/src/assets/scss/layout.scss @@ -110,7 +110,6 @@ A:HOVER { padding-bottom: 25px; max-width: $max-width; box-shadow: 0 .5rem 1rem rgba(0, 0, 0, 0.15) !important; - min-height: 98vh; background-color: $container-color; } diff --git a/source/source.go b/source/source.go index c35a739c..d8208345 100644 --- a/source/source.go +++ b/source/source.go @@ -16,7 +16,7 @@ import ( var ( 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' - 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. diff --git a/types/checkins/checkins_test.go b/types/checkins/checkins_test.go index 31ccdf6d..170ff326 100644 --- a/types/checkins/checkins_test.go +++ b/types/checkins/checkins_test.go @@ -38,10 +38,12 @@ func TestInit(t *testing.T) { db, err := database.OpenTester() require.Nil(t, err) SetDB(db) + failures.SetDB(db) db.AutoMigrate(&Checkin{}, &CheckinHit{}, &failures.Failure{}) db.Create(&testCheckin) 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(&CheckinHit{})) diff --git a/types/checkins/database.go b/types/checkins/database.go index b7676f6c..48554e01 100644 --- a/types/checkins/database.go +++ b/types/checkins/database.go @@ -16,7 +16,7 @@ func SetDB(database database.Database) { func (c *Checkin) AfterFind() { c.AllHits = c.Hits() - c.AllFailures = c.Failures().LastAmount(64) + c.AllFailures = c.Failures().LastAmount(32) if last := c.LastHit(); last != nil { c.LastHitTime = last.CreatedAt } diff --git a/types/checkins/methods.go b/types/checkins/methods.go index ec28f59e..8e1054a7 100644 --- a/types/checkins/methods.go +++ b/types/checkins/methods.go @@ -43,12 +43,3 @@ func (c *Checkin) IsRunning() bool { 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) -} diff --git a/types/checkins/routine.go b/types/checkins/routine.go index d3cb422b..5ac38ff5 100644 --- a/types/checkins/routine.go +++ b/types/checkins/routine.go @@ -9,20 +9,6 @@ import ( 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 func (c *Checkin) checkinRoutine() { reCheck := c.Period() diff --git a/types/services/services_test.go b/types/services/services_test.go index 8cfa989d..71b17681 100644 --- a/types/services/services_test.go +++ b/types/services/services_test.go @@ -503,6 +503,62 @@ func TestServices(t *testing.T) { 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) { assert.Nil(t, db.Close()) }) diff --git a/utils/time.go b/utils/time.go index 1cbdd736..76c56b79 100644 --- a/utils/time.go +++ b/utils/time.go @@ -22,7 +22,3 @@ func (d Duration) Human() string { func FormatDuration(d time.Duration) string { return durafmt.ParseShort(d).LimitFirstN(3).String() } - -func rev(f float64) float64 { - return f * -1 -} diff --git a/utils/utils_test.go b/utils/utils_test.go index 961a3315..a907d494 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -129,7 +129,14 @@ func TestTimestamp_Ago(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) { @@ -190,3 +197,12 @@ func TestConfigLoad(t *testing.T) { assert.True(t, b("SAMPLE_DATA")) 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)) + } +}