Skip to content

Commit

Permalink
testing - cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlong committed Feb 6, 2019
1 parent 68f0654 commit 55f5322
Show file tree
Hide file tree
Showing 14 changed files with 357 additions and 416 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 0 additions & 2 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 17 additions & 12 deletions cmd/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions core/failures.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
488 changes: 238 additions & 250 deletions dev/COVERAGE.html

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
84 changes: 0 additions & 84 deletions handlers/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}
1 change: 0 additions & 1 deletion handlers/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions source/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
17 changes: 8 additions & 9 deletions source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion source/wiki.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 24 additions & 11 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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
}
Expand All @@ -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)
Expand All @@ -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
Expand Down
Loading

0 comments on commit 55f5322

Please sign in to comment.