cypress updates, change to SQLite database package and settings,

pull/471/head
Hunter Long 2020-03-31 11:41:12 -07:00
parent e6a4dd3e45
commit 1d3418a9f0
18 changed files with 137 additions and 229 deletions

1
.gitignore vendored
View File

@ -33,3 +33,4 @@ databases
statping statping
docker docker
tmp tmp
/frontend/cypress/screenshots/

View File

@ -10,14 +10,7 @@ import (
_ "github.com/jinzhu/gorm/dialects/mysql" _ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/postgres" _ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite" _ "github.com/mattn/go-sqlite3"
)
const (
TIME_NANO = "2006-01-02T15:04:05Z"
TIME = "2006-01-02 15:04:05"
CHART_TIME = "2006-01-02T15:04:05.999999-07:00"
TIME_DAY = "2006-01-02"
) )
var database Database var database Database

View File

@ -9,7 +9,7 @@ import (
_ "github.com/jinzhu/gorm/dialects/mysql" _ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/postgres" _ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite" _ "github.com/mattn/go-sqlite3"
) )
var ( var (

View File

@ -1,5 +1,5 @@
{ {
"projectId": "bi8mhr", "projectId": "wmw54a",
"env": { "env": {
"DB_HOST": "localhost", "DB_HOST": "localhost",
"DB_USER": "root", "DB_USER": "root",
@ -10,8 +10,8 @@
}, },
"baseUrl": "http://localhost:8888", "baseUrl": "http://localhost:8888",
"chromeWebSecurity": false, "chromeWebSecurity": false,
"defaultCommandTimeout": 8000, "defaultCommandTimeout": 15000,
"requestTimeout": 8000, "requestTimeout": 15000,
"watchForFileChanges": false, "watchForFileChanges": false,
"failOnStatusCode": false "failOnStatusCode": false
} }

View File

@ -2,39 +2,12 @@
context('Setup Process', () => { context('Setup Process', () => {
// it('should go to setup Statping with Postgres', () => {
// cy.visit('http://localhost:8080')
// cy.get('select[name=db_connection]').select('postgres')
// cy.get('input[name="db_host"]').clear().type(Cypress.env('DB_HOST'))
// cy.get('input[name="db_port"]').clear().type('5432')
// cy.get('input[name="db_user"]').clear().type(Cypress.env('DB_USER'))
// if (Cypress.env('TRAVIS')==="yes") {
// cy.get('input[name="db_password"]').clear()
// } else {
// cy.get('input[name="db_password"]').clear().type(Cypress.env('DB_PASS'))
// }
// cy.get('input[name="db_database"]').clear().type(Cypress.env('DB_DATABASE'))
// cy.get('input[name="project"]').clear().type('Demo Tester')
// cy.get('input[name="description"]').clear().type('This is a test from Crypress!')
// cy.get('input[name="domain"]').clear().type('http://localhost:8080')
// cy.get('input[name="username"]').clear().type('admin')
// cy.get('input[name="email"]').clear().type('info@domain.com')
// cy.get('input[name="password"]').clear().type('admin')
// cy.scrollTo('bottom')
// cy.get('#setup_button').click().wait(10000)
// cy.get('.header-title').should('contain', 'Demo Tester')
// cy.get('.header-desc').should('contain', 'This is a test from Crypress!')
// cy.scrollTo('bottom')
// cy.get('.service_li').should('have.length', 5)
// cy.get('.card').should('have.length', 5)
// })
it('should setup Statping with SQLite', () => { it('should setup Statping with SQLite', () => {
cy.visit('/setup', {failOnStatusCode: false}) cy.visit('/setup', {failOnStatusCode: false})
cy.get('#db_connection').select('sqlite') cy.get('#db_connection').select('sqlite')
cy.get('#project').clear().type('Demo Tester') cy.get('#project').clear().type('Demo Tester')
cy.get('#description').clear().type('This is a test from Crypress!') cy.get('#description').clear().type('This is a test from Crypress!')
cy.get('#domain').clear().type('http://localhost:8080') cy.get('#domain').clear().type('http://localhost:8888')
cy.get('#username').clear().type('admin') cy.get('#username').clear().type('admin')
cy.get('#password').clear().type('admin') cy.get('#password').clear().type('admin')
cy.get('#password_confirm').clear().type('admin') cy.get('#password_confirm').clear().type('admin')
@ -42,8 +15,12 @@ context('Setup Process', () => {
cy.get('#title').should('contain', 'Demo Tester') cy.get('#title').should('contain', 'Demo Tester')
cy.get('#description').should('contain', 'This is a test from Crypress!') cy.get('#description').should('contain', 'This is a test from Crypress!')
cy.get('.list-group').should('have.length', 5) })
it('should have sample data', () => {
cy.visit('/')
cy.get('.card').should('have.length', 5) cy.get('.card').should('have.length', 5)
cy.get('.group_header').should('have.length', 2)
}) })
}) })

View File

@ -52,10 +52,16 @@ context('Groups Tests', () => {
cy.visit('/dashboard/services') cy.visit('/dashboard/services')
cy.get('.sortable_groups > tr').should('have.length', 5) cy.get('.sortable_groups > tr').should('have.length', 5)
cy.get('.sortable_groups > tr').eq(0).contains('PRIVATE') cy.get('.sortable_groups > tr').eq(0).contains('PUBLIC')
cy.get('.sortable_groups > tr').eq(0).contains('Test Private Group') cy.get('.sortable_groups > tr').eq(0).contains('Test Group')
cy.get('.sortable_groups > tr').eq(1).contains('PUBLIC') cy.get('.sortable_groups > tr').eq(1).contains('PRIVATE')
cy.get('.sortable_groups > tr').eq(1).contains('Test Group') cy.get('.sortable_groups > tr').eq(1).contains('Test Private Group')
})
it('should delete new groups', () => {
cy.get('.sortable_groups > tr').eq(0).find('.btn-danger').click()
cy.get('.sortable_groups > tr').eq(1).find('.btn-danger').click()
cy.get('.sortable_groups > tr').should('have.length', 3)
}) })
}) })

