additional testing

pull/127/head^2^2
Hunter Long 2019-02-11 13:10:17 -08:00
parent 55f5322985
commit 0cf1e077ef
6 changed files with 245 additions and 270 deletions

View File

@ -51,29 +51,12 @@ func LoadConfigFile(directory string) (*DbConfig, error) {
// LoadUsingEnv will attempt to load database configs based on environment variables. If DB_CONN is set if will force this function.
func LoadUsingEnv() (*DbConfig, error) {
Configs = new(DbConfig)
Configs.LocalIP = GetLocalIP()
if os.Getenv("DB_CONN") == "" {
return Configs, errors.New("Missing DB_CONN environment variable")
Configs, err := EnvToConfig()
if err != nil {
return Configs, err
}
if os.Getenv("DB_CONN") != "sqlite" {
if os.Getenv("DB_HOST") == "" {
return Configs, errors.New("Missing DB_HOST environment variable")
}
if os.Getenv("DB_USER") == "" {
return Configs, errors.New("Missing DB_USER environment variable")
}
if os.Getenv("DB_PASS") == "" {
return Configs, errors.New("Missing DB_PASS environment variable")
}
if os.Getenv("DB_DATABASE") == "" {
return Configs, errors.New("Missing DB_DATABASE environment variable")
}
}
Configs = EnvToConfig()
CoreApp.Name = os.Getenv("NAME")
domain := os.Getenv("DOMAIN")
if domain == "" {
if Configs.Domain == "" {
CoreApp.Domain = Configs.LocalIP
} else {
CoreApp.Domain = os.Getenv("DOMAIN")
@ -81,7 +64,7 @@ func LoadUsingEnv() (*DbConfig, error) {
CoreApp.DbConnection = Configs.DbConn
CoreApp.UseCdn = types.NewNullBool(os.Getenv("USE_CDN") == "true")
err := Configs.Connect(true, utils.Directory)
err = Configs.Connect(true, utils.Directory)
if err != nil {
utils.Log(4, err)
return nil, err
@ -126,7 +109,26 @@ func DefaultPort(db string) int64 {
}
// EnvToConfig converts environment variables to a DbConfig variable
func EnvToConfig() *DbConfig {
func EnvToConfig() (*DbConfig, error) {
Configs = new(DbConfig)
var err error
if os.Getenv("DB_CONN") == "" {
return Configs, errors.New("Missing DB_CONN environment variable")
}
if os.Getenv("DB_CONN") != "sqlite" {
if os.Getenv("DB_HOST") == "" {
return Configs, errors.New("Missing DB_HOST environment variable")
}
if os.Getenv("DB_USER") == "" {
return Configs, errors.New("Missing DB_USER environment variable")
}
if os.Getenv("DB_PASS") == "" {
return Configs, errors.New("Missing DB_PASS environment variable")
}
if os.Getenv("DB_DATABASE") == "" {
return Configs, errors.New("Missing DB_DATABASE environment variable")
}
}
port := utils.ToInt(os.Getenv("DB_PORT"))
if port == 0 {
port = DefaultPort(os.Getenv("DB_PORT"))
@ -150,7 +152,7 @@ func EnvToConfig() *DbConfig {
adminPass = "admin"
}
data := &DbConfig{
Configs = &DbConfig{
DbConn: os.Getenv("DB_CONN"),
DbHost: os.Getenv("DB_HOST"),
DbUser: os.Getenv("DB_USER"),
@ -166,7 +168,7 @@ func EnvToConfig() *DbConfig {
Error: nil,
Location: utils.Directory,
}
return data
return Configs, err
}
// SampleData runs all the sample data for a new Statping installation

View File

@ -19,6 +19,7 @@ import (
"github.com/hunterlong/statping/source"
"github.com/hunterlong/statping/utils"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
@ -121,3 +122,27 @@ func TestInsertNotifierDB(t *testing.T) {
err := InsertNotifierDB()
assert.Nil(t, err)
}
func TestEnvToConfig(t *testing.T) {
os.Setenv("DB_CONN", "sqlite")
os.Setenv("DB_USER", "")
os.Setenv("DB_PASS", "")
os.Setenv("DB_DATABASE", "")
os.Setenv("NAME", "Testing")
os.Setenv("DOMAIN", "http://localhost:8080")
os.Setenv("DESCRIPTION", "Testing Statping")
os.Setenv("ADMIN_USER", "admin")
os.Setenv("ADMIN_PASS", "admin123")
config, err := EnvToConfig()
assert.Nil(t, err)
assert.Equal(t, config.DbConn, "sqlite")
assert.Equal(t, config.Domain, "http://localhost:8080")
assert.Equal(t, config.Description, "Testing Statping")
assert.Equal(t, config.Username, "admin")
assert.Equal(t, config.Password, "admin123")
}
func TestGetLocalIP(t *testing.T) {
ip := GetLocalIP()
assert.Contains(t, ip, "http://")
}

View File

@ -116,12 +116,6 @@ func reorderServices() {
sort.Sort(ServiceOrder(CoreApp.Services))
}
// ToJSON will convert a service to a JSON string
func (s *Service) ToJSON() string {
data, _ := json.Marshal(s)
return string(data)
}
// AvgTime will return the average amount of time for a service to response back successfully
func (s *Service) AvgTime() string {
total, _ := s.TotalHits()

View File

@ -24,6 +24,7 @@ import (
var (
newServiceId int64
newGroupId int64
)
func TestSelectHTTPService(t *testing.T) {
@ -345,3 +346,68 @@ func TestDNScheckService(t *testing.T) {
assert.Nil(t, err)
assert.NotZero(t, amount)
}
func TestSelectServiceLink(t *testing.T) {
service := SelectService(1)
assert.Equal(t, "google", service.Permalink.String)
}
func TestDbtimestamp(t *testing.T) {
CoreApp.DbConnection = "mysql"
query := Dbtimestamp("minute", "latency")
assert.Equal(t, "CONCAT(date_format(created_at, '%Y-%m-%d %H:00:00')) AS timeframe, AVG(latency) AS value", query)
CoreApp.DbConnection = "postgres"
query = Dbtimestamp("minute", "latency")
assert.Equal(t, "date_trunc('minute', created_at) AS timeframe, AVG(latency) AS value", query)
CoreApp.DbConnection = "sqlite"
query = Dbtimestamp("minute", "latency")
assert.Equal(t, "datetime((strftime('%s', created_at) / 60) * 60, 'unixepoch') AS timeframe, AVG(latency) as value", query)
}
func TestGroup_Create(t *testing.T) {
group := &Group{&types.Group{
Name: "Testing",
}}
newGroupId, err := group.Create()
assert.Nil(t, err)
assert.NotZero(t, newGroupId)
}
func TestGroup_Services(t *testing.T) {
group := SelectGroup(1)
assert.NotEmpty(t, group.Services())
}
func TestSelectGroups(t *testing.T) {
groups := SelectGroups(true, false)
assert.Equal(t, int(3), len(groups))
groups = SelectGroups(true, true)
assert.Equal(t, int(4), len(groups))
}
func TestService_TotalFailures(t *testing.T) {
service := SelectService(8)
failures, err := service.TotalFailures()
assert.Nil(t, err)
assert.Equal(t, uint64(1), failures)
}
func TestService_TotalFailures24(t *testing.T) {
service := SelectService(8)
failures, err := service.TotalFailures24()
assert.Nil(t, err)
assert.Equal(t, uint64(1), failures)
}
func TestService_TotalFailuresOnDate(t *testing.T) {
ago := time.Now().UTC()
service := SelectService(8)
failures, err := service.TotalFailuresOnDate(ago)
assert.Nil(t, err)
assert.Equal(t, uint64(0), failures)
}
func TestCountFailures(t *testing.T) {
failures := CountFailures()
assert.Equal(t, uint64(1463), failures)
}

View File

@ -7,66 +7,54 @@
/* Mobile Service Container */
HTML, BODY {
background-color: #fcfcfc;
padding-bottom: 10px;
}
padding-bottom: 10px; }
.container {
padding-top: 20px;
padding-bottom: 25px;
max-width: 860px;
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
}
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important; }
.header-title {
color: #464646;
}
color: #464646; }
.header-desc {
color: #939393;
}
color: #939393; }
.btn {
border-radius: 0.2rem;
}
border-radius: 0.2rem; }
.online_list .badge {
margin-top: 0.2rem;
}
margin-top: 0.2rem; }
.navbar {
margin-bottom: 30px;
}
margin-bottom: 30px; }
.btn-sm {
line-height: 1.3;
font-size: 0.75rem;
}
font-size: 0.75rem; }
.view_service_btn {
position: absolute;
bottom: -40px;
right: 40px;
}
right: 40px; }
.service_lower_info {
position: absolute;
bottom: -40px;
left: 40px;
color: #d1ffca;
font-size: 0.85rem;
}
font-size: 0.85rem; }
.lg_number {
font-size: 2.3rem;
font-weight: bold;
display: block;
color: #4f4f4f;
}
color: #4f4f4f; }
.stats_area {
text-align: center;
color: #a5a5a5;
}
color: #a5a5a5; }
.lower_canvas {
height: 3.4rem;
@ -74,151 +62,118 @@ HTML, BODY {
background-color: #48d338;
padding: 15px 10px;
margin-left: 0px !important;
margin-right: 0px !important;
}
margin-right: 0px !important; }
.lower_canvas SPAN {
font-size: 1rem;
color: #fff;
}
color: #fff; }
.footer {
text-decoration: none;
margin-top: 20px;
}
margin-top: 20px; }
.footer A {
color: #8d8d8d;
text-decoration: none;
}
text-decoration: none; }
.footer A:HOVER {
color: #6d6d6d;
}
color: #6d6d6d; }
.badge {
color: white;
border-radius: 0.2rem;
}
border-radius: 0.2rem; }
.btn-group {
height: 25px;
}
.btn-group A {
padding: 0.1rem 0.75rem;
font-size: 0.8rem;
}
height: 25px; }
.btn-group A {
padding: 0.1rem .75rem;
font-size: 0.8rem; }
.card-body .badge {
color: #fff;
}
color: #fff; }
.nav-pills .nav-link {
border-radius: 0.2rem;
}
border-radius: 0.2rem; }
.form-control {
border-radius: 0.2rem;
}
border-radius: 0.2rem; }
.card {
background-color: #ffffff;
border: 1px solid rgba(0, 0, 0, 0.125);
}
border: 1px solid rgba(0, 0, 0, 0.125); }
.card-body {
overflow: hidden;
}
overflow: hidden; }
.card-body H4 A {
color: #444444;
text-decoration: none;
}
text-decoration: none; }
.chart-container {
position: relative;
height: 170px;
width: 100%;
overflow: hidden;
}
overflow: hidden; }
.service-chart-container {
position: relative;
height: 400px;
width: 100%;
}
width: 100%; }
.service-chart-heatmap {
position: relative;
height: 300px;
width: 100%;
}
width: 100%; }
.btn-primary {
background-color: #3e9bff;
border-color: #006fe6;
color: white;
}
.btn-primary.dyn-dark {
background-color: #32a825 !important;
border-color: #2c9320 !important;
}
.btn-primary.dyn-light {
background-color: #75de69 !important;
border-color: #88e37e !important;
}
color: white; }
.btn-primary.dyn-dark {
background-color: #32a825 !important;
border-color: #2c9320 !important; }
.btn-primary.dyn-light {
background-color: #75de69 !important;
border-color: #88e37e !important; }
.btn-success {
background-color: #47d337;
}
.btn-success.dyn-dark {
background-color: #32a825 !important;
border-color: #2c9320 !important;
}
.btn-success.dyn-light {
background-color: #75de69 !important;
border-color: #88e37e !important;
}
background-color: #47d337; }
.btn-success.dyn-dark {
background-color: #32a825 !important;
border-color: #2c9320 !important; }
.btn-success.dyn-light {
background-color: #75de69 !important;
border-color: #88e37e !important; }
.btn-danger {
background-color: #dd3545;
}
.btn-danger.dyn-dark {
background-color: #b61f2d !important;
border-color: #a01b28 !important;
}
.btn-danger.dyn-light {
background-color: #e66975 !important;
border-color: #e97f89 !important;
}
background-color: #dd3545; }
.btn-danger.dyn-dark {
background-color: #b61f2d !important;
border-color: #a01b28 !important; }
.btn-danger.dyn-light {
background-color: #e66975 !important;
border-color: #e97f89 !important; }
.bg-success {
background-color: #47d337 !important;
}
background-color: #47d337 !important; }
.bg-danger {
background-color: #dd3545 !important;
}
background-color: #dd3545 !important; }
.bg-success .dyn-dark {
background-color: #35b027 !important;
}
background-color: #35b027 !important; }
.bg-danger .dyn-dark {
background-color: #bf202f !important;
}
background-color: #bf202f !important; }
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
background-color: #13a00d;
}
background-color: #13a00d; }
.nav-pills A {
color: #424242;
}
color: #424242; }
.nav-pills I {
margin-right: 10px;
}
margin-right: 10px; }
.CodeMirror {
/* Bootstrap Settings */
@ -238,26 +193,23 @@ HTML, BODY {
border: 1px solid #ccc;
border-radius: 4px;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
/* Code Mirror Settings */
font-family: monospace;
position: relative;
overflow: hidden;
height: 80vh;
}
height: 80vh; }
.CodeMirror-focused {
/* Bootstrap Settings */
border-color: #66afe9;
outline: 0;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6);
transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
}
transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; }
.switch {
font-size: 1rem;
position: relative;
}
position: relative; }
.switch input {
position: absolute;
@ -268,8 +220,7 @@ HTML, BODY {
clip: rect(0 0 0 0);
clip-path: inset(50%);
overflow: hidden;
padding: 0;
}
padding: 0; }
.switch input + label {
position: relative;
@ -282,26 +233,23 @@ HTML, BODY {
outline: none;
user-select: none;
vertical-align: middle;
text-indent: calc(calc(calc(2.375rem * .8) * 2) + .5rem);
}
text-indent: calc(calc(calc(2.375rem * .8) * 2) + .5rem); }
.switch input + label::before,
.switch input + label::after {
content: "";
content: '';
position: absolute;
top: 0;
left: 0;
width: calc(calc(2.375rem * .8) * 2);
bottom: 0;
display: block;
}
display: block; }
.switch input + label::before {
right: 0;
background-color: #dee2e6;
border-radius: calc(2.375rem * .8);
transition: 0.2s all;
}
transition: 0.2s all; }
.switch input + label::after {
top: 2px;
@ -310,154 +258,120 @@ HTML, BODY {
height: calc(calc(2.375rem * .8) - calc(2px * 2));
border-radius: 50%;
background-color: white;
transition: 0.2s all;
}
transition: 0.2s all; }
.switch input:checked + label::before {
background-color: #08d;
}
background-color: #08d; }
.switch input:checked + label::after {
margin-left: calc(2.375rem * .8);
}
margin-left: calc(2.375rem * .8); }
.switch input:focus + label::before {
outline: none;
box-shadow: 0 0 0 0.2rem rgba(0, 136, 221, 0.25);
}
box-shadow: 0 0 0 0.2rem rgba(0, 136, 221, 0.25); }
.switch input:disabled + label {
color: #868e96;
cursor: not-allowed;
}
cursor: not-allowed; }
.switch input:disabled + label::before {
background-color: #e9ecef;
}
background-color: #e9ecef; }
.switch.switch-sm {
font-size: 0.875rem;
}
font-size: 0.875rem; }
.switch.switch-sm input + label {
min-width: calc(calc(1.9375rem * .8) * 2);
height: calc(1.9375rem * .8);
line-height: calc(1.9375rem * .8);
text-indent: calc(calc(calc(1.9375rem * .8) * 2) + .5rem);
}
text-indent: calc(calc(calc(1.9375rem * .8) * 2) + .5rem); }
.switch.switch-sm input + label::before {
width: calc(calc(1.9375rem * .8) * 2);
}
width: calc(calc(1.9375rem * .8) * 2); }
.switch.switch-sm input + label::after {
width: calc(calc(1.9375rem * .8) - calc(2px * 2));
height: calc(calc(1.9375rem * .8) - calc(2px * 2));
}
height: calc(calc(1.9375rem * .8) - calc(2px * 2)); }
.switch.switch-sm input:checked + label::after {
margin-left: calc(1.9375rem * .8);
}
margin-left: calc(1.9375rem * .8); }
.switch.switch-lg {
font-size: 1.25rem;
}
font-size: 1.25rem; }
.switch.switch-lg input + label {
min-width: calc(calc(3rem * .8) * 2);
height: calc(3rem * .8);
line-height: calc(3rem * .8);
text-indent: calc(calc(calc(3rem * .8) * 2) + .5rem);
}
text-indent: calc(calc(calc(3rem * .8) * 2) + .5rem); }
.switch.switch-lg input + label::before {
width: calc(calc(3rem * .8) * 2);
}
width: calc(calc(3rem * .8) * 2); }
.switch.switch-lg input + label::after {
width: calc(calc(3rem * .8) - calc(2px * 2));
height: calc(calc(3rem * .8) - calc(2px * 2));
}
height: calc(calc(3rem * .8) - calc(2px * 2)); }
.switch.switch-lg input:checked + label::after {
margin-left: calc(3rem * .8);
}
margin-left: calc(3rem * .8); }
.switch + .switch {
margin-left: 1rem;
}
margin-left: 1rem; }
@keyframes pulse_animation {
0% {
transform: scale(1);
}
transform: scale(1); }
30% {
transform: scale(1);
}
transform: scale(1); }
40% {
transform: scale(1.02);
}
transform: scale(1.02); }
50% {
transform: scale(1);
}
transform: scale(1); }
60% {
transform: scale(1);
}
transform: scale(1); }
70% {
transform: scale(1.05);
}
transform: scale(1.05); }
80% {
transform: scale(1);
}
transform: scale(1); }
100% {
transform: scale(1);
}
}
transform: scale(1); } }
.pulse {
animation-name: pulse_animation;
animation-duration: 1500ms;
transform-origin: 70% 70%;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
animation-timing-function: linear; }
@keyframes glow-grow {
0% {
opacity: 0;
transform: scale(1);
}
transform: scale(1); }
80% {
opacity: 1;
}
opacity: 1; }
100% {
transform: scale(2);
opacity: 0;
}
}
opacity: 0; } }
.pulse-glow {
animation-name: glow-grown;
animation-duration: 100ms;
transform-origin: 70% 30%;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
animation-timing-function: linear; }
.pulse-glow:before,
.pulse-glow:after {
position: absolute;
content: "";
content: '';
height: 0.5rem;
width: 1.75rem;
top: 1.2rem;
right: 2.15rem;
border-radius: 0;
box-shadow: 0 0 7px #47d337;
animation: glow-grow 2s ease-out infinite;
}
animation: glow-grow 2s ease-out infinite; }
.sortable_drag {
background-color: #0000000f;
}
background-color: #0000000f; }
.drag_icon {
cursor: move;
@ -471,132 +385,106 @@ HTML, BODY {
margin-right: 5px;
margin-left: -10px;
text-align: center;
color: #b1b1b1;
}
color: #b1b1b1; }
/* (Optional) Apply a "closed-hand" cursor during drag operation. */
.drag_icon:active {
cursor: grabbing;
cursor: -moz-grabbing;
cursor: -webkit-grabbing;
}
cursor: -webkit-grabbing; }
.switch_btn {
float: right;
margin: -1px 0px 0px 0px;
display: block;
}
display: block; }
#start_container {
position: absolute;
z-index: 99999;
margin-top: 20px;
}
margin-top: 20px; }
#end_container {
position: absolute;
z-index: 99999;
margin-top: 20px;
right: 0;
}
right: 0; }
.pointer {
cursor: pointer;
}
cursor: pointer; }
.jumbotron {
background-color: white;
}
background-color: white; }
@media (max-width: 767px) {
HTML, BODY {
background-color: #fcfcfc;
}
background-color: #fcfcfc; }
.sm-container {
margin-top: 0px !important;
padding: 0 !important;
}
padding: 0 !important; }
.list-group-item H5 {
font-size: 0.9rem;
}
font-size: 0.9rem; }
.container {
padding: 0px !important;
padding-top: 15px !important;
}
padding-top: 15px !important; }
.group_header {
margin-left: 15px;
}
margin-left: 15px; }
.navbar {
margin-left: 0px;
margin-top: 0px;
width: 100%;
margin-bottom: 0;
}
margin-bottom: 0; }
.btn-sm {
line-height: 0.9rem;
font-size: 0.65rem;
}
font-size: 0.65rem; }
.full-col-12 {
padding-left: 0px;
padding-right: 0px;
}
padding-right: 0px; }
.card {
border: 0;
border-radius: 0rem;
padding: 0;
background-color: #ffffff;
}
background-color: #ffffff; }
.card-body {
font-size: 10pt;
padding: 0px 10px;
}
padding: 0px 10px; }
.lg_number {
font-size: 7.8vw;
}
font-size: 7.8vw; }
.stats_area {
margin-top: 1.5rem !important;
margin-bottom: 1.5rem !important;
}
margin-bottom: 1.5rem !important; }
.stats_area .col-4 {
padding-left: 0;
padding-right: 0;
font-size: 0.6rem;
}
font-size: 0.6rem; }
.list-group-item {
border-top: 1px solid #e4e4e4;
border: 0px;
}
border: 0px; }
.list-group-item:first-child {
border-top-left-radius: 0;
border-top-right-radius: 0;
}
border-top-right-radius: 0; }
.list-group-item:last-child {
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
border-bottom-left-radius: 0; }
.list-group-item P {
font-size: 0.7rem;
}
font-size: 0.7rem; }
.service-chart-container {
height: 200px;
}
}
height: 200px; } }
/*# sourceMappingURL=base.css.map */

View File

@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2019-02-06 12:42:08.202468 -0800 PST m=+0.598756678
// 2019-02-11 11:11:00.271926 -0800 PST m=+0.838529941
//
// This contains the most recently Markdown source for the Statping Wiki.
package source