statping/handlers/checkins_test.go

49 lines
1.1 KiB
Go
Raw Normal View History

2020-03-04 10:29:00 +00:00
package handlers
import (
2020-03-08 18:13:27 +00:00
"github.com/stretchr/testify/assert"
2020-03-04 10:29:00 +00:00
"testing"
)
func TestApiCheckinRoutes(t *testing.T) {
tests := []HTTPTest{
{
Name: "Statping Checkins",
URL: "/api/checkins",
Method: "GET",
ExpectedStatus: 200,
2020-03-08 01:23:41 +00:00
BeforeTest: SetTestENV,
2020-03-08 18:13:27 +00:00
SecureRoute: true,
2020-03-04 10:29:00 +00:00
}, {
Name: "Statping Create Checkin",
URL: "/api/checkin",
Method: "POST",
Body: `{
2020-03-08 01:23:41 +00:00
"service_id": 2,
"name": "Server Checkin",
"interval": 900,
"grace": 60
}`,
2020-03-04 10:29:00 +00:00
ExpectedStatus: 200,
ExpectedContains: []string{`"status":"success","type":"checkin","method":"create"`},
2020-03-08 01:23:41 +00:00
BeforeTest: SetTestENV,
2020-03-08 18:13:27 +00:00
SecureRoute: true,
2020-03-04 10:29:00 +00:00
},
{
2020-03-08 18:13:27 +00:00
Name: "Statping Checkins Unauthorized",
2020-03-04 10:29:00 +00:00
URL: "/api/checkins",
Method: "GET",
2020-03-08 18:13:27 +00:00
ExpectedStatus: 401,
AfterTest: SetTestENV,
SecureRoute: true,
2020-03-04 10:29:00 +00:00
}}
for _, v := range tests {
t.Run(v.Name, func(t *testing.T) {
2020-03-08 01:23:41 +00:00
str, t, err := RunHTTPTest(v, t)
t.Logf("Test %s: \n %v\n", v.Name, str)
2020-03-08 18:13:27 +00:00
assert.Nil(t, err)
2020-03-04 10:29:00 +00:00
})
}
}