add discov tests (#448)

This commit is contained in:
Kevin Wan
2021-02-07 20:24:47 +08:00
committed by GitHub
parent 22a1fa649e
commit 5b79ba2618
3 changed files with 34 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package discov
import (
"sync/atomic"
"testing"
"github.com/stretchr/testify/assert"
@@ -198,3 +199,18 @@ func TestContainer(t *testing.T) {
}
}
}
func TestSubscriber(t *testing.T) {
var opt subOptions
Exclusive()(&opt)
sub := new(Subscriber)
sub.items = newContainer(opt.exclusive)
var count int32
sub.AddListener(func() {
atomic.AddInt32(&count, 1)
})
sub.items.notifyChange()
assert.Empty(t, sub.Values())
assert.Equal(t, int32(1), atomic.LoadInt32(&count))
}