mirror of https://github.com/statping/statping
tests
parent
128c53e5e1
commit
cfdee4659b
|
@ -14,7 +14,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.InitCLI()
|
utils.InitLogs()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStatpingDirectory(t *testing.T) {
|
func TestStatpingDirectory(t *testing.T) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ func init() {
|
||||||
rootCmd.AddCommand(onceCmd)
|
rootCmd.AddCommand(onceCmd)
|
||||||
rootCmd.AddCommand(envCmd)
|
rootCmd.AddCommand(envCmd)
|
||||||
rootCmd.AddCommand(resetCmd)
|
rootCmd.AddCommand(resetCmd)
|
||||||
utils.InitCLI()
|
utils.InitLogs()
|
||||||
parseFlags(rootCmd)
|
parseFlags(rootCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,11 @@
|
||||||
"key": "sample_data",
|
"key": "sample_data",
|
||||||
"value": "true",
|
"value": "true",
|
||||||
"type": "text"
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "newletter",
|
||||||
|
"value": "true",
|
||||||
|
"type": "text"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"options": {
|
"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",
|
"name": "Logs",
|
||||||
"event": [
|
"event": [
|
||||||
|
|
|
@ -34,6 +34,8 @@ var testCheckinHits = []*CheckinHit{{
|
||||||
var testApiKey string
|
var testApiKey string
|
||||||
|
|
||||||
func TestInit(t *testing.T) {
|
func TestInit(t *testing.T) {
|
||||||
|
err := utils.InitLogs()
|
||||||
|
require.Nil(t, err)
|
||||||
db, err := database.OpenTester()
|
db, err := database.OpenTester()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
db.AutoMigrate(&Checkin{}, &CheckinHit{}, &failures.Failure{})
|
db.AutoMigrate(&Checkin{}, &CheckinHit{}, &failures.Failure{})
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
package configs
|
package configs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/statping/statping/utils"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
utils.InitLogs()
|
||||||
|
}
|
||||||
|
|
||||||
func TestSQLiteConfig(t *testing.T) {
|
func TestSQLiteConfig(t *testing.T) {
|
||||||
sqlite := &DbConfig{
|
sqlite := &DbConfig{
|
||||||
DbConn: "sqlite",
|
DbConn: "sqlite",
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"github.com/statping/statping/database"
|
"github.com/statping/statping/database"
|
||||||
"github.com/statping/statping/types/null"
|
"github.com/statping/statping/types/null"
|
||||||
"github.com/statping/statping/types/services"
|
"github.com/statping/statping/types/services"
|
||||||
|
"github.com/statping/statping/utils"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -31,6 +32,8 @@ var s2 = &services.Service{
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInit(t *testing.T) {
|
func TestInit(t *testing.T) {
|
||||||
|
err := utils.InitLogs()
|
||||||
|
require.Nil(t, err)
|
||||||
db, err := database.OpenTester()
|
db, err := database.OpenTester()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
db.CreateTable(&Group{}, &services.Service{})
|
db.CreateTable(&Group{}, &services.Service{})
|
||||||
|
|
|
@ -2,6 +2,7 @@ package incidents
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/statping/statping/database"
|
"github.com/statping/statping/database"
|
||||||
|
"github.com/statping/statping/utils"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -26,6 +27,8 @@ var update2 = &IncidentUpdate{
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInit(t *testing.T) {
|
func TestInit(t *testing.T) {
|
||||||
|
err := utils.InitLogs()
|
||||||
|
require.Nil(t, err)
|
||||||
db, err := database.OpenTester()
|
db, err := database.OpenTester()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
db.AutoMigrate(&Incident{}, &IncidentUpdate{})
|
db.AutoMigrate(&Incident{}, &IncidentUpdate{})
|
||||||
|
|
|
@ -18,6 +18,8 @@ var example = &Message{
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInit(t *testing.T) {
|
func TestInit(t *testing.T) {
|
||||||
|
err := utils.InitLogs()
|
||||||
|
require.Nil(t, err)
|
||||||
db, err := database.OpenTester()
|
db, err := database.OpenTester()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
db.CreateTable(&Message{})
|
db.CreateTable(&Message{})
|
||||||
|
|
|
@ -93,6 +93,9 @@ func (s *exampleGRPC) GetFeature(ctx context.Context, point *pb.Point) (*pb.Feat
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStartExampleEndpoints(t *testing.T) {
|
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 Linux: /etc/ssl/certs/ca-certificates.crt
|
||||||
// root CA for MacOSX: /opt/local/share/curl/curl-ca-bundle.crt
|
// root CA for MacOSX: /opt/local/share/curl/curl-ca-bundle.crt
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package users
|
||||||
import (
|
import (
|
||||||
"github.com/statping/statping/database"
|
"github.com/statping/statping/database"
|
||||||
"github.com/statping/statping/types/null"
|
"github.com/statping/statping/types/null"
|
||||||
|
"github.com/statping/statping/utils"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -16,6 +17,8 @@ var example = &User{
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInit(t *testing.T) {
|
func TestInit(t *testing.T) {
|
||||||
|
err := utils.InitLogs()
|
||||||
|
require.Nil(t, err)
|
||||||
db, err := database.OpenTester()
|
db, err := database.OpenTester()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
db.CreateTable(&User{})
|
db.CreateTable(&User{})
|
||||||
|
|
|
@ -12,7 +12,7 @@ var (
|
||||||
configLog = Log.WithField("type", "configs")
|
configLog = Log.WithField("type", "configs")
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitCLI() {
|
func initCLI() {
|
||||||
Params = viper.New()
|
Params = viper.New()
|
||||||
Params.AutomaticEnv()
|
Params.AutomaticEnv()
|
||||||
setDefaults()
|
setDefaults()
|
||||||
|
@ -43,6 +43,7 @@ func InitCLI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setDefaults() {
|
func setDefaults() {
|
||||||
|
var err error
|
||||||
defaultDir, err := os.Getwd()
|
defaultDir, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
configLog.Errorln(err)
|
configLog.Errorln(err)
|
||||||
|
@ -69,6 +70,9 @@ func setDefaults() {
|
||||||
Params.SetDefault("REMOVE_AFTER", 2160*time.Hour)
|
Params.SetDefault("REMOVE_AFTER", 2160*time.Hour)
|
||||||
Params.SetDefault("CLEANUP_INTERVAL", 1*time.Hour)
|
Params.SetDefault("CLEANUP_INTERVAL", 1*time.Hour)
|
||||||
Params.SetDefault("LANGUAGE", "en")
|
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")
|
dbConn := Params.GetString("DB_CONN")
|
||||||
dbInt := Params.GetInt("DB_PORT")
|
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
|
// InitLogs will create the '/logs' directory and creates a file '/logs/statup.log' for application logging
|
||||||
func InitLogs() error {
|
func InitLogs() error {
|
||||||
|
initCLI()
|
||||||
if Params.GetBool("DISABLE_LOGS") {
|
if Params.GetBool("DISABLE_LOGS") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -154,9 +155,9 @@ func InitLogs() error {
|
||||||
}
|
}
|
||||||
ljLogger = &lumberjack.Logger{
|
ljLogger = &lumberjack.Logger{
|
||||||
Filename: Directory + logFilePath,
|
Filename: Directory + logFilePath,
|
||||||
MaxSize: 16,
|
MaxSize: Params.GetInt("LOGS_MAX_SIZE"),
|
||||||
MaxBackups: 5,
|
MaxBackups: Params.GetInt("LOGS_MAX_COUNT"),
|
||||||
MaxAge: 28,
|
MaxAge: Params.GetInt("LOGS_MAX_AGE"),
|
||||||
}
|
}
|
||||||
|
|
||||||
mw := io.MultiWriter(os.Stdout, ljLogger)
|
mw := io.MultiWriter(os.Stdout, ljLogger)
|
||||||
|
|
|
@ -25,6 +25,9 @@ func TestReplaceValue(t *testing.T) {
|
||||||
|
|
||||||
func TestInitLogs(t *testing.T) {
|
func TestInitLogs(t *testing.T) {
|
||||||
assert.Nil(t, InitLogs())
|
assert.Nil(t, InitLogs())
|
||||||
|
require.NotEmpty(t, Params.GetString("STATPING_DIR"))
|
||||||
|
require.False(t, Params.GetBool("DISABLE_LOGS"))
|
||||||
|
|
||||||
Log.Infoln("this is a test")
|
Log.Infoln("this is a test")
|
||||||
assert.FileExists(t, Directory+"/logs/statping.log")
|
assert.FileExists(t, Directory+"/logs/statping.log")
|
||||||
}
|
}
|
||||||
|
@ -182,7 +185,7 @@ func TestHttpRequest(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConfigLoad(t *testing.T) {
|
func TestConfigLoad(t *testing.T) {
|
||||||
InitCLI()
|
initCLI()
|
||||||
setDefaults()
|
setDefaults()
|
||||||
|
|
||||||
s := Params.GetString
|
s := Params.GetString
|
||||||
|
|
Loading…
Reference in New Issue