pull/627/head
hunterlong 4 years ago
parent 128c53e5e1
commit cfdee4659b

@ -14,7 +14,7 @@ var (
)
func init() {
utils.InitCLI()
utils.InitLogs()
}
func TestStatpingDirectory(t *testing.T) {

@ -35,7 +35,7 @@ func init() {
rootCmd.AddCommand(onceCmd)
rootCmd.AddCommand(envCmd)
rootCmd.AddCommand(resetCmd)
utils.InitCLI()
utils.InitLogs()
parseFlags(rootCmd)
}

120
dev/postman.json vendored

@ -126,6 +126,11 @@
"key": "sample_data",
"value": "true",
"type": "text"
},
{
"key": "newletter",
"value": "true",
"type": "text"
}
],
"options": {
@ -259,6 +264,121 @@
}
]
},
{
"name": "Newletter",
"event": [
{
"listen": "test",
"script": {
"id": "7caef526-8b4b-4dbe-a36c-98ce06c77309",
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "email",
"value": "example@gmail.com",
"type": "text"
},
{
"key": "domain",
"value": "http://localhost:8080",
"type": "text"
},
{
"key": "timezone",
"value": "PST",
"type": "text"
}
]
},
"url": {
"raw": "https://news.statping.com/new",
"protocol": "https",
"host": [
"news",
"statping",
"com"
],
"path": [
"new"
]
},
"description": "The API endpoint for users to add their email to the Statping newsletter."
},
"response": [
{
"name": "Newletter",
"originalRequest": {
"method": "POST",
"header": [],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "email",
"value": "example@gmail.com",
"type": "text"
},
{
"key": "domain",
"value": "http://localhost:8080",
"type": "text"
},
{
"key": "timezone",
"value": "PST",
"type": "text"
}
]
},
"url": {
"raw": "https://news.statping.com/new",
"protocol": "https",
"host": [
"news",
"statping",
"com"
],
"path": [
"new"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Length",
"value": "27"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Date",
"value": "Fri, 29 May 2020 22:01:45 GMT"
}
],
"cookie": [],
"body": "{\n \"data\": {\n \"id\": \"Q21FaAQvH\"\n }\n}"
}
]
},
{
"name": "Logs",
"event": [

@ -34,6 +34,8 @@ var testCheckinHits = []*CheckinHit{{
var testApiKey string
func TestInit(t *testing.T) {
err := utils.InitLogs()
require.Nil(t, err)
db, err := database.OpenTester()
require.Nil(t, err)
db.AutoMigrate(&Checkin{}, &CheckinHit{}, &failures.Failure{})

@ -1,10 +1,15 @@
package configs
import (
"github.com/statping/statping/utils"
"github.com/stretchr/testify/require"
"testing"
)
func init() {
utils.InitLogs()
}
func TestSQLiteConfig(t *testing.T) {
sqlite := &DbConfig{
DbConn: "sqlite",

@ -4,6 +4,7 @@ import (
"github.com/statping/statping/database"
"github.com/statping/statping/types/null"
"github.com/statping/statping/types/services"
"github.com/statping/statping/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
@ -31,6 +32,8 @@ var s2 = &services.Service{
}
func TestInit(t *testing.T) {
err := utils.InitLogs()
require.Nil(t, err)
db, err := database.OpenTester()
require.Nil(t, err)
db.CreateTable(&Group{}, &services.Service{})

@ -2,6 +2,7 @@ package incidents
import (
"github.com/statping/statping/database"
"github.com/statping/statping/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
@ -26,6 +27,8 @@ var update2 = &IncidentUpdate{
}
func TestInit(t *testing.T) {
err := utils.InitLogs()
require.Nil(t, err)
db, err := database.OpenTester()
require.Nil(t, err)
db.AutoMigrate(&Incident{}, &IncidentUpdate{})

@ -18,6 +18,8 @@ var example = &Message{
}
func TestInit(t *testing.T) {
err := utils.InitLogs()
require.Nil(t, err)
db, err := database.OpenTester()
require.Nil(t, err)
db.CreateTable(&Message{})

@ -93,6 +93,9 @@ func (s *exampleGRPC) GetFeature(ctx context.Context, point *pb.Point) (*pb.Feat
}
func TestStartExampleEndpoints(t *testing.T) {
err := utils.InitLogs()
require.Nil(t, err)
// root CA for Linux: /etc/ssl/certs/ca-certificates.crt
// root CA for MacOSX: /opt/local/share/curl/curl-ca-bundle.crt

@ -3,6 +3,7 @@ package users
import (
"github.com/statping/statping/database"
"github.com/statping/statping/types/null"
"github.com/statping/statping/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
@ -16,6 +17,8 @@ var example = &User{
}
func TestInit(t *testing.T) {
err := utils.InitLogs()
require.Nil(t, err)
db, err := database.OpenTester()
require.Nil(t, err)
db.CreateTable(&User{})

@ -12,7 +12,7 @@ var (
configLog = Log.WithField("type", "configs")
)
func InitCLI() {
func initCLI() {
Params = viper.New()
Params.AutomaticEnv()
setDefaults()
@ -43,6 +43,7 @@ func InitCLI() {
}
func setDefaults() {
var err error
defaultDir, err := os.Getwd()
if err != nil {
configLog.Errorln(err)
@ -69,6 +70,9 @@ func setDefaults() {
Params.SetDefault("REMOVE_AFTER", 2160*time.Hour)
Params.SetDefault("CLEANUP_INTERVAL", 1*time.Hour)
Params.SetDefault("LANGUAGE", "en")
Params.SetDefault("LOGS_MAX_COUNT", 5)
Params.SetDefault("LOGS_MAX_AGE", 28)
Params.SetDefault("LOGS_MAX_SIZE", 16)
dbConn := Params.GetString("DB_CONN")
dbInt := Params.GetInt("DB_PORT")

@ -146,6 +146,7 @@ func createLog(dir string) error {
// InitLogs will create the '/logs' directory and creates a file '/logs/statup.log' for application logging
func InitLogs() error {
initCLI()
if Params.GetBool("DISABLE_LOGS") {
return nil
}
@ -154,9 +155,9 @@ func InitLogs() error {
}
ljLogger = &lumberjack.Logger{
Filename: Directory + logFilePath,
MaxSize: 16,
MaxBackups: 5,
MaxAge: 28,
MaxSize: Params.GetInt("LOGS_MAX_SIZE"),
MaxBackups: Params.GetInt("LOGS_MAX_COUNT"),
MaxAge: Params.GetInt("LOGS_MAX_AGE"),
}
mw := io.MultiWriter(os.Stdout, ljLogger)

@ -25,6 +25,9 @@ func TestReplaceValue(t *testing.T) {
func TestInitLogs(t *testing.T) {
assert.Nil(t, InitLogs())
require.NotEmpty(t, Params.GetString("STATPING_DIR"))
require.False(t, Params.GetBool("DISABLE_LOGS"))
Log.Infoln("this is a test")
assert.FileExists(t, Directory+"/logs/statping.log")
}
@ -182,7 +185,7 @@ func TestHttpRequest(t *testing.T) {
}
func TestConfigLoad(t *testing.T) {
InitCLI()
initCLI()
setDefaults()
s := Params.GetString

Loading…
Cancel
Save