Skip to content

Commit

Permalink
WIP: moved tests to separated directory (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
roblaszczak authored Aug 7, 2019
1 parent 95161a2 commit 577f2ac
Show file tree
Hide file tree
Showing 22 changed files with 46 additions and 36 deletions.
1 change: 1 addition & 0 deletions UPGRADE-1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
Migrating Pub/Subs

find . -type f -iname '*.go' -exec sed -i -E "s/github\.com\/ThreeDotsLabs\/watermill\/message\/infrastructure\/(amqp|googlecloud|http|io|kafka|nats|sql)/github.com\/ThreeDotsLabs\/watermill-\1\/pkg\/\1/" "{}" +;
find . -type f -iname '*.go' -exec sed -i -E "s/github\.com\/ThreeDotsLabs\/watermill\/message\/infrastructure\/gochannel/github\.com\/ThreeDotsLabs\/watermill\/pubsub\/gochannel/" "{}" +;
2 changes: 1 addition & 1 deletion _examples/metrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/components/metrics"
"github.com/ThreeDotsLabs/watermill/message"
"github.com/ThreeDotsLabs/watermill/message/infrastructure/gochannel"
"github.com/ThreeDotsLabs/watermill/message/router/middleware"
"github.com/ThreeDotsLabs/watermill/message/router/plugin"
"github.com/ThreeDotsLabs/watermill/pubsub/gochannel"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion components/cqrs/cqrs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/components/cqrs"
"github.com/ThreeDotsLabs/watermill/message"
"github.com/ThreeDotsLabs/watermill/message/infrastructure/gochannel"
"github.com/ThreeDotsLabs/watermill/pubsub/gochannel"
)

// TestCQRS is functional test of CQRS command handler and event handler.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/docs/getting-started/go-channel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ThreeDotsLabs/watermill/message"

"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/message/infrastructure/gochannel"
"github.com/ThreeDotsLabs/watermill/pubsub/gochannel"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion docs/content/docs/getting-started/router/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/message"
"github.com/ThreeDotsLabs/watermill/message/infrastructure/gochannel"
"github.com/ThreeDotsLabs/watermill/message/router/middleware"
"github.com/ThreeDotsLabs/watermill/message/router/plugin"
"github.com/ThreeDotsLabs/watermill/pubsub/gochannel"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion docs/content/docs/pub-sub.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Every Pub/Sub is similar in most aspects.
To avoid implementing separate tests for every Pub/Sub, we've created a test suite which should be passed by any Pub/Sub
implementation.

These tests can be found in `message/infrastructure/test_pubsub.go`.
These tests can be found in `pubsub/tests/test_pubsub.go`.

### Built-in implementations

Expand Down
6 changes: 3 additions & 3 deletions message/decorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
"testing"
"time"

"github.com/ThreeDotsLabs/watermill/message/infrastructure"
"github.com/ThreeDotsLabs/watermill/pubsub/tests"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/message"
"github.com/ThreeDotsLabs/watermill/message/infrastructure/gochannel"
"github.com/ThreeDotsLabs/watermill/message/subscriber"
"github.com/ThreeDotsLabs/watermill/pubsub/gochannel"
)

