From 57a21766c7907accf113e5a66d78cc2a4c441497 Mon Sep 17 00:00:00 2001 From: lowit Date: Wed, 25 May 2022 16:49:54 +0300 Subject: [PATCH] issue-37: Remove testify from dependencies closes #37 --- bell_test.go | 75 ++++++++++++++++++++++++++-------------------------- go.mod | 8 ------ go.sum | 11 -------- 3 files changed, 38 insertions(+), 56 deletions(-) diff --git a/bell_test.go b/bell_test.go index da03580..8760599 100644 --- a/bell_test.go +++ b/bell_test.go @@ -1,8 +1,6 @@ package bell import ( - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "sort" "sync/atomic" "testing" @@ -19,100 +17,101 @@ func resetSystem() { globalState = &Events{channels: map[string][]chan Message{}} } +func assertNoError(t *testing.T, err error) { + t.Helper() + if err != nil { + t.Error(err) + } +} + +func assertTrue(t *testing.T, v bool) { + t.Helper() + if v != true { + t.Error("Value must be true") + } +} + // TestListenN checking the function of adding multiple copies of event listeners func TestListenN(t *testing.T) { - resetSystem() defer resetSystem() eventName := "event" var wasRunning int32 ListenN(eventName, func(Message) { atomic.AddInt32(&wasRunning, 1) }, 3) - require.NoError(t, Ring(eventName, nil)) + assertNoError(t, Ring(eventName, nil)) Wait() - assert.Equal(t, int32(1), wasRunning) + assertTrue(t, wasRunning == 1) - require.NoError(t, Ring(eventName, nil)) - require.NoError(t, Ring(eventName, nil)) + assertNoError(t, Ring(eventName, nil)) + assertNoError(t, Ring(eventName, nil)) Wait() - assert.Equal(t, int32(3), wasRunning) + assertTrue(t, wasRunning == 3) } // TestListen Testing the function of adding event listeners func TestListen(t *testing.T) { - resetSystem() defer resetSystem() expMessageEvent := "test_event" expMessageValue := "value" Listen(expMessageEvent, func(message Message) { - assert.Equal(t, expMessageValue, message) + assertTrue(t, expMessageValue == message) }) - assert.Equal(t, 1, len(globalState.channels)) - assert.Equal(t, 1, len(globalState.channels[expMessageEvent])) + assertTrue(t, len(globalState.channels) == 1) + assertTrue(t, len(globalState.channels[expMessageEvent]) == 1) - assert.NotPanics(t, func() { - err := Ring(expMessageEvent, expMessageValue) - assert.NoError(t, err) - }) - - assert.NotPanics(t, func() { - resetSystem() - }) + assertNoError(t, Ring(expMessageEvent, expMessageValue)) } // TestRing_Fail Checking the correctness of error handling in case of an erroneous ringing func TestRing_Fail(t *testing.T) { - resetSystem() defer resetSystem() err := Ring("undefined_event", func() {}) - assert.EqualError(t, err, "channel undefined_event not found") + assertTrue(t, err.Error() == "channel undefined_event not found") } // TestRemove Checking if event handlers are removed from storage func TestRemove(t *testing.T) { - resetSystem() defer resetSystem() globalState.channels["test"] = append(globalState.channels["test"], make(chan Message), make(chan Message)) globalState.channels["test2"] = append(globalState.channels["test2"], make(chan Message)) Remove("test") - assert.Equal(t, 1, len(globalState.channels)) + assertTrue(t, len(globalState.channels) == 1) globalState.channels["test3"] = append(globalState.channels["test3"], make(chan Message)) globalState.channels["test4"] = append(globalState.channels["test4"], make(chan Message)) Remove("test2") - assert.Equal(t, 2, len(globalState.channels)) + assertTrue(t, len(globalState.channels) == 2) globalState.channels["test3"] = append(globalState.channels["test3"], make(chan Message)) globalState.channels["test4"] = append(globalState.channels["test4"], make(chan Message)) Remove() - assert.Equal(t, 0, len(globalState.channels)) + assertTrue(t, len(globalState.channels) == 0) } // TestHas Checking the Correctness of Determining the Existence of Event Listeners func TestHas(t *testing.T) { - resetSystem() defer resetSystem() - assert.False(t, Has("test")) + assertTrue(t, !Has("test")) globalState.channels["test"] = append(globalState.channels["test"], make(chan Message)) - assert.True(t, Has("test")) + assertTrue(t, Has("test")) } // TestList Checking the correct receipt of the list of events on which handlers are installed func TestList(t *testing.T) { - resetSystem() defer resetSystem() - assert.Empty(t, List()) + assertTrue(t, len(List()) == 0) globalState.channels["test"] = append(globalState.channels["test"], make(chan Message), make(chan Message)) globalState.channels["test2"] = append(globalState.channels["test2"], make(chan Message)) @@ -120,13 +119,13 @@ func TestList(t *testing.T) { actualList := List() sort.Strings(actualList) - assert.Equal(t, 2, len(actualList)) - assert.Equal(t, []string{"test", "test2"}, actualList) + assertTrue(t, len(actualList) == 2) + assertTrue(t, actualList[0] == "test") + assertTrue(t, actualList[1] == "test2") } // TestWait Checking Wait function func TestWait(t *testing.T) { - resetSystem() defer resetSystem() eventName := "test" @@ -136,16 +135,18 @@ func TestWait(t *testing.T) { time.Sleep(time.Millisecond) atomic.StoreInt32(&wasRunning, 1) }) - require.NoError(t, Ring(eventName, nil)) + assertNoError(t, Ring(eventName, nil)) Wait() - assert.Equal(t, int32(1), wasRunning) + assertTrue(t, wasRunning == 1) } // TestQueue checking function for set queue size func TestQueue(t *testing.T) { + defer resetSystem() + var size uint = 6 Queue(size) - assert.Equal(t, size, globalState.queueSize) + assertTrue(t, size == globalState.queueSize) } diff --git a/go.mod b/go.mod index 9283f10..c8cc910 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,3 @@ module github.com/nuttech/bell/v2 go 1.17 - -require github.com/stretchr/testify v1.7.0 - -require ( - github.com/davecgh/go-spew v1.1.0 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect -) diff --git a/go.sum b/go.sum index acb88a4..e69de29 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +0,0 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=