View File

@ -4,7 +4,6 @@ import "../support/commands"
context('Services Tests', () => { context('Services Tests', () => {
beforeEach(() => { beforeEach(() => {
cy.restoreLocalStorageCache(); cy.restoreLocalStorageCache();
}); });
@ -13,33 +12,6 @@ context('Services Tests', () => {
cy.saveLocalStorageCache(); cy.saveLocalStorageCache();
}); });
// it('should go to setup Statping with Postgres', () => {
// cy.visit('http://localhost:8080')
// cy.get('select[name=db_connection]').select('postgres')
// cy.get('input[name="db_host"]').clear().type(Cypress.env('DB_HOST'))
// cy.get('input[name="db_port"]').clear().type('5432')
// cy.get('input[name="db_user"]').clear().type(Cypress.env('DB_USER'))
// if (Cypress.env('TRAVIS')==="yes") {
// cy.get('input[name="db_password"]').clear()
// } else {
// cy.get('input[name="db_password"]').clear().type(Cypress.env('DB_PASS'))
// }
// cy.get('input[name="db_database"]').clear().type(Cypress.env('DB_DATABASE'))
// cy.get('input[name="project"]').clear().type('Demo Tester')
// cy.get('input[name="description"]').clear().type('This is a test from Crypress!')
// cy.get('input[name="domain"]').clear().type('http://localhost:8080')
// cy.get('input[name="username"]').clear().type('admin')
// cy.get('input[name="email"]').clear().type('info@domain.com')
// cy.get('input[name="password"]').clear().type('admin')
// cy.scrollTo('bottom')
// cy.get('#setup_button').click().wait(10000)
// cy.get('.header-title').should('contain', 'Demo Tester')
// cy.get('.header-desc').should('contain', 'This is a test from Crypress!')
// cy.scrollTo('bottom')
// cy.get('.service_li').should('have.length', 5)
// cy.get('.card').should('have.length', 5)
// })
it('should Login', () => { it('should Login', () => {
cy.visit('/login') cy.visit('/login')
cy.get('#username').clear().type('admin') cy.get('#username').clear().type('admin')

View File

@ -13,33 +13,6 @@ context('Users Tests', () => {
cy.saveLocalStorageCache(); cy.saveLocalStorageCache();
}); });
// it('should go to setup Statping with Postgres', () => {
// cy.visit('http://localhost:8080')
// cy.get('select[name=db_connection]').select('postgres')
// cy.get('input[name="db_host"]').clear().type(Cypress.env('DB_HOST'))
// cy.get('input[name="db_port"]').clear().type('5432')
// cy.get('input[name="db_user"]').clear().type(Cypress.env('DB_USER'))
// if (Cypress.env('TRAVIS')==="yes") {
// cy.get('input[name="db_password"]').clear()
// } else {
// cy.get('input[name="db_password"]').clear().type(Cypress.env('DB_PASS'))
// }
// cy.get('input[name="db_database"]').clear().type(Cypress.env('DB_DATABASE'))
// cy.get('input[name="project"]').clear().type('Demo Tester')
// cy.get('input[name="description"]').clear().type('This is a test from Crypress!')
// cy.get('input[name="domain"]').clear().type('http://localhost:8080')
// cy.get('input[name="username"]').clear().type('admin')
// cy.get('input[name="email"]').clear().type('info@domain.com')
// cy.get('input[name="password"]').clear().type('admin')
// cy.scrollTo('bottom')
// cy.get('#setup_button').click().wait(10000)
// cy.get('.header-title').should('contain', 'Demo Tester')
// cy.get('.header-desc').should('contain', 'This is a test from Crypress!')
// cy.scrollTo('bottom')
// cy.get('.service_li').should('have.length', 5)
// cy.get('.card').should('have.length', 5)
// })
it('should Login', () => { it('should Login', () => {
cy.visit('/login') cy.visit('/login')
cy.get('#username').clear().type('admin') cy.get('#username').clear().type('admin')
@ -68,12 +41,11 @@ context('Users Tests', () => {
cy.get('button[type="submit"]').click() cy.get('button[type="submit"]').click()
}) })
it('should confirm new user', () => { // it('should confirm new user', () => {
cy.visit('/dashboard/users') // cy.visit('/dashboard/users')
cy.get('#users_table > tr').should('have.length', 2) // cy.get('#users_table > tr').should('have.length', 2)
cy.get('#users_table > tr').eq(0).contains('admin') // cy.get('#users_table > tr').eq(0).contains('admin')
cy.get('#users_table > tr').eq(1).contains('admin2') // cy.get('#users_table > tr').eq(1).contains('admin2')
}) // })
}) })

View File

@ -9,8 +9,8 @@
"lint": "vue-cli-service lint", "lint": "vue-cli-service lint",
"test": "cross-env NODE_ENV=development mochapack --webpack-config webpack.config.js --require test/setup.js test/**/*.spec.js", "test": "cross-env NODE_ENV=development mochapack --webpack-config webpack.config.js --require test/setup.js test/**/*.spec.js",
"backend-test": "newman run -e ../dev/postman_environment.json --delay-request 500 ../dev/postman.json", "backend-test": "newman run -e ../dev/postman_environment.json --delay-request 500 ../dev/postman.json",
"cypress": "cypress open", "cypress:open": "cypress open",
"e2e": "cypress run --record --key" "cypress:test": "cypress run --record --key 49d99e5e-04c6-46df-beef-54b68e152a4d"
}, },
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free-solid": "^5.1.0-3", "@fortawesome/fontawesome-free-solid": "^5.1.0-3",

