go-pattern-examples/structure/03_bridge/bridge_test.go

28 lines
657 B
Go
Raw Normal View History

2020-04-21 17:50:21 +03:00
package bridge
2020-04-28 11:37:17 +03:00
import "testing"
2020-04-21 17:50:21 +03:00
2020-04-28 11:37:17 +03:00
func TestSendMessage(t *testing.T) {
2020-04-21 17:50:21 +03:00
2020-04-28 11:37:17 +03:00
//注意看这里,接口的实例关系在初始化时候是固定的
ws := &WSMessage{&EmergencyWSMessage{}, 100}
//注意看这里,接口的实例关系在初始化时候是固定的
email := &EmailMessage{&EmergencyEmailMessage{}, 10}
ws.NoticeUser("Miss White ,Let's Drink")
email.NoticeUser("Miss White,Fire!,Fire!")
2020-04-21 17:50:21 +03:00
2020-04-28 11:37:17 +03:00
ews := &EmergencyWSMessage{}
eem := &EmergencyEmailMessage{}
list := []IMessage{
&WSMessage{ews, 50},
&WSMessage{ews, 100},
&EmailMessage{eem, 10},
&EmailMessage{eem, 20},
}
for _, v := range list {
v.NoticeUser("Lets go for fun")
}
2020-04-21 17:50:21 +03:00
}