Permalink
Browse files

testing - cleanup

  • Loading branch information...
hunterlong committed Feb 6, 2019
1 parent 68f0654 commit 55f53229858c969b95c9a6c791d75d0ed1a4e6ac
Showing with 357 additions and 416 deletions.
  1. +1 −1 Makefile
  2. +0 −2 cmd/cli.go
  3. +17 −12 cmd/cli_test.go
  4. +8 −0 core/failures.go
  5. +238 −250 dev/COVERAGE.html
  6. +1 −9 dev/README.md
  7. +0 −84 handlers/index.go
  8. +0 −1 handlers/routes.go
  9. +7 −0 source/js/main.js
  10. +8 −9 source/source.go
  11. +1 −1 source/wiki.go
  12. +24 −11 utils/utils.go
  13. +51 −35 utils/utils_test.go
  14. +1 −1 version.txt
@@ -235,7 +235,7 @@ dev-deps:
# remove files for a clean compile/build
clean:
rm -rf ./{logs,assets,plugins,statup.db,config.yml,.sass-cache,config.yml,statping,build,.sass-cache,statup.db,index.html,vendor}
rm -rf cmd/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
rm -rf cmd/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log,*.html,*.json}
rm -rf core/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
rm -rf handlers/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
rm -rf notifiers/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
@@ -41,8 +41,6 @@ func catchCLI(args []string) error {
loadDotEnvs()

switch args[0] {
case "app":
handlers.DesktopInit(ipAddress, port)
case "version":
if COMMIT != "" {
fmt.Printf("Statping v%v (%v)\n", VERSION, COMMIT)
@@ -60,15 +60,24 @@ func TestHelpCommand(t *testing.T) {
assert.True(t, c.StdoutContains("statping help - Shows the user basic information about Statping"))
}

func TestExportCommand(t *testing.T) {
func TestStaticCommand(t *testing.T) {
cmd := helperCommand(nil, "static")
var got = make(chan string)
commandAndSleep(cmd, time.Duration(10*time.Second), got)
gg, _ := <-got
t.Log(gg)
assert.Contains(t, gg, "Exporting Static 'index.html' page...")
assert.Contains(t, gg, "Exported Statping index page: 'index.html'")
assert.True(t, fileExists(dir+"/index.html"))
assert.FileExists(t, dir+"/index.html")
}

func TestExportCommand(t *testing.T) {
cmd := helperCommand(nil, "export")
var got = make(chan string)
commandAndSleep(cmd, time.Duration(10*time.Second), got)
gg, _ := <-got
t.Log(gg)
assert.FileExists(t, dir+"/statping-export.json")
}

func TestUpdateCommand(t *testing.T) {
@@ -123,9 +132,12 @@ func TestSassCLI(t *testing.T) {
}

func TestUpdateCLI(t *testing.T) {
t.SkipNow()
run := catchCLI([]string{"update"})
assert.EqualError(t, run, "end")
cmd := helperCommand(nil, "update")
var got = make(chan string)
commandAndSleep(cmd, time.Duration(15*time.Second), got)
gg, _ := <-got
t.Log(gg)
assert.Contains(t, gg, "version")
}

func TestTestPackageCLI(t *testing.T) {
@@ -168,13 +180,6 @@ func runCommand(c *exec.Cmd, out chan<- string) {
out <- string(bout)
}

func fileExists(file string) bool {
if _, err := os.Stat(file); os.IsNotExist(err) {
return false
}
return true
}

func Clean() {
utils.DeleteFile(dir + "/config.yml")
utils.DeleteFile(dir + "/statping.db")
@@ -205,5 +205,13 @@ func (f *Failure) ParseError() string {
if err {
return fmt.Sprintf("Domain is offline or not found")
}
err = strings.Contains(f.Issue, "i/o timeout")
if err {
return fmt.Sprintf("Connection Timed Out")
}
err = strings.Contains(f.Issue, "Client.Timeout exceeded while reading body")
if err {
return fmt.Sprintf("Timed Out on Response Body")
}
return f.Issue
}

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1342,14 +1342,6 @@ More info on: https://github.com/hunterlong/statping
## Usage
#### func DesktopInit
```go
func DesktopInit(ip string, port int)
```
DesktopInit will run the Statping server on a specific IP and port using SQLite
database
#### func ExecuteResponse
```go
@@ -1601,7 +1593,7 @@ and sass installed on your local system.
More info on: https://github.com/hunterlong/statping
Code generated by go generate; DO NOT EDIT. This file was generated by robots at
2019-02-06 10:11:39.973396 -0800 PST m=+0.560856203
2019-02-06 12:42:08.202468 -0800 PST m=+0.598756678
This contains the most recently Markdown source for the Statping Wiki.
@@ -18,8 +18,6 @@ package handlers
import (
"encoding/json"
"github.com/hunterlong/statping/core"
"github.com/hunterlong/statping/types"
"github.com/hunterlong/statping/utils"
"net/http"
)

@@ -39,85 +37,3 @@ func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
}
json.NewEncoder(w).Encode(health)
}

func trayHandler(w http.ResponseWriter, r *http.Request) {
ExecuteResponse(w, r, "tray.gohtml", core.CoreApp, nil)
}

// DesktopInit will run the Statping server on a specific IP and port using SQLite database
func DesktopInit(ip string, port int) {
var err error
exists := utils.FileExists(utils.Directory + "/statup.db")
if exists {
core.Configs, err = core.LoadConfigFile(utils.Directory)
if err != nil {
utils.Log(3, err)
return
}
err = core.Configs.Connect(false, utils.Directory)
if err != nil {
utils.Log(3, err)
return
}
core.InitApp()
RunHTTPServer(ip, port)
}

config := &core.DbConfig{
DbConn: "sqlite",
Project: "Statping",
Description: "Statping running as an App!",
Domain: "http://localhost",
Username: "admin",
Password: "admin",
Email: "user@email.com",
Error: nil,
Location: utils.Directory,
}

config, err = config.Save()
if err != nil {
utils.Log(4, err)
}

config.DropDatabase()
config.CreateDatabase()
core.CoreApp = config.CreateCore()

if err != nil {
utils.Log(3, err)
return
}

core.Configs, err = core.LoadConfigFile(utils.Directory)
if err != nil {
utils.Log(3, err)
config.Error = err
return
}

err = core.Configs.Connect(false, utils.Directory)
if err != nil {
utils.Log(3, err)
core.DeleteConfig()
config.Error = err
return
}

admin := core.ReturnUser(&types.User{
Username: config.Username,
Password: config.Password,
Email: config.Email,
Admin: types.NewNullBool(true),
})
admin.Create()

core.InsertSampleData()

config.ApiKey = core.CoreApp.ApiKey
config.ApiSecret = core.CoreApp.ApiSecret
config.Update()

core.InitApp()
RunHTTPServer(ip, port)
}
@@ -146,7 +146,6 @@ func Router() *mux.Router {
// API Generic Routes
r.Handle("/metrics", http.HandlerFunc(prometheusHandler))
r.Handle("/health", http.HandlerFunc(healthCheckHandler))
r.Handle("/tray", http.HandlerFunc(trayHandler))
r.Handle("/.well-known/", http.StripPrefix("/.well-known/", http.FileServer(http.Dir(dir+"/.well-known"))))

r.NotFoundHandler = http.HandlerFunc(error404Handler)
@@ -178,6 +178,13 @@ function FailureAnnotations(chart, service, start=0, end=9999999999, group="hour
});
}


$('input[id=service_name]').on('keyup', function() {
var url = $(this).val();
url = url.replace(/[^\w\s]/gi, '').replace(/\s+/g, '-').toLowerCase();
$('#permalink').val(url);
});

$('input[type=checkbox]').on('change', function() {
var element = $(this).attr('id');
$("#"+element+"-value").val(this.checked ? "true" : "false")
@@ -103,10 +103,11 @@ func UsingAssets(folder string) bool {

// SaveAsset will save an asset to the '/assets/' folder.
func SaveAsset(data []byte, folder, file string) error {
utils.Log(1, fmt.Sprintf("Saving %v", folder+"/assets/"+file))
err := ioutil.WriteFile(folder+"/assets/"+file, data, 0744)
location := folder + "/assets/" + file
utils.Log(1, fmt.Sprintf("Saving %v", location))
err := utils.SaveFile(location, data)
if err != nil {
utils.Log(3, fmt.Sprintf("Failed to save %v/%v, %v", folder, file, err))
utils.Log(3, fmt.Sprintf("Failed to save %v, %v", location, err))
return err
}
return nil
@@ -168,16 +169,14 @@ func CopyAllToPublic(box *rice.Box, folder string) error {
}
if info.IsDir() {
folder := fmt.Sprintf("%v/assets/%v/%v", utils.Directory, folder, info.Name())
MakePublicFolder(folder)
return nil
return MakePublicFolder(folder)
}
file, err := box.Bytes(path)
if err != nil {
return nil
return err
}
filePath := fmt.Sprintf("%v%v", folder, path)
SaveAsset(file, utils.Directory, filePath)
return nil
filePath := fmt.Sprintf("%v/%v", folder, path)
return SaveAsset(file, utils.Directory, filePath)
})
return err
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -41,7 +41,12 @@ func init() {
if os.Getenv("STATPING_DIR") != "" {
Directory = os.Getenv("STATPING_DIR")
} else {
Directory = dir()
dir, err := os.Getwd()
if err != nil {
Directory = "."
return
}
Directory = dir
}
}

@@ -51,6 +56,23 @@ func ToInt(s interface{}) int64 {
case string:
val, _ := strconv.Atoi(v)
return int64(val)
case []byte:
val, _ := strconv.Atoi(string(v))
return int64(val)
case float32:
return int64(v)
case float64:
return int64(v)
case int:
return int64(v)
case int16:
return int64(v)
case int32:
return int64(v)
case int64:
return v
case uint:
return int64(v)
default:
return 0
}
@@ -59,7 +81,7 @@ func ToInt(s interface{}) int64 {
// ToString converts a int to a string
func ToString(s interface{}) string {
switch v := s.(type) {
case int, int32, int64:
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
return fmt.Sprintf("%v", v)
case float32, float64:
return fmt.Sprintf("%f", v)
@@ -76,15 +98,6 @@ func ToString(s interface{}) string {
}
}

// dir returns the current working directory
func dir() string {
dir, err := os.Getwd()
if err != nil {
return "."
}
return dir
}

type Timestamp time.Time
type Timestamper interface {
Ago() string
Oops, something went wrong.

0 comments on commit 55f5322

Please sign in to comment.