diff --git a/.travis.yml b/.travis.yml
index 2a2f92d2..5638e60d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,7 +18,7 @@ services:
env:
global:
- - VERSION=0.28.6
+ - VERSION=0.28.7
- DB_HOST=localhost
- DB_USER=travis
- DB_PASS=
diff --git a/Dockerfile b/Dockerfile
index 585a5780..57edc01c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,6 +1,6 @@
FROM alpine:latest
-ENV VERSION=v0.28.6
+ENV VERSION=v0.28.7
RUN apk --no-cache add libstdc++ ca-certificates
RUN wget -q https://github.com/hunterlong/statup/releases/download/$VERSION/statup-linux-alpine.tar.gz && \
diff --git a/core/database.go b/core/database.go
index 745240e0..0332b797 100644
--- a/core/database.go
+++ b/core/database.go
@@ -162,7 +162,7 @@ func CreateDatabase() {
sql := "postgres_up.sql"
if dbServer == "mysql" {
sql = "mysql_up.sql"
- } else if dbServer == "sqlite3" {
+ } else if dbServer == "sqlite" {
sql = "sqlite_up.sql"
}
up, _ := SqlBox.String(sql)
diff --git a/core/services.go b/core/services.go
index a30c3892..8b8a374f 100644
--- a/core/services.go
+++ b/core/services.go
@@ -128,7 +128,15 @@ func (s *Service) GraphData() string {
var d []DateScan
increment := "minute"
since := time.Now().Add(time.Hour*-12 + time.Minute*0 + time.Second*0)
+
+ // this function needs some work, asap
sql := fmt.Sprintf("SELECT date_trunc('%v', created_at), AVG(latency)*1000 AS value FROM hits WHERE service=%v AND created_at > '%v' GROUP BY 1 ORDER BY date_trunc ASC;", increment, s.Id, since.Format(time.RFC3339))
+ if dbServer == "mysql" {
+ sql = fmt.Sprintf("SELECT created_at, AVG(latency)*1000 AS VALUE FROM hits WHERE service=%v GROUP BY 1 ORDER BY created_at ASC;", s.Id)
+ } else if dbServer == "sqlite" {
+ sql = fmt.Sprintf("SELECT created_at, AVG(latency)*1000 AS VALUE FROM hits WHERE service=%v GROUP BY 1 ORDER BY created_at ASC;", s.Id)
+ }
+
dated, err := DbSession.Query(db.Raw(sql))
if err != nil {
utils.Log(2, err)
diff --git a/core/setup.go b/core/setup.go
index 7ae5a5d8..f81bde73 100644
--- a/core/setup.go
+++ b/core/setup.go
@@ -1,6 +1,7 @@
package core
import (
+ "fmt"
"github.com/hunterlong/statup/types"
"github.com/hunterlong/statup/utils"
"os"
@@ -77,17 +78,32 @@ func LoadSampleData() error {
Method: "POST",
PostData: `{ "title": "statup", "body": "bar", "userId": 19999 }`,
}
- s1.Create()
- s2.Create()
- s3.Create()
- s4.Create()
+ id, err := s1.Create()
+ if err != nil {
+ utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
+ }
+ id, err = s2.Create()
+ if err != nil {
+ utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
+ }
+ id, err = s3.Create()
+ if err != nil {
+ utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
+ }
+ id, err = s4.Create()
+ if err != nil {
+ utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
+ }
checkin := &Checkin{
Service: s2.Id,
Interval: 30,
Api: utils.NewSHA1Hash(18),
}
- checkin.Create()
+ id, err = checkin.Create()
+ if err != nil {
+ utils.Log(3, fmt.Sprintf("Error creating Checkin %v: %v", id, err))
+ }
//for i := 0; i < 3; i++ {
// s1.Check()
diff --git a/handlers/misc.go b/handlers/misc.go
index 99ead482..03ec423c 100644
--- a/handlers/misc.go
+++ b/handlers/misc.go
@@ -7,4 +7,4 @@ import (
func Error404Handler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
ExecuteResponse(w, r, "error_404.html", nil)
-}
\ No newline at end of file
+}
diff --git a/handlers/settings.go b/handlers/settings.go
index daec9cd2..633f8aae 100644
--- a/handlers/settings.go
+++ b/handlers/settings.go
@@ -1,7 +1,6 @@
package handlers
import (
- "fmt"
"github.com/hunterlong/statup/core"
"github.com/hunterlong/statup/notifications"
"github.com/hunterlong/statup/types"
@@ -25,7 +24,6 @@ func PluginsHandler(w http.ResponseWriter, r *http.Request) {
//}
//CoreApp.PluginFields = pluginFields
- fmt.Println(core.CoreApp.Communications)
ExecuteResponse(w, r, "settings.html", core.CoreApp)
}
diff --git a/main_test.go b/main_test.go
index 569ef619..0c09e7f1 100644
--- a/main_test.go
+++ b/main_test.go
@@ -20,333 +20,120 @@ var (
testSession *sessions.Session
)
-func init() {
- route = handlers.Router()
-}
-
-func TestInit(t *testing.T) {
+func RunInit(t *testing.T) {
RenderBoxes()
os.Remove("./statup.db")
- handlers.Router()
+ os.Remove("./config.yml")
+ route = handlers.Router()
LoadDotEnvs()
-
}
-func TestMySQLMakeConfig(t *testing.T) {
- config := &core.DbConfig{
- "mysql",
- os.Getenv("DB_HOST"),
- os.Getenv("DB_USER"),
- os.Getenv("DB_PASS"),
- os.Getenv("DB_DATABASE"),
- 3306,
- "Testing MYSQL",
- "This is a test of Statup.io!",
- "",
- "admin",
- "admin",
- "",
- nil,
+var forceSequential chan bool = make(chan bool, 1)
+
+type databaseTest struct {
+ in string
+ out string
+}
+
+var dbTests []databaseTest
+
+func TestRunAll(t *testing.T) {
+
+ databases := []string{"mysql", "sqlite", "postgres"}
+
+ for _, dbt := range databases {
+
+ forceSequential <- true
+
+ t.Run(dbt+" init", func(t *testing.T) {
+ RunInit(t)
+ })
+ t.Run(dbt+" load database config", func(t *testing.T) {
+ RunMySQLMakeConfig(t, dbt)
+ })
+ t.Run(dbt+" Sample Data", func(t *testing.T) {
+ RunInsertMysqlSample(t)
+ })
+ t.Run(dbt+" Select Core", func(t *testing.T) {
+ RunSelectCoreMYQL(t, dbt)
+ })
+ t.Run(dbt+" Select Services", func(t *testing.T) {
+ RunSelectAllMysqlServices(t)
+ })
+ t.Run(dbt+" Select Comms", func(t *testing.T) {
+ RunSelectAllMysqlCommunications(t)
+ })
+ t.Run(dbt+" Create User", func(t *testing.T) {
+ RunUser_Create(t)
+ })
+ t.Run(dbt+" Select Services", func(t *testing.T) {
+ RunSelectAllServices(t)
+ })
+ t.Run(dbt+" Select One Service", func(t *testing.T) {
+ RunOneService_Check(t)
+ })
+ t.Run(dbt+" Create Service", func(t *testing.T) {
+ RunService_Create(t)
+ })
+ t.Run(dbt+" Create Hits", func(t *testing.T) {
+ RunCreateService_Hits(t)
+ })
+ t.Run(dbt+" Avg Time", func(t *testing.T) {
+ RunService_AvgTime(t)
+ })
+ t.Run(dbt+" Online 24h", func(t *testing.T) {
+ RunService_Online24(t)
+ })
+ t.Run(dbt+" Chart Data", func(t *testing.T) {
+ RunService_GraphData(t)
+ })
+ t.Run(dbt+" Create Service", func(t *testing.T) {
+ RunBadService_Create(t)
+ })
+ t.Run(dbt+" Check Service", func(t *testing.T) {
+ RunBadService_Check(t)
+ })
+ t.Run(dbt+" Select Hits", func(t *testing.T) {
+ RunService_Hits(t)
+ })
+ t.Run(dbt+" Select Limited Hits", func(t *testing.T) {
+ RunService_LimitedHits(t)
+ })
+ t.Run(dbt+" HTTP /", func(t *testing.T) {
+ RunIndexHandler(t)
+ })
+ t.Run(dbt+" HTTP /service/1", func(t *testing.T) {
+ RunServiceHandler(t)
+ })
+ t.Run(dbt+" HTTP /metrics", func(t *testing.T) {
+ RunPrometheusHandler(t)
+ })
+ t.Run(dbt+" HTTP /metrics", func(t *testing.T) {
+ RunFailingPrometheusHandler(t)
+ })
+ t.Run(dbt+" HTTP /login", func(t *testing.T) {
+ RunLoginHandler(t)
+ })
+ t.Run(dbt+" HTTP /dashboard", func(t *testing.T) {
+ RunDashboardHandler(t)
+ })
+ t.Run(dbt+" HTTP /users", func(t *testing.T) {
+ RunUsersHandler(t)
+ })
+ t.Run(dbt+" HTTP /services", func(t *testing.T) {
+ RunServicesHandler(t)
+ })
+ t.Run(dbt+" HTTP /help", func(t *testing.T) {
+ RunHelpHandler(t)
+ })
+ t.Run(dbt+" HTTP /settings", func(t *testing.T) {
+ RunSettingsHandler(t)
+ })
+
+ <-forceSequential
+
}
- err := config.Save()
- assert.Nil(t, err)
- _, err = core.LoadConfig()
- assert.Nil(t, err)
- assert.Equal(t, "mysql", core.Configs.Connection)
-
- err = core.DbConnection(core.Configs.Connection)
- assert.Nil(t, err)
- core.InsertDefaultComms()
-}
-
-func TestInsertMysqlSample(t *testing.T) {
- err := core.LoadSampleData()
- assert.Nil(t, err)
-}
-
-func TestSelectCoreMYQL(t *testing.T) {
- var err error
- core.CoreApp, err = core.SelectCore()
- assert.Nil(t, err)
- assert.Equal(t, "Testing MYSQL", core.CoreApp.Name)
- assert.Equal(t, VERSION, core.CoreApp.Version)
-}
-
-func TestSqliteMakeConfig(t *testing.T) {
- config := &core.DbConfig{
- "sqlite",
- os.Getenv("DB_HOST"),
- os.Getenv("DB_USER"),
- os.Getenv("DB_PASS"),
- os.Getenv("DB_DATABASE"),
- 5432,
- "Testing SQLITE",
- "This is a test of Statup.io!",
- "",
- "admin",
- "admin",
- "",
- nil,
- }
- err := config.Save()
- assert.Nil(t, err)
-
- _, err = core.LoadConfig()
- assert.Nil(t, err)
- assert.Equal(t, "sqlite", core.Configs.Connection)
-
- err = core.DbConnection(core.Configs.Connection)
- assert.Nil(t, err)
- core.InsertDefaultComms()
-}
-
-func TestInsertSqliteSample(t *testing.T) {
- err := core.LoadSampleData()
- assert.Nil(t, err)
-}
-
-func TestPostgresMakeConfig(t *testing.T) {
- config := &core.DbConfig{
- "postgres",
- os.Getenv("DB_HOST"),
- os.Getenv("DB_USER"),
- os.Getenv("DB_PASS"),
- os.Getenv("DB_DATABASE"),
- 5432,
- "Testing POSTGRES",
- "This is a test of Statup.io!",
- "",
- "admin",
- "admin",
- "",
- nil,
- }
- err := config.Save()
- assert.Nil(t, err)
-
- _, err = core.LoadConfig()
- assert.Nil(t, err)
- assert.Equal(t, "postgres", core.Configs.Connection)
-
- err = core.DbConnection(core.Configs.Connection)
- assert.Nil(t, err)
- core.InsertDefaultComms()
-}
-
-func TestInsertPostgresSample(t *testing.T) {
- err := core.LoadSampleData()
- assert.Nil(t, err)
-}
-
-func TestSelectCorePostgres(t *testing.T) {
- var err error
- core.CoreApp, err = core.SelectCore()
- assert.Nil(t, err)
- assert.Equal(t, "Testing POSTGRES", core.CoreApp.Name)
- assert.Equal(t, VERSION, core.CoreApp.Version)
-}
-
-func TestSelectCore(t *testing.T) {
- var err error
- core.CoreApp, err = core.SelectCore()
- assert.Nil(t, err)
- assert.Equal(t, "Testing POSTGRES", core.CoreApp.Name)
- assert.Equal(t, VERSION, core.CoreApp.Version)
-}
-
-func TestUser_Create(t *testing.T) {
- user := &core.User{
- Username: "admin",
- Password: "admin",
- Email: "info@testuser.com",
- }
- id, err := user.Create()
- assert.Nil(t, err)
- assert.NotZero(t, id)
-}
-
-func TestSelectAllServices(t *testing.T) {
- var err error
- services, err := core.SelectAllServices()
- assert.Nil(t, err)
- assert.Equal(t, 4, len(services))
-}
-
-func TestOneService_Check(t *testing.T) {
- service := core.SelectService(1)
- assert.NotNil(t, service)
- t.Log(service)
- assert.Equal(t, "Google", service.Name)
-}
-
-func TestService_Create(t *testing.T) {
- service := &core.Service{
- Name: "test service",
- Domain: "https://google.com",
- ExpectedStatus: 200,
- Interval: 1,
- Port: 0,
- Type: "https",
- Method: "GET",
- }
- id, err := service.Create()
- assert.Nil(t, err)
- assert.Equal(t, int64(5), id)
-}
-
-func TestService_Check(t *testing.T) {
- service := core.SelectService(1)
- assert.NotNil(t, service)
- assert.Equal(t, "Google", service.Name)
- out := service.Check()
- assert.Equal(t, true, out.Online)
-}
-
-func TestService_AvgTime(t *testing.T) {
- service := core.SelectService(1)
- assert.NotNil(t, service)
- avg := service.AvgUptime()
- assert.Equal(t, "100", avg)
-}
-
-func TestService_Online24(t *testing.T) {
- service := core.SelectService(1)
- assert.NotNil(t, service)
- online := service.Online24()
- assert.Equal(t, float32(100), online)
-}
-
-func TestService_GraphData(t *testing.T) {
- service := core.SelectService(1)
- assert.NotNil(t, service)
- data := service.GraphData()
- assert.NotEmpty(t, data)
-}
-
-func TestBadService_Create(t *testing.T) {
- service := &core.Service{
- Name: "Bad Service",
- Domain: "https://9839f83h72gey2g29278hd2od2d.com",
- ExpectedStatus: 200,
- Interval: 10,
- Port: 0,
- Type: "http",
- Method: "GET",
- }
- id, err := service.Create()
- assert.Nil(t, err)
- assert.Equal(t, int64(6), id)
-}
-
-func TestBadService_Check(t *testing.T) {
- service := core.SelectService(4)
- assert.NotNil(t, service)
- assert.Equal(t, "JSON API Tester", service.Name)
-}
-
-func TestService_Hits(t *testing.T) {
- service := core.SelectService(1)
- assert.NotNil(t, service)
- hits, err := service.Hits()
- assert.Nil(t, err)
- assert.NotZero(t, len(hits))
-}
-
-func TestService_LimitedHits(t *testing.T) {
- service := core.SelectService(1)
- assert.NotNil(t, service)
- hits, err := service.LimitedHits()
- assert.Nil(t, err)
- assert.NotZero(t, len(hits))
-}
-
-func TestIndexHandler(t *testing.T) {
- req, err := http.NewRequest("GET", "/", nil)
- assert.Nil(t, err)
- rr := httptest.NewRecorder()
- route.ServeHTTP(rr, req)
- assert.True(t, strings.Contains(rr.Body.String(), "This is a test of Statup.io!"))
-}
-
-func TestServiceHandler(t *testing.T) {
- req, err := http.NewRequest("GET", "/service/1", nil)
- assert.Nil(t, err)
- rr := httptest.NewRecorder()
- route.ServeHTTP(rr, req)
- assert.True(t, strings.Contains(rr.Body.String(), "
Statup | Services"))
-}
-
-func TestPrometheusHandler(t *testing.T) {
- req, err := http.NewRequest("GET", "/metrics", nil)
- req.Header.Set("Authorization", core.CoreApp.ApiSecret)
- assert.Nil(t, err)
- rr := httptest.NewRecorder()
- route.ServeHTTP(rr, req)
- t.Log(rr.Body.String())
- assert.True(t, strings.Contains(rr.Body.String(), "statup_total_services 6"))
-}
-
-func TestFailingPrometheusHandler(t *testing.T) {
- req, err := http.NewRequest("GET", "/metrics", nil)
- assert.Nil(t, err)
- rr := httptest.NewRecorder()
- route.ServeHTTP(rr, req)
- assert.Equal(t, 401, rr.Result().StatusCode)
-}
-
-func TestLoginHandler(t *testing.T) {
- form := url.Values{}
- form.Add("username", "admin")
- form.Add("password", "admin")
- req, err := http.NewRequest("POST", "/dashboard", strings.NewReader(form.Encode()))
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
- assert.Nil(t, err)
- rr := httptest.NewRecorder()
- route.ServeHTTP(rr, req)
- assert.Equal(t, 303, rr.Result().StatusCode)
-}
-
-func TestDashboardHandler(t *testing.T) {
- req, err := http.NewRequest("GET", "/dashboard", nil)
- assert.Nil(t, err)
- rr := httptest.NewRecorder()
- route.ServeHTTP(rr, req)
- assert.True(t, strings.Contains(rr.Body.String(), "Statup | Dashboard"))
-}
-
-func TestUsersHandler(t *testing.T) {
- req, err := http.NewRequest("GET", "/users", nil)
- assert.Nil(t, err)
- rr := httptest.NewRecorder()
- route.ServeHTTP(rr, req)
- assert.True(t, strings.Contains(rr.Body.String(), "Statup | Users"))
-}
-
-func TestServicesHandler(t *testing.T) {
- req, err := http.NewRequest("GET", "/services", nil)
- assert.Nil(t, err)
- rr := httptest.NewRecorder()
- route.ServeHTTP(rr, req)
- assert.True(t, strings.Contains(rr.Body.String(), "Statup | Services"))
-}
-
-func TestHelpHandler(t *testing.T) {
- req, err := http.NewRequest("GET", "/help", nil)
- assert.Nil(t, err)
- rr := httptest.NewRecorder()
- route.ServeHTTP(rr, req)
- assert.True(t, strings.Contains(rr.Body.String(), "Statup | Help"))
-}
-
-func TestSettingsHandler(t *testing.T) {
- req, err := http.NewRequest("GET", "/settings", nil)
- assert.Nil(t, err)
- rr := httptest.NewRecorder()
- route.ServeHTTP(rr, req)
- assert.True(t, strings.Contains(rr.Body.String(), "Statup | Settings"))
- assert.True(t, strings.Contains(rr.Body.String(), "Theme Editor"))
- assert.True(t, strings.Contains(rr.Body.String(), "Email Settings"))
}
func TestVersionCommand(t *testing.T) {
@@ -377,3 +164,274 @@ func TestAssetsCommand(t *testing.T) {
t.Log(c.Stdout())
assert.True(t, c.StdoutContains("Statup v"))
}
+
+func RunMySQLMakeConfig(t *testing.T, db string) {
+
+ port := 5432
+ if db == "mysql" {
+ port = 3306
+ }
+
+ config := &core.DbConfig{
+ db,
+ os.Getenv("DB_HOST"),
+ os.Getenv("DB_USER"),
+ os.Getenv("DB_PASS"),
+ os.Getenv("DB_DATABASE"),
+ port,
+ "Testing " + db,
+ "This is a test of Statup.io!",
+ "",
+ "admin",
+ "admin",
+ "",
+ nil,
+ }
+ err := config.Save()
+ assert.Nil(t, err)
+
+ _, err = core.LoadConfig()
+ assert.Nil(t, err)
+ assert.Equal(t, db, core.Configs.Connection)
+
+ err = core.DbConnection(core.Configs.Connection)
+ assert.Nil(t, err)
+ core.InsertDefaultComms()
+}
+
+func RunInsertMysqlSample(t *testing.T) {
+ err := core.LoadSampleData()
+ assert.Nil(t, err)
+}
+
+func RunSelectCoreMYQL(t *testing.T, db string) {
+ var err error
+ core.CoreApp, err = core.SelectCore()
+ assert.Nil(t, err)
+ assert.Equal(t, "Testing "+db, core.CoreApp.Name)
+ assert.Equal(t, VERSION, core.CoreApp.Version)
+}
+
+func RunSelectAllMysqlServices(t *testing.T) {
+ var err error
+ services, err := core.SelectAllServices()
+ assert.Nil(t, err)
+ assert.Equal(t, 4, len(services))
+}
+
+func RunSelectAllMysqlCommunications(t *testing.T) {
+ var err error
+ comms, err := core.SelectAllCommunications()
+ assert.Nil(t, err)
+ assert.Equal(t, 2, len(comms))
+}
+
+func RunUser_Create(t *testing.T) {
+ user := &core.User{
+ Username: "admin",
+ Password: "admin",
+ Email: "info@testuser.com",
+ }
+ id, err := user.Create()
+ assert.Nil(t, err)
+ assert.NotZero(t, id)
+}
+
+func RunSelectAllServices(t *testing.T) {
+ var err error
+ services, err := core.SelectAllServices()
+ assert.Nil(t, err)
+ assert.Equal(t, 4, len(services))
+}
+
+func RunOneService_Check(t *testing.T) {
+ service := core.SelectService(1)
+ assert.NotNil(t, service)
+ t.Log(service)
+ assert.Equal(t, "Google", service.Name)
+}
+
+func RunService_Create(t *testing.T) {
+ service := &core.Service{
+ Name: "test service",
+ Domain: "https://google.com",
+ ExpectedStatus: 200,
+ Interval: 1,
+ Port: 0,
+ Type: "http",
+ Method: "GET",
+ }
+ id, err := service.Create()
+ assert.Nil(t, err)
+ assert.Equal(t, int64(5), id)
+}
+
+func RunService_AvgTime(t *testing.T) {
+ service := core.SelectService(1)
+ assert.NotNil(t, service)
+ avg := service.AvgUptime()
+ assert.Equal(t, "100", avg)
+}
+
+func RunService_Online24(t *testing.T) {
+ service := core.SelectService(1)
+ assert.NotNil(t, service)
+ online := service.Online24()
+ assert.Equal(t, float32(100), online)
+}
+
+func RunService_GraphData(t *testing.T) {
+ service := core.SelectService(1)
+ assert.NotNil(t, service)
+ data := service.GraphData()
+ assert.NotEmpty(t, data)
+}
+
+func RunBadService_Create(t *testing.T) {
+ service := &core.Service{
+ Name: "Bad Service",
+ Domain: "https://9839f83h72gey2g29278hd2od2d.com",
+ ExpectedStatus: 200,
+ Interval: 10,
+ Port: 0,
+ Type: "http",
+ Method: "GET",
+ }
+ id, err := service.Create()
+ assert.Nil(t, err)
+ assert.Equal(t, int64(6), id)
+}
+
+func RunBadService_Check(t *testing.T) {
+ service := core.SelectService(4)
+ assert.NotNil(t, service)
+ assert.Equal(t, "JSON API Tester", service.Name)
+}
+
+func RunCreateService_Hits(t *testing.T) {
+ services, err := core.SelectAllServices()
+ assert.Nil(t, err)
+ assert.NotNil(t, services)
+ for i := 0; i <= 2; i++ {
+ for _, s := range services {
+ service := s.Check()
+ assert.NotNil(t, service)
+ }
+ }
+}
+
+func RunService_Hits(t *testing.T) {
+ service := core.SelectService(1)
+ assert.NotNil(t, service)
+ hits, err := service.Hits()
+ assert.Nil(t, err)
+ assert.NotZero(t, len(hits))
+}
+
+func RunService_LimitedHits(t *testing.T) {
+ service := core.SelectService(1)
+ assert.NotNil(t, service)
+ hits, err := service.LimitedHits()
+ assert.Nil(t, err)
+ assert.NotZero(t, len(hits))
+}
+
+func RunIndexHandler(t *testing.T) {
+ req, err := http.NewRequest("GET", "/", nil)
+ assert.Nil(t, err)
+ rr := httptest.NewRecorder()
+ route.ServeHTTP(rr, req)
+ assert.True(t, strings.Contains(rr.Body.String(), "This is a test of Statup.io!"))
+ assert.True(t, strings.Contains(rr.Body.String(), "footer"))
+}
+
+func RunServiceHandler(t *testing.T) {
+ req, err := http.NewRequest("GET", "/service/1", nil)
+ assert.Nil(t, err)
+ rr := httptest.NewRecorder()
+ route.ServeHTTP(rr, req)
+ assert.True(t, strings.Contains(rr.Body.String(), "Statup | Google Service"))
+ assert.True(t, strings.Contains(rr.Body.String(), "footer"))
+}
+
+func RunPrometheusHandler(t *testing.T) {
+ req, err := http.NewRequest("GET", "/metrics", nil)
+ req.Header.Set("Authorization", core.CoreApp.ApiSecret)
+ assert.Nil(t, err)
+ rr := httptest.NewRecorder()
+ route.ServeHTTP(rr, req)
+ t.Log(rr.Body.String())
+ assert.True(t, strings.Contains(rr.Body.String(), "statup_total_services 6"))
+}
+
+func RunFailingPrometheusHandler(t *testing.T) {
+ req, err := http.NewRequest("GET", "/metrics", nil)
+ assert.Nil(t, err)
+ rr := httptest.NewRecorder()
+ route.ServeHTTP(rr, req)
+ assert.Equal(t, 401, rr.Result().StatusCode)
+}
+
+func RunLoginHandler(t *testing.T) {
+ form := url.Values{}
+ form.Add("username", "admin")
+ form.Add("password", "admin")
+ req, err := http.NewRequest("POST", "/dashboard", strings.NewReader(form.Encode()))
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ assert.Nil(t, err)
+ rr := httptest.NewRecorder()
+ route.ServeHTTP(rr, req)
+ assert.Equal(t, 303, rr.Result().StatusCode)
+}
+
+func RunDashboardHandler(t *testing.T) {
+ req, err := http.NewRequest("GET", "/dashboard", nil)
+ assert.Nil(t, err)
+ rr := httptest.NewRecorder()
+ route.ServeHTTP(rr, req)
+ assert.True(t, strings.Contains(rr.Body.String(), "Statup | Dashboard"))
+ assert.True(t, strings.Contains(rr.Body.String(), "footer"))
+}
+
+func RunUsersHandler(t *testing.T) {
+ req, err := http.NewRequest("GET", "/users", nil)
+ assert.Nil(t, err)
+ rr := httptest.NewRecorder()
+ route.ServeHTTP(rr, req)
+ assert.True(t, strings.Contains(rr.Body.String(), "Statup | Users"))
+ assert.True(t, strings.Contains(rr.Body.String(), "footer"))
+}
+
+func RunServicesHandler(t *testing.T) {
+ req, err := http.NewRequest("GET", "/services", nil)
+ assert.Nil(t, err)
+ rr := httptest.NewRecorder()
+ route.ServeHTTP(rr, req)
+ assert.True(t, strings.Contains(rr.Body.String(), "Statup | Services"))
+ assert.True(t, strings.Contains(rr.Body.String(), "footer"))
+}
+
+func RunHelpHandler(t *testing.T) {
+ req, err := http.NewRequest("GET", "/help", nil)
+ assert.Nil(t, err)
+ rr := httptest.NewRecorder()
+ route.ServeHTTP(rr, req)
+ assert.True(t, strings.Contains(rr.Body.String(), "Statup | Help"))
+ assert.True(t, strings.Contains(rr.Body.String(), "footer"))
+}
+
+func RunSettingsHandler(t *testing.T) {
+ req, err := http.NewRequest("GET", "/settings", nil)
+ assert.Nil(t, err)
+ rr := httptest.NewRecorder()
+ route.ServeHTTP(rr, req)
+ assert.True(t, strings.Contains(rr.Body.String(), "Statup | Settings"))
+ assert.True(t, strings.Contains(rr.Body.String(), "Theme Editor"))
+ assert.True(t, strings.Contains(rr.Body.String(), "Email Settings"))
+ assert.True(t, strings.Contains(rr.Body.String(), "footer"))
+}
+
+//func RunComplete(t *testing.T) {
+// //os.Remove("./statup.db")
+// os.Remove("./config.yml")
+//}
diff --git a/source/js/setup.js b/source/js/setup.js
index 1e35b068..77792afd 100644
--- a/source/js/setup.js
+++ b/source/js/setup.js
@@ -16,6 +16,12 @@ $('select#database_type').on('change', function(){
$("#db_user").show();
$("#db_database").show();
}
+ if (selected=="mysql") {
+ $("#db_port_in").val('3306');
+ } else if (selected=="postgres") {
+ $("#db_port_in").val('5432');
+ }
+
});
$("#setup_form").submit(function() {
diff --git a/source/sql/down.sql b/source/sql/down.sql
index 824f4e27..44611f72 100644
--- a/source/sql/down.sql
+++ b/source/sql/down.sql
@@ -1,7 +1,7 @@
-DROP table core;
-DROP table hits;
-DROP table failures;
-DROP table users;
-DROP table checkins;
-DROP table services;
-DROP table communication;
\ No newline at end of file
+DROP TABLE IF EXISTS core;
+DROP TABLE IF EXISTS hits;
+DROP TABLE IF EXISTS failures;
+DROP TABLE IF EXISTS users;
+DROP TABLE IF EXISTS checkins;
+DROP TABLE IF EXISTS services;
+DROP TABLE IF EXISTS communication;
\ No newline at end of file
diff --git a/source/sql/sqlite_up.sql b/source/sql/sqlite_up.sql
index a67f6571..97c552ef 100644
--- a/source/sql/sqlite_up.sql
+++ b/source/sql/sqlite_up.sql
@@ -11,7 +11,7 @@ CREATE TABLE core (
);
CREATE TABLE users (
- id SERIAL PRIMARY KEY,
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
username text,
password text,
email text,
@@ -22,7 +22,7 @@ CREATE TABLE users (
);
CREATE TABLE services (
- id SERIAL PRIMARY KEY,
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
name text,
domain text,
check_type text,
@@ -37,14 +37,14 @@ CREATE TABLE services (
);
CREATE TABLE hits (
- id SERIAL PRIMARY KEY,
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
service INTEGER NOT NULL REFERENCES services(id) ON DELETE CASCADE ON UPDATE CASCADE,
latency float,
created_at TIMESTAMP
);
CREATE TABLE failures (
- id SERIAL PRIMARY KEY,
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
issue text,
method text,
service INTEGER NOT NULL REFERENCES services(id) ON DELETE CASCADE ON UPDATE CASCADE,
@@ -52,7 +52,7 @@ CREATE TABLE failures (
);
CREATE TABLE checkins (
- id SERIAL PRIMARY KEY,
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
service INTEGER NOT NULL REFERENCES services(id) ON DELETE CASCADE ON UPDATE CASCADE,
check_interval integer,
api text,
@@ -60,7 +60,7 @@ CREATE TABLE checkins (
);
CREATE TABLE communication (
- id SERIAL PRIMARY KEY,
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
method text,
host text,
port integer,
diff --git a/source/tmpl/help.html b/source/tmpl/help.html
index afeaf9d5..ca31f788 100644
--- a/source/tmpl/help.html
+++ b/source/tmpl/help.html
@@ -50,6 +50,8 @@
+{{template "footer"}}
+
diff --git a/source/tmpl/setup.html b/source/tmpl/setup.html
index ed57d2e7..309efd79 100644
--- a/source/tmpl/setup.html
+++ b/source/tmpl/setup.html
@@ -35,24 +35,24 @@
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
@@ -60,13 +60,13 @@