From 982ef5f1a090ddf3e33daa0fa201c67f837cf509 Mon Sep 17 00:00:00 2001 From: steden <1470804@qq.com> Date: Wed, 21 Dec 2022 00:39:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++++++++ .github/workflows/go.yml | 31 +++++++++++++++++++ test/publishEvent_test.go | 37 +++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/workflows/go.yml create mode 100644 test/publishEvent_test.go diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -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. diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..2b03345 --- /dev/null +++ b/.github/workflows/go.yml @@ -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 ./... diff --git a/test/publishEvent_test.go b/test/publishEvent_test.go new file mode 100644 index 0000000..8c517b5 --- /dev/null +++ b/test/publishEvent_test.go @@ -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) +}