View File

@ -216,18 +216,18 @@
} }
}, },
watch: { watch: {
in_service() { in_service () {
this.service = this.in_service this.service = this.in_service
} }
}, },
async mounted() { async mounted () {
if (!this.$store.getters.groups) { if (!this.$store.getters.groups) {
const groups = await Api.groups() const groups = await Api.groups()
this.$store.commit('setGroups', groups) this.$store.commit('setGroups', groups)
} }
}, },
methods: { methods: {
async saveService() { async saveService () {
let s = this.service let s = this.service
this.loading = true this.loading = true
delete s.failures delete s.failures
@ -241,8 +241,7 @@
s.port = parseInt(s.port) s.port = parseInt(s.port)
s.notify_after = parseInt(s.notify_after) s.notify_after = parseInt(s.notify_after)
s.expected_status = parseInt(s.expected_status) s.expected_status = parseInt(s.expected_status)
s.order = parseInt(s.order)
window.console.log(s)
if (s.id) { if (s.id) {
await this.updateService(s) await this.updateService(s)
@ -254,14 +253,14 @@
this.loading = false this.loading = false
this.$router.push('/dashboard/services') this.$router.push('/dashboard/services')
}, },
async createService(s) { async createService (s) {
await Api.service_create(s) await Api.service_create(s)
}, },
async updateService(s) { async updateService (s) {
await Api.service_update(s) await Api.service_update(s)
} }
} }
} }
</script> </script>
<!-- Add "scoped" attribute to limit CSS to this component only --> <!-- Add "scoped" attribute to limit CSS to this component only -->

