pull/443/head
Hunter Long 2020-03-19 04:04:09 -07:00
parent db872ad767
commit 80cf8d7ac3
4 changed files with 70 additions and 63 deletions

View File

@ -1,62 +1,61 @@
os:
- linux
language: go
go: 1.14
go_import_path: github.com/statping/statping
after_success:
- "if [[ \"$TRAVIS_BRANCH\" == \"master\" && \"$TRAVIS_PULL_REQUEST\" = \"false\" ]]; then make travis-build; fi"
before_install:
- "rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install stable"
- "nvm install 10.17.0"
- "nvm use 10.17.0 --default"
before_script:
- "mysql -e 'CREATE DATABASE IF NOT EXISTS test;'"
- "psql -c 'create database test;' -U postgres"
branches:
only:
- master
cache:
directories:
- "~/.npm"
- "~/.cache"
- "$GOPATH/src/github.com/statping/statping/frontend/node_modules"
- "$GOPATH/src/github.com/statping/statping/vendor"
sudo: required
services:
- docker
- postgresql
- mysql
- mongodb
- ~/.npm
- ~/.cache
- $GOPATH/src/github.com/statping/statping/frontend/node_modules
- $GOPATH/src/github.com/statping/statping/vendor
env:
global:
- PATH=$HOME/.local/bin:$PATH
- "PATH=$HOME/.local/bin:$PATH"
- DB_HOST=localhost
- DB_USER=travis
- DB_PASS=
- DB_DATABASE=test
- GO_ENV=test
- STATPING_DIR=$GOPATH/src/github.com/statping/statping
go: 1.14
go_import_path: github.com/statping/statping
install:
- "npm install -g sass"
- "npm install -g newman"
- "npm install -g cross-env"
- "pip install --user awscli"
- "go mod vendor"
- "make test-deps yarn clean compile install"
language: go
matrix:
allow_failures:
- go: master
-
go: master
fast_finish: true
notifications:
email: true
branches:
only:
- master
before_install:
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install stable
- nvm install 10.17.0
- nvm use 10.17.0 --default
install:
- npm install -g sass
- npm install -g newman
- npm install -g cross-env
- pip install --user awscli
- go mod vendor
- make test-deps yarn clean compile install
before_script:
- mysql -e 'CREATE DATABASE IF NOT EXISTS test;'
- psql -c 'create database test;' -U postgres
os:
- linux
script:
- travis_retry make clean test-ci
- if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" = "false" ]]; then
make coverage; fi
after_success:
- if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" = "false" ]]; then
make travis-build; fi
- "travis_retry make clean test-ci"
- "if [[ \"$TRAVIS_BRANCH\" == \"master\" && \"$TRAVIS_PULL_REQUEST\" = \"false\" ]]; then make coverage; fi"
services:
- docker
- postgresql
- mysql
- mongodb
sudo: required
webhooks:
urls:
- "$GITTER"
on_success: change
on_failure: always
on_start: never
on_success: change
urls:
- $GITTER

View File

@ -3,23 +3,42 @@ package groups
import (
"github.com/statping/statping/database"
"github.com/statping/statping/types/null"
"github.com/statping/statping/types/services"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)
var example = &Group{
Id: 1,
Name: "Example Group",
Public: null.NewNullBool(true),
Order: 1,
}
var s1 = &services.Service{
Name: "Example Service",
Public: null.NewNullBool(true),
Order: 1,
GroupId: 1,
}
var s2 = &services.Service{
Name: "Example Service 2",
Public: null.NewNullBool(true),
Order: 2,
GroupId: 1,
}
func TestInit(t *testing.T) {
db, err := database.OpenTester()
require.Nil(t, err)
db.CreateTable(&Group{})
db.CreateTable(&Group{}, &services.Service{})
db.Create(&example)
db.Create(&s1)
db.Create(&s2)
SetDB(db)
services.SetDB(db)
}
func TestFind(t *testing.T) {

View File

@ -1,19 +0,0 @@
package groups
import (
"github.com/statping/statping/types/services"
)
func (g *Group) Services() []*services.Service {
var services []*services.Service
db.Where("group = ?", g.Id).Find(&services)
return services
}
// GroupOrder will reorder the groups based on 'order_id' (Order)
type GroupOrder []*Group
// Sort interface for resorting the Groups in order
func (c GroupOrder) Len() int { return len(c) }
func (c GroupOrder) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
func (c GroupOrder) Less(i, j int) bool { return c[i].Order < c[j].Order }

View File

@ -14,3 +14,11 @@ type Group struct {
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
}
// GroupOrder will reorder the groups based on 'order_id' (Order)
type GroupOrder []*Group
// Sort interface for resorting the Groups in order
func (c GroupOrder) Len() int { return len(c) }
func (c GroupOrder) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
func (c GroupOrder) Less(i, j int) bool { return c[i].Order < c[j].Order }