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