Cleanup testing procedures

- remove "unit" build flag
 - make sure tests without build flag (integration, external) run
   without deps
 - move unit-tests step in front of "docker image build" drone pipeline
This commit is contained in:
Denis Arh
2019-05-14 14:51:57 +02:00
parent e50d016a38
commit c15eb72b06
19 changed files with 70 additions and 89 deletions
+16 -37
View File
@@ -6,23 +6,20 @@ kind: pipeline
name: docker image build
steps:
#- name: build
# image: crusttech/crust-builder:latest
# pull: always
# environment:
# CGO_ENABLED: 0
# GOOS: linux
# GOARCH: amd64
# commands:
# - go build -ldflags "-X github.com/crusttech/crust/internal/version.BuildTime=`date +%FT%T%z` -X github.com/crusttech/crust/internal/version.Version=`git describe --always --tags`" -o build/crust-$GOOS-$GOARCH cmd/crust/*.go
# - go build -ldflags "-X github.com/crusttech/crust/internal/version.BuildTime=`date +%FT%T%z` -X github.com/crusttech/crust/internal/version.Version=`git describe --always --tags`" -o build/compose-$GOOS-$GOARCH cmd/compose/*.go
# - go build -ldflags "-X github.com/crusttech/crust/internal/version.BuildTime=`date +%FT%T%z` -X github.com/crusttech/crust/internal/version.Version=`git describe --always --tags`" -o build/messaging-$GOOS-$GOARCH cmd/messaging/*.go
# - go build -ldflags "-X github.com/crusttech/crust/internal/version.BuildTime=`date +%FT%T%z` -X github.com/crusttech/crust/internal/version.Version=`git describe --always --tags`" -o build/system-$GOOS-$GOARCH cmd/system/*.go
# - go build -ldflags "-X github.com/crusttech/crust/internal/version.BuildTime=`date +%FT%T%z` -X github.com/crusttech/crust/internal/version.Version=`git describe --always --tags`" -o build/system-cli-$GOOS-$GOARCH cmd/system-cli/*.go
- name: unit-tests
image: crusttech/crust-builder:latest
pull: always
environment:
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
CI: circleci
commands:
- make test
- name: api-system
image: plugins/docker
depends_on: [ clone ]
depends_on: [ 'unit-tests' ]
settings:
repo: crusttech/api-system
auto_tag: true # generate tag names automatically based on git branch and git tag
@@ -35,7 +32,7 @@ steps:
- name: api-compose
image: plugins/docker
depends_on: [ clone ]
depends_on: [ 'unit-tests' ]
settings:
repo: crusttech/api-compose
auto_tag: true # generate tag names automatically based on git branch and git tag
@@ -46,7 +43,7 @@ steps:
from_secret: docker_hub_password
- name: api-messaging
depends_on: [ clone ]
depends_on: [ 'unit-tests' ]
image: plugins/docker
settings:
repo: crusttech/api-messaging
@@ -60,7 +57,7 @@ steps:
- name: crust
image: plugins/docker
depends_on: [ clone ]
depends_on: [ 'unit-tests' ]
settings:
repo: crusttech/crust
auto_tag: true # generate tag names automatically based on git branch and git tag
@@ -102,15 +99,12 @@ steps:
COMPOSE_DB_DSN: crust:crust@tcp(crust-db:3306)/crust?collation=utf8mb4_general_ci
MESSAGING_DB_DSN: crust:crust@tcp(crust-db:3306)/crust?collation=utf8mb4_general_ci
commands:
# Run tests without any dependencies
- go test ./cmd/... ./internal/... ./compose/... ./messaging/... ./system/...
# Wait for the db before running other tests
- wait-for-it.sh -t 60 --strict crust-db:3306 -- echo "Crust DB1 is up"
- gotest -v --tags="migrations" ./system/db/...
- gotest -v --tags="migrations" ./compose/db/...
- gotest -v --tags="migrations" ./messaging/db/...
- go test -run=^$ --tags="unit integration external" ./cmd/... ./internal/... ./compose/... ./messaging/... ./system/...
- gotest -failfast --coverprofile=coverage.txt -v --tags="unit integration" ./internal/... ./system/... ./compose/... ./messaging/...
- go test -run=^$ --tags="integration external" ./cmd/... ./internal/... ./compose/... ./messaging/... ./system/...
- gotest -failfast --coverprofile=coverage.txt -v --tags="integration" ./internal/... ./system/... ./compose/... ./messaging/...
- name: coverage
image: plugins/codecov
@@ -119,21 +113,6 @@ steps:
files:
- coverage.txt
- name: build
image: crusttech/crust-builder:latest
pull: always
environment:
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
commands:
- go build -ldflags "-X github.com/crusttech/crust/internal/version.BuildTime=`date +%FT%T%z` -X github.com/crusttech/crust/internal/version.Version=`git describe --always --tags`" -o build/crust-$GOOS-$GOARCH cmd/crust/*.go
- go build -ldflags "-X github.com/crusttech/crust/internal/version.BuildTime=`date +%FT%T%z` -X github.com/crusttech/crust/internal/version.Version=`git describe --always --tags`" -o build/compose-$GOOS-$GOARCH cmd/compose/*.go
- go build -ldflags "-X github.com/crusttech/crust/internal/version.BuildTime=`date +%FT%T%z` -X github.com/crusttech/crust/internal/version.Version=`git describe --always --tags`" -o build/messaging-$GOOS-$GOARCH cmd/messaging/*.go
- go build -ldflags "-X github.com/crusttech/crust/internal/version.BuildTime=`date +%FT%T%z` -X github.com/crusttech/crust/internal/version.Version=`git describe --always --tags`" -o build/system-$GOOS-$GOARCH cmd/system/*.go
- go build -ldflags "-X github.com/crusttech/crust/internal/version.BuildTime=`date +%FT%T%z` -X github.com/crusttech/crust/internal/version.Version=`git describe --always --tags`" -o build/system-cli-$GOOS-$GOARCH cmd/system-cli/*.go
services:
- name: crust-db
pull: always
+10 -5
View File
@@ -64,6 +64,10 @@ mailhog.up:
########################################################################################################################
# QA
test:
# Run basic unit tests
$(GO) test ./cmd/... ./internal/... ./compose/... ./messaging/... ./system/...
test.internal: $(GOTEST)
$(GOTEST) -covermode count -coverprofile .cover.out -v ./internal/...
$(GO) tool cover -func=.cover.out
@@ -104,6 +108,12 @@ test.cross-dep:
grep -rE "crust/(system|messaging)/" compose || exit 0
grep -rE "crust/(system|compose)/" messaging || exit 0
integration:
# Run drone's integration pipeline
rm -f build/gen*
drone exec --pipeline integration
vet:
$(GO) vet ./...
@@ -145,8 +155,3 @@ $(MOCKGEN):
clean:
rm -f $(REALIZE) $(GOCRITIC) $(GOTEST)
integration:
rm -f build/gen*
drone exec --pipeline integration
+1 -1
View File
@@ -1,4 +1,4 @@
// +build unit integration
// +build integration
package repository
@@ -1,5 +1,3 @@
// +build unit
package ql
import (
@@ -1,5 +1,3 @@
// +build unit
package ql
import (
@@ -1,5 +1,3 @@
// +build unit
package repository
import (
@@ -1,5 +1,3 @@
// +build unit
package repository
/*
@@ -1,4 +1,4 @@
// +build unit integration
// +build integration
package repository
-2
View File
@@ -1,5 +1,3 @@
// +build unit
package mail
import (
-2
View File
@@ -1,5 +1,3 @@
// +build unit
package store
import (
@@ -1,5 +1,3 @@
// +build unit
package repository
import (
@@ -1,5 +1,3 @@
// +build unit
package repository
import (
@@ -1,4 +1,4 @@
// +build unit integration
// +build integration
package repository
+24 -12
View File
@@ -208,6 +208,18 @@ func (svc *channel) FindMembers(channelID uint64) (out types.ChannelMemberSet, e
}
func (svc *channel) Create(in *types.Channel) (out *types.Channel, err error) {
if len(in.Name) == 0 && in.Type != types.ChannelTypeGroup {
return nil, errors.New("channel name not provided")
}
if settingsChannelNameLength > 0 && len(in.Name) > settingsChannelNameLength {
return nil, errors.Errorf("channel name (%d characters) too long (max: %d)", len(in.Name), settingsChannelNameLength)
}
if len(in.Topic) > 0 && settingsChannelTopicLength > 0 && len(in.Topic) > settingsChannelTopicLength {
return nil, errors.Errorf("channel topic (%d characters) too long (max: %d)", len(in.Topic), settingsChannelTopicLength)
}
return out, svc.db.Transaction(func() (err error) {
var msg *types.Message
@@ -240,18 +252,6 @@ func (svc *channel) Create(in *types.Channel) (out *types.Channel, err error) {
return errors.WithStack(ErrNoPermissions)
}
if len(in.Name) == 0 && in.Type != types.ChannelTypeGroup {
return errors.New("channel name not provided")
}
if settingsChannelNameLength > 0 && len(in.Name) > settingsChannelNameLength {
return errors.Errorf("channel name (%d characters) too long (max: %d)", len(in.Name), settingsChannelNameLength)
}
if len(in.Topic) > 0 && settingsChannelTopicLength > 0 && len(in.Topic) > settingsChannelTopicLength {
return errors.Errorf("channel topic (%d characters) too long (max: %d)", len(in.Topic), settingsChannelTopicLength)
}
// This is a fresh channel, just copy values
out = &types.Channel{
Name: in.Name,
@@ -340,6 +340,18 @@ func (svc *channel) checkGroupExistance(mm types.ChannelMemberSet) (out *types.C
}
func (svc *channel) Update(in *types.Channel) (ch *types.Channel, err error) {
if len(in.Name) == 0 && in.Type != types.ChannelTypeGroup {
return nil, errors.New("channel name not provided")
}
if settingsChannelNameLength > 0 && len(in.Name) > settingsChannelNameLength {
return nil, errors.Errorf("channel name (%d characters) too long (max: %d)", len(in.Name), settingsChannelNameLength)
}
if len(in.Topic) > 0 && settingsChannelTopicLength > 0 && len(in.Topic) > settingsChannelTopicLength {
return nil, errors.Errorf("channel topic (%d characters) too long (max: %d)", len(in.Topic), settingsChannelTopicLength)
}
return ch, svc.db.Transaction(func() (err error) {
var changed bool
+6 -6
View File
@@ -1,5 +1,3 @@
// +build unit
package service
import (
@@ -17,11 +15,13 @@ func TestChannelNameTooShort(t *testing.T) {
ctx := context.Background()
ctx = auth.SetIdentityToContext(ctx, &systemTypes.User{})
svc := channel{db: &mockDB{}, ctx: ctx}
svc := channel{}
e := func(out *types.Channel, err error) error { return err }
longName := strings.Repeat("X", settingsChannelNameLength+1)
test.Assert(t, e(svc.Create(&types.Channel{})) != nil, "Should not allow to create unnamed channels")
test.Assert(t, e(svc.Create(&types.Channel{Name: longName})) != nil, "Should not allow to create channel with really long name")
if settingsChannelNameLength > 0 {
longName := strings.Repeat("X", settingsChannelNameLength+1)
test.Assert(t, e(svc.Create(&types.Channel{Name: longName})) != nil, "Should not allow to create channel with really long name")
}
}
+4 -1
View File
@@ -197,11 +197,14 @@ func (svc message) Create(in *types.Message) (message *types.Message, err error)
}
in.Message = strings.TrimSpace(in.Message)
var mlen = len(in.Message)
if mlen == 0 {
return nil, errors.Errorf("refusing to create message without contents")
} else if settingsMessageBodyLength > 0 && mlen > settingsMessageBodyLength {
}
if settingsMessageBodyLength > 0 && mlen > settingsMessageBodyLength {
return nil, errors.Errorf("message length (%d characters) too long (max: %d)", mlen, settingsMessageBodyLength)
}
+6 -6
View File
@@ -1,5 +1,3 @@
// +build unit
package service
import (
@@ -17,13 +15,15 @@ func TestMessageLength(t *testing.T) {
ctx := context.Background()
ctx = auth.SetIdentityToContext(ctx, &systemTypes.User{})
svc := message{db: &mockDB{}, ctx: ctx}
svc := message{}
e := func(out *types.Message, err error) error { return err }
longText := strings.Repeat("X", settingsMessageBodyLength+1)
test.Assert(t, e(svc.Create(&types.Message{})) != nil, "Should not allow to create empty message")
test.Assert(t, e(svc.Create(&types.Message{Message: longText})) != nil, "Should not allow to create message with really long text")
if settingsMessageBodyLength > 0 {
longText := strings.Repeat("X", settingsMessageBodyLength+1)
test.Assert(t, e(svc.Create(&types.Message{Message: longText})) != nil, "Should not allow to create message with really long text")
}
}
func TestMentionsExtraction(t *testing.T) {
-2
View File
@@ -1,5 +1,3 @@
// +build unit
package types
import (
@@ -1,4 +1,4 @@
// +build unit integration
// +build integration
package repository