diff --git a/.travis.yml b/.travis.yml index 566d1c53..6ef1c5b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/types/groups/groups_test.go b/types/groups/groups_test.go index e881259c..dfdc0436 100644 --- a/types/groups/groups_test.go +++ b/types/groups/groups_test.go @@ -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) { diff --git a/types/groups/methods.go b/types/groups/methods.go deleted file mode 100644 index 1052c339..00000000 --- a/types/groups/methods.go +++ /dev/null @@ -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 } diff --git a/types/groups/struct.go b/types/groups/struct.go index 7c0573b7..c99febd0 100644 --- a/types/groups/struct.go +++ b/types/groups/struct.go @@ -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 }