mirror of
https://github.com/crazybber/go-pattern-examples.git
synced 2024-11-28 22:46:03 +03:00
30 lines
513 B
Go
30 lines
513 B
Go
package observer
|
||
|
||
import (
|
||
"context"
|
||
"testing"
|
||
)
|
||
|
||
func TestObserver(t *testing.T) {
|
||
|
||
//内容提供商,科技BBS
|
||
techInfoProvider := TechBBS{}
|
||
|
||
lily := User{"Lily"}
|
||
|
||
jacky := User{"Jacky"}
|
||
|
||
techInfoProvider.Registry(&lily)
|
||
techInfoProvider.Registry(&jacky)
|
||
|
||
updateKey := updates{}
|
||
|
||
updateValue := updates{topic: "cosmos", order: 1001}
|
||
|
||
updateContent := context.WithValue(context.Background(), updateKey, updateValue)
|
||
techInfoProvider.SetConext(updateContent)
|
||
|
||
techInfoProvider.noticeAllUpdate()
|
||
|
||
}
|