迁移单元测试

This commit is contained in:
steden
2022-12-21 00:39:08 +08:00
parent 9e4d878ad6
commit 982ef5f1a0
3 changed files with 88 additions and 0 deletions

View 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
View 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
View 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)
}