Skip to content

Commit b5b88d8

Browse files
authored
fix: add testsssss (#6)
1 parent a9c6351 commit b5b88d8

29 files changed

+1369
-104
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: Unit Testing
22

33
on:
44
push:
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Integration Testing
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
10+
jobs:
11+
build:
12+
name: Build and test
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
go-version: ["oldstable", "stable"]
17+
env:
18+
VERBOSE: 1
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
- uses: getong/[email protected]
24+
with:
25+
rabbitmq version: "3.13.3-management-alpine"
26+
host port: 5672
27+
rabbitmq user: "test"
28+
rabbitmq password: "test"
29+
rabbitmq vhost: "test"
30+
- name: Set up Go
31+
uses: actions/setup-go@v5
32+
with:
33+
go-version: ${{ matrix.go-version }}
34+
- name: Run tests
35+
run: make integration-test-ci

Makefile

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,37 @@ TESTS_ARGS += -test.count 1
2626
TESTS_ARGS += -test.failfast
2727
TESTS_ARGS += -test.coverprofile coverage.out
2828
TESTS_ARGS += -test.timeout 60s
29-
TESTS_ARGS += -race
29+
TESTS_ARGS_WITHRACE := $(TESTS_ARGS)
30+
TESTS_ARGS_WITHRACE += -race
31+
3032
run-tests: $(GOTESTSUM)
31-
@ gotestsum $(TESTS_ARGS) -short
33+
@gotestsum $(TESTS_ARGS_WITHRACE) -short
3234

3335
test: run-tests $(TPARSE) ## Run Tests & parse details
3436
@cat gotestsum.json.out | $(TPARSE) -all -notests
37+
docker-test:
38+
@docker-compose -f test.compose.yaml up -d --build
39+
40+
integration-test: docker-test
41+
@echo "Running Integration Tests"
42+
@gotestsum $(TESTS_ARGS)
43+
@cat gotestsum.json.out | $(TPARSE) -all -notests
3544

45+
integration-test-ci: $(GOTESTSUM) $(TPARSE)
46+
@echo "Running Integration Tests"
47+
@gotestsum $(TESTS_ARGS)
48+
@cat gotestsum.json.out | $(TPARSE) -all -notests
49+
50+
docker-clean:
51+
@docker-compose -f test.compose.yaml down
3652

3753
lint: $(GOLANGCI) ## Runs golangci-lint with predefined configuration
3854
@echo "Applying linter"
3955
golangci-lint version
4056
golangci-lint run -c .golangci.yaml ./...
4157

42-
.PHONY: lint lint-prepare clean build unittest
58+
.PHONY: lint lint-prepare clean build unittest
59+
60+
61+
go-generate: $(MOCKERY) ## Runs go generte ./...
62+
go generate ./...

consumer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package goqueue
33
import "context"
44

55
// Consumer represents an entity that consumes messages from a queue.
6+
//
7+
//go:generate mockery --name Consumer
68
type Consumer interface {
79
// Consume consumes messages from the queue and passes them to the provided handler.
810
// It takes a context, an InboundMessageHandler, and a map of metadata as parameters.
@@ -14,6 +16,7 @@ type Consumer interface {
1416
Stop(ctx context.Context) (err error)
1517
}
1618

19+
//go:generate mockery --name InboundMessageHandler
1720
type InboundMessageHandler interface {
1821
HandleMessage(ctx context.Context, m InboundMessage) (err error)
1922
}
@@ -39,5 +42,5 @@ type InboundMessage struct {
3942
// eg RabbitMQ: https://www.rabbitmq.com/docs/dlx
4043
MoveToDeadLetterQueue func(ctx context.Context) (err error) `json:"-"`
4144
// Requeue is used to put the message back to the tail of the queue after a delay.
42-
Requeue func(ctx context.Context, delayFn DelayFn) (err error) `json:"-"`
45+
PutToBackOfQueueWithDelay func(ctx context.Context, delayFn DelayFn) (err error) `json:"-"`
4346
}

consumer/option.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@ package consumer
22

33
import "github.com/bxcodec/goqueue"
44

5+
const (
6+
DefaultMaxRetryFailedMessage = 3
7+
DefaultBatchMessageSize = 1
8+
)
9+
510
// Option represents the configuration options for the consumer.
611
type Option struct {
712
// BatchMessageSize specifies the maximum number of messages to be processed in a single batch.
813
BatchMessageSize int
914
// QueueName specifies the name of the queue to consume messages from.
1015
QueueName string
1116
// Middlewares is a list of middleware functions to be applied to the inbound message handler.
12-
Middlewares []goqueue.InboundMessageHandlerMiddlewareFunc
17+
Middlewares []goqueue.InboundMessageHandlerMiddlewareFunc
18+
ActionsPatternSubscribed []string
19+
TopicName string
20+
MaxRetryFailedMessage int64
1321
}
1422

1523
// OptionFunc is a function type that takes an `opt` parameter of type `*Option`.
@@ -40,3 +48,28 @@ func WithMiddlewares(middlewares ...goqueue.InboundMessageHandlerMiddlewareFunc)
4048
opt.Middlewares = middlewares
4149
}
4250
}
51+
52+
// WithActionsPatternSubscribed sets the actions that the consumer will subscribe to.
53+
// It takes a variadic parameter `actions` which represents the actions to be subscribed.
54+
// The actions are stored in the `ActionsPatternSubscribed` field of the `Option` struct.
55+
func WithActionsPatternSubscribed(actions ...string) OptionFunc {
56+
return func(opt *Option) {
57+
opt.ActionsPatternSubscribed = actions
58+
}
59+
}
60+
61+
// WithTopicName sets the topic name for the consumer option.
62+
func WithTopicName(name string) OptionFunc {
63+
return func(opt *Option) {
64+
opt.TopicName = name
65+
}
66+
}
67+
68+
// WithMaxRetryFailedMessage sets the maximum number of retries for failed messages.
69+
// It takes an integer parameter 'n' and returns an OptionFunc.
70+
// The OptionFunc updates the 'MaxRetryFailedMessage' field of the Option struct.
71+
func WithMaxRetryFailedMessage(n int64) OptionFunc {
72+
return func(opt *Option) {
73+
opt.MaxRetryFailedMessage = n
74+
}
75+
}

0 commit comments

Comments
 (0)