mirror of https://github.com/statping/statping
tests
parent
555103f901
commit
7fa80523b2
|
@ -156,12 +156,37 @@ func TestMainApiRoutes(t *testing.T) {
|
|||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Update Core",
|
||||
URL: "/api/core",
|
||||
Method: "POST",
|
||||
ExpectedStatus: 200,
|
||||
Body: `{
|
||||
"name": "Updated Core"
|
||||
}`,
|
||||
AfterTest: func(t *testing.T) error {
|
||||
assert.Equal(t, "Updated Core", core.App.Name)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "404 Error Page",
|
||||
URL: "/api/missing_404_page",
|
||||
Method: "GET",
|
||||
ExpectedStatus: 404,
|
||||
}}
|
||||
},
|
||||
//{
|
||||
// Name: "Prometheus Export Metrics",
|
||||
// URL: "/metrics",
|
||||
// Method: "GET",
|
||||
// ExpectedStatus: 200,
|
||||
// ExpectedContains: []string{
|
||||
// `Statping Totals`,
|
||||
// `total_failures`,
|
||||
// `Golang Metrics`,
|
||||
// },
|
||||
//}
|
||||
}
|
||||
|
||||
for _, v := range tests {
|
||||
t.Run(v.Name, func(t *testing.T) {
|
||||
|
|
|
@ -99,10 +99,6 @@ func apiThemeSaveHandler(w http.ResponseWriter, r *http.Request) {
|
|||
sendErrorJson(err, w, r)
|
||||
return
|
||||
}
|
||||
if err := source.SaveAsset([]byte(themes.Base), "scss/main.scss"); err != nil {
|
||||
sendErrorJson(err, w, r)
|
||||
return
|
||||
}
|
||||
if err := source.SaveAsset([]byte(themes.Variables), "scss/variables.scss"); err != nil {
|
||||
sendErrorJson(err, w, r)
|
||||
return
|
||||
|
@ -128,6 +124,7 @@ func apiThemeCreateHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
if err := source.CompileSASS(source.DefaultScss...); err != nil {
|
||||
source.CopyToPublic(source.TmplBox, "css", "main.css")
|
||||
source.CopyToPublic(source.TmplBox, "css", "base.css")
|
||||
log.Errorln("Default 'base.css' was inserted because SASS did not work.")
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/statping/statping/source"
|
||||
"github.com/statping/statping/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestThemeRoutes(t *testing.T) {
|
||||
tests := []HTTPTest{
|
||||
{
|
||||
Name: "Create Theme Assets",
|
||||
URL: "/api/theme/create",
|
||||
Method: "GET",
|
||||
ExpectedStatus: 200,
|
||||
ExpectedContains: []string{`"status":"success"`},
|
||||
BeforeTest: SetTestENV,
|
||||
AfterTest: func(t *testing.T) error {
|
||||
assert.True(t, source.UsingAssets(utils.Directory))
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Get Theme",
|
||||
URL: "/api/theme",
|
||||
Method: "GET",
|
||||
ExpectedStatus: 200,
|
||||
ExpectedContains: []string{
|
||||
`"base":"@import 'variables';`,
|
||||
`"mobile":"@import 'variables'`,
|
||||
`"variables":"/*`,
|
||||
},
|
||||
BeforeTest: SetTestENV,
|
||||
},
|
||||
{
|
||||
Name: "Save Theme",
|
||||
URL: "/api/theme",
|
||||
Method: "POST",
|
||||
Body: `{
|
||||
"base": ".base { }",
|
||||
"variables": "$variable: #bababa",
|
||||
"mobile": ".mobile { }"
|
||||
}`,
|
||||
ExpectedStatus: 200,
|
||||
BeforeTest: SetTestENV,
|
||||
},
|
||||
{
|
||||
Name: "Delete Theme",
|
||||
URL: "/api/theme",
|
||||
Method: "DELETE",
|
||||
ExpectedStatus: 200,
|
||||
BeforeTest: SetTestENV,
|
||||
AfterTest: func(t *testing.T) error {
|
||||
assert.False(t, source.UsingAssets(utils.Directory))
|
||||
return nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, v := range tests {
|
||||
t.Run(v.Name, func(t *testing.T) {
|
||||
str, t, err := RunHTTPTest(v, t)
|
||||
t.Logf("Test %s: \n %v\n", v.Name, str)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ func getUser(r *http.Request) (*users.User, int64, error) {
|
|||
func apiUserHandler(w http.ResponseWriter, r *http.Request) {
|
||||
user, _, err := getUser(r)
|
||||
if err != nil {
|
||||
sendErrorJson(err, w, r)
|
||||
sendErrorJson(err, w, r, http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
user.Password = ""
|
||||
|
|
|
@ -39,6 +39,11 @@ func TestApiUsersRoutes(t *testing.T) {
|
|||
URL: "/api/users/1",
|
||||
Method: "GET",
|
||||
ExpectedStatus: 200,
|
||||
}, {
|
||||
Name: "Statping Missing User",
|
||||
URL: "/api/users/9393939393",
|
||||
Method: "GET",
|
||||
ExpectedStatus: 404,
|
||||
}, {
|
||||
Name: "Statping Update User",
|
||||
URL: "/api/users/1",
|
||||
|
@ -71,6 +76,11 @@ func TestApiUsersRoutes(t *testing.T) {
|
|||
ExpectedContains: []string{`incorrect authentication`},
|
||||
ExpectedStatus: 200,
|
||||
HttpHeaders: []string{"Content-Type=application/x-www-form-urlencoded"},
|
||||
}, {
|
||||
Name: "Statping Logout",
|
||||
URL: "/api/logout",
|
||||
Method: "GET",
|
||||
ExpectedStatus: 303,
|
||||
}}
|
||||
|
||||
for _, v := range tests {
|
||||
|
|
Loading…
Reference in New Issue