mirror of
https://github.com/farseer-go/eventBus.git
synced 2025-12-24 13:37:51 +08:00
迁移单元测试
This commit is contained in:
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
31
.github/workflows/go.yml
vendored
Normal file
31
.github/workflows/go.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
# This workflow will build a golang project
|
||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
|
||||
|
||||
name: Go
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.19
|
||||
|
||||
- name: Go Mod Tidy
|
||||
run: go mod tidy
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
|
||||
- name: Test
|
||||
run: go test -v ./...
|
||||
37
test/publishEvent_test.go
Normal file
37
test/publishEvent_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"github.com/farseer-go/eventBus"
|
||||
"github.com/farseer-go/fs"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var count int
|
||||
|
||||
type testEventPublish struct {
|
||||
count int
|
||||
}
|
||||
|
||||
func TestPublishEvent(t *testing.T) {
|
||||
fs.Initialize[eventBus.Module]("unit test")
|
||||
|
||||
eventBus.Subscribe("test_event_subscribe", func(message any, ea eventBus.EventArgs) {
|
||||
event := message.(testEventPublish)
|
||||
count += event.count + 1
|
||||
})
|
||||
|
||||
eventBus.Subscribe("test_event_subscribe", func(message any, ea eventBus.EventArgs) {
|
||||
event := message.(testEventPublish)
|
||||
count += event.count + 2
|
||||
})
|
||||
|
||||
eventBus.PublishEvent("test_event_subscribe", testEventPublish{count: 6})
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
assert.Equal(t, 15, count)
|
||||
|
||||
eventBus.PublishEventAsync("test_event_subscribe", testEventPublish{count: 4})
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
assert.Equal(t, 26, count)
|
||||
}
|
||||
Reference in New Issue
Block a user