Ejemplo n.º 1
0
func Run() error {
	conf := config.Load()
	go Hub.Run()
	http.HandleFunc("/", ServeHome)
	http.HandleFunc("/ws", Hub.ServeWs)
	port := fmt.Sprintf(":%s", conf.Port)
	err := http.ListenAndServe(port, nil)
	if err != nil {
		fmt.Println(err)
		return err
	}
	return nil
}
Ejemplo n.º 2
0
func TestClientSendRecv(t *testing.T) {
	conf := config.Load()
	correctResponse := make(chan int)
	randString := random.Letters(50)
	ws := NewClient()
	ws.Recv = checkMessage(randString, correctResponse)
	wsUrl := fmt.Sprintf("http://%s:%s/ws", conf.Host, conf.Port)
	err := ws.Connect(wsUrl)
	if err != nil {
		log.Println(err)
	}
	go ws.Read()
	log.Println("Waiting for correctResponse", randString)
	ws.Write([]byte(randString))
	<-correctResponse
	log.Println("Got correctResponse", randString)
}
Ejemplo n.º 3
0
func TestServiceCallMethod(t *testing.T) {
	conf := config.Load()
	correctResponse := make(chan int)
	randString := random.Letters(25)
	service := NewTestService()
	service.ShouldBe = randString
	service.CorrectResponse = correctResponse
	// service.Methods = map[string]func(interface{}, []byte){
	// 	"TestServiceMessage": checkResponse,
	// }
	wsUrl := fmt.Sprintf("http://%s:%s/ws", conf.Host, conf.Port)
	err := service.Connect(wsUrl)
	if err != nil {
		log.Println(err)
	}
	go service.Read()
	log.Println("Waiting for correctResponse", randString)
	checkJson := fmt.Sprintf("{\"data\": \"%s\", \"method\": \"TestServiceMessage\"}", randString)
	service.Write([]byte(checkJson))
	<-correctResponse
	log.Println("Got correctResponse", randString)
}