var noop = func(*message.Message) {}
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestMessageTransformSubscriberDecorator_Subscribe(t *testing.T) {

received, all := subscriber.BulkRead(messages, numMessages, time.Second)
require.True(t, all)
infrastructure.AssertAllMessagesReceived(t, sent, received)
tests.AssertAllMessagesReceived(t, sent, received)

for _, msg := range received {
assert.Equal(
Expand Down
2 changes: 1 addition & 1 deletion message/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/internal"
sync_internal "github.com/ThreeDotsLabs/watermill/message/infrastructure/sync"
sync_internal "github.com/ThreeDotsLabs/watermill/pubsub/sync"
)

var (
Expand Down
12 changes: 6 additions & 6 deletions message/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
"testing"
"time"

"github.com/ThreeDotsLabs/watermill/message/infrastructure"
"github.com/ThreeDotsLabs/watermill/pubsub/tests"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/internal"
"github.com/ThreeDotsLabs/watermill/message"
"github.com/ThreeDotsLabs/watermill/message/infrastructure/gochannel"
"github.com/ThreeDotsLabs/watermill/message/subscriber"
"github.com/ThreeDotsLabs/watermill/pubsub/gochannel"
)

func TestRouter_functional(t *testing.T) {
Expand Down Expand Up @@ -105,14 +105,14 @@ func TestRouter_functional(t *testing.T) {

receivedMessages1, all := subscriber.BulkRead(receivedMessagesCh1, len(expectedReceivedMessages), time.Second*10)
assert.True(t, all)
infrastructure.AssertAllMessagesReceived(t, expectedReceivedMessages, receivedMessages1)
tests.AssertAllMessagesReceived(t, expectedReceivedMessages, receivedMessages1)

receivedMessages2, all := subscriber.BulkRead(receivedMessagesCh2, len(expectedReceivedMessages), time.Second*10)
assert.True(t, all)
infrastructure.AssertAllMessagesReceived(t, expectedReceivedMessages, receivedMessages2)
tests.AssertAllMessagesReceived(t, expectedReceivedMessages, receivedMessages2)

<-allPublishedByHandler
infrastructure.AssertAllMessagesReceived(t, expectedSentByHandler, publishedByHandler)
tests.AssertAllMessagesReceived(t, expectedSentByHandler, publishedByHandler)
}

func TestRouter_functional_nack(t *testing.T) {
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestRouter_functional_nack(t *testing.T) {
messages, all := subscriber.BulkRead(messageReceived, 2, time.Second)
assert.True(t, all, "not all messages received, probably not ack received, received %d", len(messages))

infrastructure.AssertAllMessagesReceived(t, []*message.Message{publishedMsg, publishedMsg}, messages)
tests.AssertAllMessagesReceived(t, []*message.Message{publishedMsg, publishedMsg}, messages)
}

func TestRouter_stop_when_all_handlers_stopped(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions message/subscriber/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/ThreeDotsLabs/watermill/message/infrastructure"
"github.com/ThreeDotsLabs/watermill/pubsub/tests"

"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/message"
Expand Down Expand Up @@ -46,7 +46,7 @@ func TestBulkRead(t *testing.T) {
readMessages, all := subscriber.BulkRead(messagesCh, messagesCount, time.Second)
assert.True(t, all)

infrastructure.AssertAllMessagesReceived(t, messages, readMessages)
tests.AssertAllMessagesReceived(t, messages, readMessages)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion message/infrastructure/doc.go → pubsub/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
// Detailed Pub/Subs docs: https://watermill.io/docs/pub-sub-implementations/
// Getting started guide: https://watermill.io/docs/getting-started/

package infrastructure
package pubsub
5 changes: 5 additions & 0 deletions pubsub/gochannel/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This is just the simplest Pub/Sub implementation
//
// All Pub/Sub implementations can be found at https://watermill.io/docs/pub-sub-implementations/

package gochannel
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package gochannel_test
import (
"testing"

"github.com/ThreeDotsLabs/watermill/pubsub/gochannel"

"github.com/ThreeDotsLabs/watermill/pubsub/tests"

"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/message"
"github.com/ThreeDotsLabs/watermill/message/infrastructure"
"github.com/ThreeDotsLabs/watermill/message/infrastructure/gochannel"
)

func BenchmarkSubscriber(b *testing.B) {
infrastructure.BenchSubscriber(b, func(n int) (message.Publisher, message.Subscriber) {
tests.BenchSubscriber(b, func(n int) (message.Publisher, message.Subscriber) {
pubSub := gochannel.NewGoChannel(
gochannel.Config{OutputChannelBuffer: int64(n)}, watermill.NopLogger{},
)
Expand All @@ -19,7 +21,7 @@ func BenchmarkSubscriber(b *testing.B) {
}

func BenchmarkSubscriberPersistent(b *testing.B) {
infrastructure.BenchSubscriber(b, func(n int) (message.Publisher, message.Subscriber) {
tests.BenchSubscriber(b, func(n int) (message.Publisher, message.Subscriber) {
pubSub := gochannel.NewGoChannel(
gochannel.Config{
OutputChannelBuffer: int64(n),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ package gochannel_test
import (
"testing"

"github.com/ThreeDotsLabs/watermill/message/infrastructure"
"github.com/ThreeDotsLabs/watermill/pubsub/tests"
)

func TestPublishSubscribe_stress(t *testing.T) {
infrastructure.TestPubSubStressTest(
tests.TestPubSubStressTest(
t,
infrastructure.Features{
tests.Features{
ConsumerGroups: false,
ExactlyOnceDelivery: true,
GuaranteedOrder: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (
"testing"
"time"

"github.com/ThreeDotsLabs/watermill/pubsub/tests"

"github.com/ThreeDotsLabs/watermill/pubsub/gochannel"

"github.com/stretchr/testify/assert"

"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/message"
"github.com/ThreeDotsLabs/watermill/message/infrastructure"
"github.com/ThreeDotsLabs/watermill/message/infrastructure/gochannel"
"github.com/ThreeDotsLabs/watermill/message/subscriber"
"github.com/stretchr/testify/require"
)
Expand All @@ -30,9 +32,9 @@ func createPersistentPubSub(t *testing.T) (message.Publisher, message.Subscriber
}

func TestPublishSubscribe_persistent(t *testing.T) {
infrastructure.TestPubSub(
tests.TestPubSub(
t,
infrastructure.Features{
tests.Features{
ConsumerGroups: false,
ExactlyOnceDelivery: true,
GuaranteedOrder: false,
Expand All @@ -55,10 +57,10 @@ func TestPublishSubscribe_not_persistent(t *testing.T) {
msgs, err := pubSub.Subscribe(context.Background(), topicName)
require.NoError(t, err)

sendMessages := infrastructure.PublishSimpleMessages(t, messagesCount, pubSub, topicName)
sendMessages := tests.PublishSimpleMessages(t, messagesCount, pubSub, topicName)
receivedMsgs, _ := subscriber.BulkRead(msgs, messagesCount, time.Second)

infrastructure.AssertAllMessagesReceived(t, sendMessages, receivedMsgs)
tests.AssertAllMessagesReceived(t, sendMessages, receivedMsgs)

assert.NoError(t, pubSub.Close())
}
Expand Down Expand Up @@ -182,6 +184,6 @@ func testPublishSubscribeSubRace(t *testing.T) {
log.Println("asserting")

for subMsgs := range subscriberReceivedCh {
infrastructure.AssertAllMessagesReceived(t, sentMessages, subMsgs)
tests.AssertAllMessagesReceived(t, sentMessages, subMsgs)
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package infrastructure
package tests

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package infrastructure
package tests

import (
"sort"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package infrastructure
package tests

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build stress

package infrastructure
package tests

func init() {
// stress tests may work a bit slower
Expand Down

0 comments on commit 577f2ac

Please sign in to comment.