/usr/share/gocode/src/github.com/cenk/hub/hub_test.go is in golang-github-cenk-hub-dev 1.0.0+git20160321.17.b864404b5f99-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | package hub
import "testing"
const testKind Kind = 1
const testValue = "foo"
type testEvent string
func (e testEvent) Kind() Kind {
return testKind
}
func TestPubSub(t *testing.T) {
var h Hub
var s string
h.Subscribe(testKind, func(e Event) { s = string(e.(testEvent)) })
h.Publish(testEvent(testValue))
if s != testValue {
t.Errorf("invalid value: %s", s)
}
}
func TestCancel(t *testing.T) {
var h Hub
var called int
var f = func(e Event) { called += 1 }
_ = h.Subscribe(testKind, f)
cancel := h.Subscribe(testKind, f)
h.Publish(testEvent(testValue)) // 2 calls to f
cancel()
h.Publish(testEvent(testValue)) // 1 call to f
if called != 3 {
t.Errorf("unexpected call count: %d", called)
}
}
|