1
go.mod
View File

@ -14,6 +14,7 @@ require (
github.com/gorilla/mux v1.7.4 github.com/gorilla/mux v1.7.4
github.com/jinzhu/gorm v1.9.12 github.com/jinzhu/gorm v1.9.12
github.com/joho/godotenv v1.3.0 github.com/joho/godotenv v1.3.0
github.com/mattn/go-sqlite3 v2.0.1+incompatible
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/prometheus/common v0.9.1 github.com/prometheus/common v0.9.1
github.com/rendon/testcli v0.0.0-20161027181003-6283090d169f github.com/rendon/testcli v0.0.0-20161027181003-6283090d169f

View File

@ -168,9 +168,6 @@ func Router() *mux.Router {
api.Handle("/api/checkin/{api}", authenticated(checkinDeleteHandler, false)).Methods("DELETE") api.Handle("/api/checkin/{api}", authenticated(checkinDeleteHandler, false)).Methods("DELETE")
r.Handle("/checkin/{api}", http.HandlerFunc(checkinHitHandler)) r.Handle("/checkin/{api}", http.HandlerFunc(checkinHitHandler))
//r.PathPrefix("/").Handler(http.HandlerFunc(indexHandler))
//r.Handle("/badge", http.HandlerFunc(badgeHandler)).Methods("GET")
// Static Files Routes // Static Files Routes
r.PathPrefix("/files/postman.json").Handler(http.StripPrefix("/files/", http.FileServer(source.TmplBox.HTTPBox()))) r.PathPrefix("/files/postman.json").Handler(http.StripPrefix("/files/", http.FileServer(source.TmplBox.HTTPBox())))
r.PathPrefix("/files/swagger.json").Handler(http.StripPrefix("/files/", http.FileServer(source.TmplBox.HTTPBox()))) r.PathPrefix("/files/swagger.json").Handler(http.StripPrefix("/files/", http.FileServer(source.TmplBox.HTTPBox())))

View File

@ -16,7 +16,6 @@
package handlers package handlers
import ( import (
"fmt"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/statping/statping/database" "github.com/statping/statping/database"
@ -209,7 +208,6 @@ func apiServiceDeleteHandler(w http.ResponseWriter, r *http.Request) {
func apiAllServicesHandler(r *http.Request) interface{} { func apiAllServicesHandler(r *http.Request) interface{} {
user := IsUser(r) user := IsUser(r)
fmt.Println("user: ", user)
var srvs []services.Service var srvs []services.Service
for _, v := range services.AllInOrder() { for _, v := range services.AllInOrder() {
if !v.Public.Bool && !user { if !v.Public.Bool && !user {

View File

@ -41,7 +41,9 @@ func processSetupHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
//sample, _ := strconv.ParseBool(r.PostForm.Get("sample_data")) project := r.PostForm.Get("project")
description := r.PostForm.Get("description")
domain := r.PostForm.Get("domain")
log.WithFields(utils.ToFields(core.App, confgs)).Debugln("new configs posted") log.WithFields(utils.ToFields(core.App, confgs)).Debugln("new configs posted")
@ -94,11 +96,11 @@ func processSetupHandler(w http.ResponseWriter, r *http.Request) {
notifiers.InitNotifiers() notifiers.InitNotifiers()
c := &core.Core{ c := &core.Core{
Name: "Statping Sample Data", Name: project,
Description: "This data is only used to testing", Description: description,
//ApiKey: apiKey.(string), //ApiKey: apiKey.(string),
//ApiSecret: apiSecret.(string), //ApiSecret: apiSecret.(string),
Domain: "http://localhost:8080", Domain: domain,
Version: core.App.Version, Version: core.App.Version,
Started: utils.Now(), Started: utils.Now(),
CreatedAt: utils.Now(), CreatedAt: utils.Now(),

View File

@ -72,15 +72,11 @@ func Connect(configs *DbConfig, retry bool) error {
log.WithFields(utils.ToFields(dbSession)).Debugln("connected to database") log.WithFields(utils.ToFields(dbSession)).Debugln("connected to database")
maxOpenConn := utils.Getenv("MAX_OPEN_CONN", 5) maxOpenConn := utils.Getenv("MAX_OPEN_CONN", 25)
maxIdleConn := utils.Getenv("MAX_IDLE_CONN", 5) maxIdleConn := utils.Getenv("MAX_IDLE_CONN", 25)
maxLifeConn := utils.Getenv("MAX_LIFE_CONN", 2*time.Minute) maxLifeConn := utils.Getenv("MAX_LIFE_CONN", 5*time.Minute)
if configs.DbConn == "sqlite3" {
dbSession.DB().SetMaxOpenConns(2)
} else {
dbSession.DB().SetMaxOpenConns(maxOpenConn.(int)) dbSession.DB().SetMaxOpenConns(maxOpenConn.(int))
}
dbSession.DB().SetMaxIdleConns(maxIdleConn.(int)) dbSession.DB().SetMaxIdleConns(maxIdleConn.(int))
dbSession.DB().SetConnMaxLifetime(maxLifeConn.(time.Duration)) dbSession.DB().SetConnMaxLifetime(maxLifeConn.(time.Duration))

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
_ "github.com/jinzhu/gorm/dialects/mysql" _ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/postgres" _ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite" _ "github.com/mattn/go-sqlite3"
"github.com/statping/statping/source" "github.com/statping/statping/source"
"github.com/statping/statping/types/notifications" "github.com/statping/statping/types/notifications"
"github.com/statping/statping/utils" "github.com/statping/statping/utils"

View File

@ -2,25 +2,24 @@ package failures
import ( import (
"fmt" "fmt"
"github.com/prometheus/common/log"
"github.com/statping/statping/types" "github.com/statping/statping/types"
"github.com/statping/statping/utils" "github.com/statping/statping/utils"
"sync"
"time" "time"
_ "github.com/jinzhu/gorm/dialects/mysql" _ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/postgres" _ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite" _ "github.com/mattn/go-sqlite3"
)
var (
log = utils.Log
) )
func Samples() error { func Samples() error {
tx := db.Begin()
sg := new(sync.WaitGroup)
createdAt := utils.Now().Add(-3 * types.Day) createdAt := utils.Now().Add(-3 * types.Day)
for i := int64(1); i <= 4; i++ { for i := int64(1); i <= 4; i++ {
sg.Add(1) tx := db.Begin()
f1 := &Failure{ f1 := &Failure{
Service: i, Service: i,
@ -38,8 +37,6 @@ func Samples() error {
log.Infoln(fmt.Sprintf("Adding %v Failure records to service", 400)) log.Infoln(fmt.Sprintf("Adding %v Failure records to service", 400))
go func() {
defer sg.Done()
for fi := 0.; fi <= float64(400); fi++ { for fi := 0.; fi <= float64(400); fi++ {
createdAt = createdAt.Add(35 * time.Minute) createdAt = createdAt.Add(35 * time.Minute)
failure := &Failure{ failure := &Failure{
@ -50,14 +47,11 @@ func Samples() error {
tx = tx.Create(&failure) tx = tx.Create(&failure)
} }
}()
}
sg.Wait()
if err := tx.Commit().Error(); err != nil { if err := tx.Commit().Error(); err != nil {
log.Error(err) log.Error(err)
return err return err
} }
}
return nil return nil
} }

View File

@ -10,7 +10,7 @@ import (
_ "github.com/jinzhu/gorm/dialects/mysql" _ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/postgres" _ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite" _ "github.com/mattn/go-sqlite3"
) )
var SampleHits = 99900. var SampleHits = 99900.