Skip to content

Commit b14b523

Browse files
committed
chore: init testing
Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 54149fe commit b14b523

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

.github/workflows/go.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
test:
13+
strategy:
14+
matrix:
15+
os: [ubuntu-latest, macos-latest]
16+
go: [1.13, 1.14, 1.15, 1.16]
17+
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
18+
runs-on: ${{ matrix.os }}
19+
env:
20+
GO111MODULE: on
21+
TESTTAGS: ${{ matrix.test-tags }}
22+
GOPROXY: https://proxy.golang.org
23+
steps:
24+
- name: Set up Go ${{ matrix.go }}
25+
uses: actions/setup-go@v2
26+
with:
27+
go-version: ${{ matrix.go }}
28+
29+
- name: Checkout Code
30+
uses: actions/checkout@v2
31+
with:
32+
ref: ${{ github.ref }}
33+
34+
- name: golangci-lint
35+
uses: golangci/golangci-lint-action@v2
36+
37+
- name: Run Tests
38+
run: |
39+
go test -v -covermode=atomic -coverprofile=coverage.out
40+
41+
- name: Upload coverage to Codecov
42+
uses: codecov/codecov-action@v1

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module github/appleboy/queue
22

33
go 1.16
4+
5+
require github.com/stretchr/testify v1.7.0

go.sum

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
6+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
7+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
9+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
10+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
11+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

queue_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
11
package queue
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestNewQueue(t *testing.T) {
10+
q, err := NewQueue()
11+
assert.Error(t, err)
12+
assert.Nil(t, q)
13+
14+
w := &emptyWorker{}
15+
q, err = NewQueue(
16+
WithWorker(w),
17+
)
18+
assert.NoError(t, err)
19+
assert.NotNil(t, q)
20+
}

worker.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ type Worker interface {
1616
type QueuedMessage interface {
1717
Bytes() []byte
1818
}
19+
20+
var _ Worker = (*emptyWorker)(nil)
21+
22+
type emptyWorker struct{}
23+
24+
func (w *emptyWorker) BeforeRun() error { return nil }
25+
func (w *emptyWorker) AfterRun() error { return nil }
26+
func (w *emptyWorker) Run(chan struct{}) error { return nil }
27+
func (w *emptyWorker) Shutdown() error { return nil }
28+
func (w *emptyWorker) Queue(job QueuedMessage) error { return nil }
29+
func (w *emptyWorker) Capacity() int { return 0 }
30+
func (w *emptyWorker) Usage() int { return 0 }

0 commit comments

Comments
 (0)