mirror of https://github.com/statping/statping
parent
68f0654b38
commit
55f5322985
2
Makefile
2
Makefile
|
@ -235,7 +235,7 @@ dev-deps:
|
||||||
# remove files for a clean compile/build
|
# remove files for a clean compile/build
|
||||||
clean:
|
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 ./{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 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 handlers/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
|
||||||
rm -rf notifiers/{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()
|
loadDotEnvs()
|
||||||
|
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
case "app":
|
|
||||||
handlers.DesktopInit(ipAddress, port)
|
|
||||||
case "version":
|
case "version":
|
||||||
if COMMIT != "" {
|
if COMMIT != "" {
|
||||||
fmt.Printf("Statping v%v (%v)\n", VERSION, COMMIT)
|
fmt.Printf("Statping v%v (%v)\n", VERSION, COMMIT)
|
||||||
|
|
|
@ -60,7 +60,7 @@ func TestHelpCommand(t *testing.T) {
|
||||||
assert.True(t, c.StdoutContains("statping help - Shows the user basic information about Statping"))
|
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")
|
cmd := helperCommand(nil, "static")
|
||||||
var got = make(chan string)
|
var got = make(chan string)
|
||||||
commandAndSleep(cmd, time.Duration(10*time.Second), got)
|
commandAndSleep(cmd, time.Duration(10*time.Second), got)
|
||||||
|
@ -68,7 +68,16 @@ func TestExportCommand(t *testing.T) {
|
||||||
t.Log(gg)
|
t.Log(gg)
|
||||||
assert.Contains(t, gg, "Exporting Static 'index.html' page...")
|
assert.Contains(t, gg, "Exporting Static 'index.html' page...")
|
||||||
assert.Contains(t, gg, "Exported Statping index page: 'index.html'")
|
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) {
|
func TestUpdateCommand(t *testing.T) {
|
||||||
|
@ -123,9 +132,12 @@ func TestSassCLI(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateCLI(t *testing.T) {
|
func TestUpdateCLI(t *testing.T) {
|
||||||
t.SkipNow()
|
cmd := helperCommand(nil, "update")
|
||||||
run := catchCLI([]string{"update"})
|
var got = make(chan string)
|
||||||
assert.EqualError(t, run, "end")
|
commandAndSleep(cmd, time.Duration(15*time.Second), got)
|
||||||
|
gg, _ := <-got
|
||||||
|
t.Log(gg)
|
||||||
|
assert.Contains(t, gg, "version")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTestPackageCLI(t *testing.T) {
|
func TestTestPackageCLI(t *testing.T) {
|
||||||
|
@ -168,13 +180,6 @@ func runCommand(c *exec.Cmd, out chan<- string) {
|
||||||
out <- string(bout)
|
out <- string(bout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fileExists(file string) bool {
|
|
||||||
if _, err := os.Stat(file); os.IsNotExist(err) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func Clean() {
|
func Clean() {
|
||||||
utils.DeleteFile(dir + "/config.yml")
|
utils.DeleteFile(dir + "/config.yml")
|
||||||
utils.DeleteFile(dir + "/statping.db")
|
utils.DeleteFile(dir + "/statping.db")
|
||||||
|
|
|
@ -205,5 +205,13 @@ func (f *Failure) ParseError() string {
|
||||||
if err {
|
if err {
|
||||||
return fmt.Sprintf("Domain is offline or not found")
|
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
|
return f.Issue
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1342,14 +1342,6 @@ More info on: https://github.com/hunterlong/statping
|
||||||
|
|
||||||
## Usage
|
## 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
|
#### func ExecuteResponse
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
@ -1601,7 +1593,7 @@ and sass installed on your local system.
|
||||||
More info on: https://github.com/hunterlong/statping
|
More info on: https://github.com/hunterlong/statping
|
||||||
|
|
||||||
Code generated by go generate; DO NOT EDIT. This file was generated by robots at
|
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.
|
This contains the most recently Markdown source for the Statping Wiki.
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,6 @@ package handlers
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/hunterlong/statping/core"
|
"github.com/hunterlong/statping/core"
|
||||||
"github.com/hunterlong/statping/types"
|
|
||||||
"github.com/hunterlong/statping/utils"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -39,85 +37,3 @@ func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
json.NewEncoder(w).Encode(health)
|
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
|
// API Generic Routes
|
||||||
r.Handle("/metrics", http.HandlerFunc(prometheusHandler))
|
r.Handle("/metrics", http.HandlerFunc(prometheusHandler))
|
||||||
r.Handle("/health", http.HandlerFunc(healthCheckHandler))
|
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.Handle("/.well-known/", http.StripPrefix("/.well-known/", http.FileServer(http.Dir(dir+"/.well-known"))))
|
||||||
|
|
||||||
r.NotFoundHandler = http.HandlerFunc(error404Handler)
|
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() {
|
$('input[type=checkbox]').on('change', function() {
|
||||||
var element = $(this).attr('id');
|
var element = $(this).attr('id');
|
||||||
$("#"+element+"-value").val(this.checked ? "true" : "false")
|
$("#"+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.
|
// SaveAsset will save an asset to the '/assets/' folder.
|
||||||
func SaveAsset(data []byte, folder, file string) error {
|
func SaveAsset(data []byte, folder, file string) error {
|
||||||
utils.Log(1, fmt.Sprintf("Saving %v", folder+"/assets/"+file))
|
location := folder + "/assets/" + file
|
||||||
err := ioutil.WriteFile(folder+"/assets/"+file, data, 0744)
|
utils.Log(1, fmt.Sprintf("Saving %v", location))
|
||||||
|
err := utils.SaveFile(location, data)
|
||||||
if err != nil {
|
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 err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -168,16 +169,14 @@ func CopyAllToPublic(box *rice.Box, folder string) error {
|
||||||
}
|
}
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
folder := fmt.Sprintf("%v/assets/%v/%v", utils.Directory, folder, info.Name())
|
folder := fmt.Sprintf("%v/assets/%v/%v", utils.Directory, folder, info.Name())
|
||||||
MakePublicFolder(folder)
|
return MakePublicFolder(folder)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
file, err := box.Bytes(path)
|
file, err := box.Bytes(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
filePath := fmt.Sprintf("%v%v", folder, path)
|
filePath := fmt.Sprintf("%v/%v", folder, path)
|
||||||
SaveAsset(file, utils.Directory, filePath)
|
return SaveAsset(file, utils.Directory, filePath)
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Code generated by go generate; DO NOT EDIT.
|
// Code generated by go generate; DO NOT EDIT.
|
||||||
// This file was generated by robots at
|
// 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.
|
// This contains the most recently Markdown source for the Statping Wiki.
|
||||||
package source
|
package source
|
||||||
|
|
|
@ -41,7 +41,12 @@ func init() {
|
||||||
if os.Getenv("STATPING_DIR") != "" {
|
if os.Getenv("STATPING_DIR") != "" {
|
||||||
Directory = os.Getenv("STATPING_DIR")
|
Directory = os.Getenv("STATPING_DIR")
|
||||||
} else {
|
} 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:
|
case string:
|
||||||
val, _ := strconv.Atoi(v)
|
val, _ := strconv.Atoi(v)
|
||||||
return int64(val)
|
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:
|
default:
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -59,7 +81,7 @@ func ToInt(s interface{}) int64 {
|
||||||
// ToString converts a int to a string
|
// ToString converts a int to a string
|
||||||
func ToString(s interface{}) string {
|
func ToString(s interface{}) string {
|
||||||
switch v := s.(type) {
|
switch v := s.(type) {
|
||||||
case int, int32, int64:
|
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
|
||||||
return fmt.Sprintf("%v", v)
|
return fmt.Sprintf("%v", v)
|
||||||
case float32, float64:
|
case float32, float64:
|
||||||
return fmt.Sprintf("%f", v)
|
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 Timestamp time.Time
|
||||||
type Timestamper interface {
|
type Timestamper interface {
|
||||||
Ago() string
|
Ago() string
|
||||||
|
|
|
@ -39,26 +39,12 @@ func TestDir(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommand(t *testing.T) {
|
func TestCommand(t *testing.T) {
|
||||||
t.SkipNow()
|
|
||||||
in, out, err := Command("pwd")
|
in, out, err := Command("pwd")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Contains(t, in, "statup")
|
assert.Contains(t, in, "statping")
|
||||||
assert.Empty(t, out)
|
assert.Empty(t, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDurationReadable(t *testing.T) {
|
|
||||||
dur, _ := time.ParseDuration("1505s")
|
|
||||||
readable := DurationReadable(dur)
|
|
||||||
assert.Equal(t, "25 minutes", readable)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleDurationReadable() {
|
|
||||||
dur, _ := time.ParseDuration("25m")
|
|
||||||
readable := DurationReadable(dur)
|
|
||||||
fmt.Print(readable)
|
|
||||||
// Output: 25 minutes
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLog(t *testing.T) {
|
func TestLog(t *testing.T) {
|
||||||
assert.Nil(t, Log(0, errors.New("this is a 0 level error")))
|
assert.Nil(t, Log(0, errors.New("this is a 0 level error")))
|
||||||
assert.Nil(t, Log(1, errors.New("this is a 1 level error")))
|
assert.Nil(t, Log(1, errors.New("this is a 1 level error")))
|
||||||
|
@ -68,31 +54,21 @@ func TestLog(t *testing.T) {
|
||||||
assert.Nil(t, Log(5, errors.New("this is a 5 level error")))
|
assert.Nil(t, Log(5, errors.New("this is a 5 level error")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFormatDuration(t *testing.T) {
|
func TestToInt(t *testing.T) {
|
||||||
dur, _ := time.ParseDuration("158s")
|
assert.Equal(t, int64(55), ToInt("55"))
|
||||||
formatted := FormatDuration(dur)
|
assert.Equal(t, int64(55), ToInt(55))
|
||||||
assert.Equal(t, "3 minutes", formatted)
|
assert.Equal(t, int64(55), ToInt(55.0))
|
||||||
dur, _ = time.ParseDuration("-65s")
|
assert.Equal(t, int64(55), ToInt([]byte("55")))
|
||||||
formatted = FormatDuration(dur)
|
|
||||||
assert.Equal(t, "1 minute", formatted)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDeleteFile(t *testing.T) {
|
|
||||||
assert.Nil(t, DeleteFile(Directory+"/logs/statup.log"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFailedDeleteFile(t *testing.T) {
|
|
||||||
assert.Error(t, DeleteFile(Directory+"/missingfilehere.txt"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLogHTTP(t *testing.T) {
|
|
||||||
req, err := http.NewRequest("GET", "/", nil)
|
|
||||||
assert.Nil(t, err)
|
|
||||||
assert.NotEmpty(t, Http(req))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestToString(t *testing.T) {
|
func TestToString(t *testing.T) {
|
||||||
assert.Equal(t, "1", ToString(1))
|
assert.Equal(t, "55", ToString(55))
|
||||||
|
assert.Equal(t, "55.000000", ToString(55.0))
|
||||||
|
assert.Equal(t, "55", ToString([]byte("55")))
|
||||||
|
dir, _ := time.ParseDuration("55s")
|
||||||
|
assert.Equal(t, "55s", ToString(dir))
|
||||||
|
assert.Equal(t, "true", ToString(true))
|
||||||
|
assert.Equal(t, time.Now().Format("Monday January _2, 2006 at 03:04PM"), ToString(time.Now()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleToString() {
|
func ExampleToString() {
|
||||||
|
@ -101,6 +77,46 @@ func ExampleToString() {
|
||||||
// Output: 42
|
// Output: 42
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSaveFile(t *testing.T) {
|
||||||
|
assert.Nil(t, SaveFile(Directory+"/test.txt", []byte("testing saving a file")))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFileExists(t *testing.T) {
|
||||||
|
assert.True(t, FileExists(Directory+"/test.txt"))
|
||||||
|
assert.False(t, FileExists(Directory+"fake.txt"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDeleteFile(t *testing.T) {
|
||||||
|
assert.Nil(t, DeleteFile(Directory+"/test.txt"))
|
||||||
|
assert.Error(t, DeleteFile(Directory+"/missingfilehere.txt"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFormatDuration(t *testing.T) {
|
||||||
|
dur, _ := time.ParseDuration("158s")
|
||||||
|
assert.Equal(t, "3 minutes", FormatDuration(dur))
|
||||||
|
dur, _ = time.ParseDuration("-65s")
|
||||||
|
assert.Equal(t, "1 minute", FormatDuration(dur))
|
||||||
|
dur, _ = time.ParseDuration("3s")
|
||||||
|
assert.Equal(t, "3 seconds", FormatDuration(dur))
|
||||||
|
dur, _ = time.ParseDuration("48h")
|
||||||
|
assert.Equal(t, "2 days", FormatDuration(dur))
|
||||||
|
dur, _ = time.ParseDuration("12h")
|
||||||
|
assert.Equal(t, "12 hours", FormatDuration(dur))
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleDurationReadable() {
|
||||||
|
dur, _ := time.ParseDuration("25m")
|
||||||
|
readable := DurationReadable(dur)
|
||||||
|
fmt.Print(readable)
|
||||||
|
// Output: 25 minutes
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLogHTTP(t *testing.T) {
|
||||||
|
req, err := http.NewRequest("GET", "/", nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.NotEmpty(t, Http(req))
|
||||||
|
}
|
||||||
|
|
||||||
func TestStringInt(t *testing.T) {
|
func TestStringInt(t *testing.T) {
|
||||||
assert.Equal(t, "1", ToString("1"))
|
assert.Equal(t, "1", ToString("1"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.80.46
|
0.80.47
|
||||||
|
|
Loading…
Reference in New Issue