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
docker
tmp
/frontend/cypress/screenshots/

View File

@ -10,14 +10,7 @@ import (
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
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"
_ "github.com/mattn/go-sqlite3"
)
var database Database

View File

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

View File

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

View File

@ -2,39 +2,12 @@
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', () => {
cy.visit('/setup', {failOnStatusCode: false})
cy.get('#db_connection').select('sqlite')
cy.get('#project').clear().type('Demo Tester')
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('#password').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('#description').should('contain', 'This is a test from Crypress!')
cy.get('.list-group').should('have.length', 5)
cy.get('.card').should('have.length', 5)
})
it('should have sample data', () => {
cy.visit('/')
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.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('Test Private Group')
cy.get('.sortable_groups > tr').eq(1).contains('PUBLIC')
cy.get('.sortable_groups > tr').eq(1).contains('Test Group')
cy.get('.sortable_groups > tr').eq(0).contains('PUBLIC')
cy.get('.sortable_groups > tr').eq(0).contains('Test Group')
cy.get('.sortable_groups > tr').eq(1).contains('PRIVATE')
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', () => {
beforeEach(() => {
cy.restoreLocalStorageCache();
});
@ -13,33 +12,6 @@ context('Services Tests', () => {
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', () => {
cy.visit('/login')
cy.get('#username').clear().type('admin')

View File

@ -13,33 +13,6 @@ context('Users Tests', () => {
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', () => {
cy.visit('/login')
cy.get('#username').clear().type('admin')
@ -68,12 +41,11 @@ context('Users Tests', () => {
cy.get('button[type="submit"]').click()
})
it('should confirm new user', () => {
cy.visit('/dashboard/users')
cy.get('#users_table > tr').should('have.length', 2)
cy.get('#users_table > tr').eq(0).contains('admin')
cy.get('#users_table > tr').eq(1).contains('admin2')
})
// it('should confirm new user', () => {
// cy.visit('/dashboard/users')
// cy.get('#users_table > tr').should('have.length', 2)
// cy.get('#users_table > tr').eq(0).contains('admin')
// cy.get('#users_table > tr').eq(1).contains('admin2')
// })
})

View File

@ -9,8 +9,8 @@
"lint": "vue-cli-service lint",
"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",
"cypress": "cypress open",
"e2e": "cypress run --record --key"
"cypress:open": "cypress open",
"cypress:test": "cypress run --record --key 49d99e5e-04c6-46df-beef-54b68e152a4d"
},
"dependencies": {
"@fortawesome/fontawesome-free-solid": "^5.1.0-3",

View File

@ -182,86 +182,85 @@
import Api from "../API";
export default {
name: 'FormService',
data () {
return {
loading: false,
service: {
name: "",
type: "http",
domain: "",
group_id: 0,
method: "GET",
post_data: "",
headers: "",
expected: "",
expected_status: 200,
port: 80,
check_interval: 60,
timeout: 15,
permalink: "",
order: 1,
verify_ssl: true,
allow_notifications: true,
notify_all_changes: true,
notify_after: 2,
public: true,
name: 'FormService',
data () {
return {
loading: false,
service: {
name: "",
type: "http",
domain: "",
group_id: 0,
method: "GET",
post_data: "",
headers: "",
expected: "",
expected_status: 200,
port: 80,
check_interval: 60,
timeout: 15,
permalink: "",
order: 1,
verify_ssl: true,
allow_notifications: true,
notify_all_changes: true,
notify_after: 2,
public: true,
},
groups: [],
}
},
groups: [],
}
},
props: {
in_service: {
type: Object
}
},
watch: {
in_service() {
this.service = this.in_service
}
},
async mounted() {
if (!this.$store.getters.groups) {
const groups = await Api.groups()
this.$store.commit('setGroups', groups)
}
},
methods: {
async saveService() {
let s = this.service
this.loading = true
delete s.failures
delete s.created_at
delete s.updated_at
delete s.last_success
delete s.latency
delete s.online_24_hours
s.check_interval = parseInt(s.check_interval)
s.timeout = parseInt(s.timeout)
s.port = parseInt(s.port)
s.notify_after = parseInt(s.notify_after)
s.expected_status = parseInt(s.expected_status)
props: {
in_service: {
type: Object
}
},
watch: {
in_service () {
this.service = this.in_service
}
},
async mounted () {
if (!this.$store.getters.groups) {
const groups = await Api.groups()
this.$store.commit('setGroups', groups)
}
},
methods: {
async saveService () {
let s = this.service
this.loading = true
delete s.failures
delete s.created_at
delete s.updated_at
delete s.last_success
delete s.latency
delete s.online_24_hours
s.check_interval = parseInt(s.check_interval)
s.timeout = parseInt(s.timeout)
s.port = parseInt(s.port)
s.notify_after = parseInt(s.notify_after)
s.expected_status = parseInt(s.expected_status)
s.order = parseInt(s.order)
window.console.log(s)
if (s.id) {
await this.updateService(s)
} else {
await this.createService(s)
}
const services = await Api.services()
this.$store.commit('setServices', services)
this.loading = false
this.$router.push('/dashboard/services')
},
async createService(s) {
await Api.service_create(s)
},
async updateService(s) {
await Api.service_update(s)
if (s.id) {
await this.updateService(s)
} else {
await this.createService(s)
}
const services = await Api.services()
this.$store.commit('setServices', services)
this.loading = false
this.$router.push('/dashboard/services')
},
async createService (s) {
await Api.service_create(s)
},
async updateService (s) {
await Api.service_update(s)
}
}
}
}
</script>
<!-- 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/jinzhu/gorm v1.9.12
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/prometheus/common v0.9.1
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")
r.Handle("/checkin/{api}", http.HandlerFunc(checkinHitHandler))
//r.PathPrefix("/").Handler(http.HandlerFunc(indexHandler))
//r.Handle("/badge", http.HandlerFunc(badgeHandler)).Methods("GET")
// Static Files Routes
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())))

View File

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

View File

@ -41,7 +41,9 @@ func processSetupHandler(w http.ResponseWriter, r *http.Request) {
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")
@ -94,11 +96,11 @@ func processSetupHandler(w http.ResponseWriter, r *http.Request) {
notifiers.InitNotifiers()
c := &core.Core{
Name: "Statping Sample Data",
Description: "This data is only used to testing",
Name: project,
Description: description,
//ApiKey: apiKey.(string),
//ApiSecret: apiSecret.(string),
Domain: "http://localhost:8080",
Domain: domain,
Version: core.App.Version,
Started: 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")
maxOpenConn := utils.Getenv("MAX_OPEN_CONN", 5)
maxIdleConn := utils.Getenv("MAX_IDLE_CONN", 5)
maxLifeConn := utils.Getenv("MAX_LIFE_CONN", 2*time.Minute)
maxOpenConn := utils.Getenv("MAX_OPEN_CONN", 25)
maxIdleConn := utils.Getenv("MAX_IDLE_CONN", 25)
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().SetConnMaxLifetime(maxLifeConn.(time.Duration))

View File

@ -4,7 +4,7 @@ import (
"fmt"
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "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/types/notifications"
"github.com/statping/statping/utils"

View File

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

View File

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