コード例 #1
0
func sendCancelOrder() {
	in := test.ReadTestFile("cancel_order.json")
	in.From = userData.Name
	in.UserData = &userData

	res, err := test.POST(address, in)
	log.Printf("RESULT: %s\nerr?:%v", res.Message.Body, err)
}
コード例 #2
0
func send_key(key string, userData *s.InUserData) string {
	out := s.InPkg{UserData: userData, Message: &s.InMessage{Type: "chat", ID: utils.GenStringId(), Thread: utils.GenStringId(), Body: &key}, From: userData.Name}
	in, err := test.POST(address, &out)
	if err != nil {
		log.Printf("Error: %v", err)
		return ""
	}
	return strings.TrimSpace(in.Message.Body)
}
コード例 #3
0
func sendNewOrder(from, to string) {
	street_from := get_street(from, "street_from")
	house_from := s.InField{Data: s.InFieldData{Value: "1"}, Type: "text", Name: "house_from"}

	street_to := get_street(to, "street_to")
	house_to := s.InField{Data: s.InFieldData{Value: "1"}, Type: "text", Name: "house_from"}
	entrance := s.InField{Type: "number", Name: "entrance"}

	form := s.InForm{Fields: []s.InField{street_from, street_to, house_from, house_to, entrance}}
	command := s.InCommand{Action: "new_order", Form: form}

	out := s.InPkg{
		UserData: &userData,
		Message:  &s.InMessage{Type: "chat", ID: utils.GenStringId(), Thread: utils.GenStringId(), Commands: &[]s.InCommand{command}},
		From:     userData.Name,
	}

	in, err := test.POST(address, &out)
	log.Printf("RESULT: %s\nerr?:%v", in.Message.Body, err)
}
コード例 #4
0
func main() {
	msngr.TEST = true
	msngr.DEBUG = true

	cnf := configuration.ReadConfig()
	cnf.SetLogFile("test.log")
	error_chan := make(chan structs.MessageError, 10)
	ha := tstu.HandleAddress("/notify", ":9876", error_chan)
	for {
		res := <-ha
		log.Printf("HANDLE ADDR %v", res)
		if res == "listen" {
			break
		}
	}

	main_db := db.NewMainDb(cnf.Main.Database.ConnString, cnf.Main.Database.Name)
	//start_bot_result := make(chan string, 100)
	//go i.StartBot(main_db, start_bot_result)
	//for {
	//	res := <-start_bot_result
	//	log.Printf("BOT ENGINE: %v", res)
	//	if res == "listen" {
	//		break
	//	}
	//
	//}
	merror := structs.MessageError{
		Code:      500,
		Type:      "wait",
		Condition: "resource-constraint",
	}
	error_chan <- merror
	ntfr := ntf.NewNotifier(cnf.Main.CallbackAddr, "test_key", main_db)
	out_pkg, err := ntfr.NotifyText("TEST", "TEST MESSAGE")
	log.Printf("> NTF OUT IS: %v,\n err: %v", out_pkg, err)
	result, err := tstu.POST(address, &structs.InPkg{
		Message: &structs.InMessage{
			ID:    out_pkg.Message.ID,
			Error: &merror,
			Body:  &out_pkg.Message.Body,
		},
		From:     out_pkg.To,
		UserData: &structs.InUserData{Name: "TEST"},
	})
	log.Printf("ANSWER must be empty %v, %v", result, err)
	mess := "hui"
	merror.Code = 404
	result, err = tstu.POST(address, &structs.InPkg{
		Message: &structs.InMessage{
			ID:    mess,
			Error: &merror,
			Body:  &mess,
		},
		From:     out_pkg.To,
		UserData: &structs.InUserData{Name: "TEST"},
	})
	log.Printf("ANSWER must be empty %v %v", result, err)

	//result_outs := []*structs.OutPkg{}
	//for _, i := range []int{1, 2, 3, 4, 5, 6, 7} {
	//	out, err := ntfr.NotifyText("TEST", fmt.Sprintf("NOTIFY TST MESSSAGE %v", i))
	//	if out != nil {
	//		result_outs = append(result_outs, out)
	//		mw, err := main_db.Messages.GetMessageByMessageId(out.Message.ID)
	//		log.Printf("ASSERT sended status notify message? %v Err? %v", mw.MessageStatus, err)
	//	}else {
	//		log.Printf("WARN sended status notify message? %+v Err? %v", out, err)
	//	}
	//
	//}
	//
	//for _, out := range result_outs {
	//	if out.Message != nil {
	//		in := &structs.InPkg{
	//			Message:&structs.InMessage{
	//				Body:&out.Message.Body,
	//				Type:"error",
	//				Error:&out.Message.Error,
	//			},
	//			From:out.To,
	//			UserData:&structs.InUserData{Name:"TEST"},
	//		}
	//		log.Printf("TST_ERR_MESS send: \n\t%+v", in)
	//		out_echo, err := tstu.POST(address, in)
	//		log.Printf("ASSERT out_echo nil? %v and err:%v", out_echo == nil, err)
	//	}
	//	mw, err := main_db.Messages.GetMessageByMessageId(out.Message.ID)
	//	log.Printf("ASSERT err? %v we have this message? %v They have similar errors?: %v\n...message:\n%+v", err == nil, mw != nil, mw.MessageStatus == "error", mw.MessageCondition == out.Message.Error.Condition, )
	//
	//}
}
コード例 #5
0
func TestTaxiInfinityFail(t *testing.T) {
	conf := c.ReadTestConfigInRecursive()
	db := d.NewMainDb(conf.Main.Database.ConnString, conf.Main.Database.Name)
	taxi_conf := conf.Taxis["fake"]

	t.Logf("taxi api configuration for %+v:\n%v", taxi_conf.Name, taxi_conf.Api)
	external := i.GetTestInfAPI(taxi_conf.Api)

	external_api := external.(taxi.TaxiInterface)
	external_address_supplier := external.(taxi.AddressSupplier)

	apiMixin := taxi.ExternalApiMixin{API: external_api}

	carsCache := taxi.NewCarsCache(external_api)
	notifier := n.NewNotifier(conf.Main.CallbackAddr, taxi_conf.Chat.Key, db)

	address_handler, address_supplier := GetAddressInstruments(conf, taxi_conf.Name, external_address_supplier)
	configStore := d.NewConfigurationStorage(conf.Main.ConfigDatabase)
	botContext := taxi.FormTaxiBotContext(&apiMixin, db, configStore, taxi_conf, address_handler, carsCache)
	controller := m.FormBotController(botContext, db)

	t.Logf("Was create bot context: %+v\n", botContext)
	http.HandleFunc(fmt.Sprintf("/taxi/%v", taxi_conf.Name), controller)

	go func() {
		taxiContext := taxi.TaxiContext{API: external_api, DataBase: db, Cars: carsCache, Notifier: notifier}
		t.Logf("Will start order watcher for [%v]", botContext.Name)
		taxi.TaxiOrderWatch(&taxiContext, botContext)
	}()

	http.HandleFunc(fmt.Sprintf("/taxi/%v/streets", taxi_conf.Name), func(w http.ResponseWriter, r *http.Request) {
		geo.StreetsSearchController(w, r, address_supplier)
	})

	go func() {
		server_address := fmt.Sprintf(":%v", conf.Main.Port)
		t.Logf("\nStart listen and serving at: %v\n", server_address)
		server := &http.Server{
			Addr: server_address,
		}
		server.ListenAndServe()
	}()

	u.After(external_api.IsConnected, func() {
		inf_api := external.(*i.InfinityAPI)
		for i, _ := range inf_api.ConnStrings {
			inf_api.ConnStrings[i] += "w"
		}
	})

	_, err := u.GET(taxi_conf.DictUrl, &map[string]string{"q": "лесос"})
	if err != nil {
		t.Error("Error at getting street %v", err)
	}

	out_res, err := tu.POST(fmt.Sprintf("http://localhost:%v/taxi/%v", conf.Main.Port, taxi_conf.Name), &structs.InPkg{
		Message: &structs.InMessage{
			ID: u.GenStringId(),
			Commands: &[]structs.InCommand{
				structs.InCommand{Action: "information", Title: "information"},
			},
		},
		From:     "test user",
		UserData: &structs.InUserData{Name: "TEST"},
	})

	if err != nil {
		t.Errorf("Error at unmarshal result info %v", err)
	}

	if out_res == nil {
		t.Error("Out info result is nil!")
	} else {
		if out_res.Message.Type != "chat" {
			t.Errorf("Out message type != chat, but == %v", out_res.Message.Type)
		}
		ch, _ := configStore.GetChatConfig(taxi_conf.Chat.CompanyId)

		if out_res.Message.Body != ch.Information {
			t.Errorf("Out message body != info in config, but == %v", out_res.Message.Body)
		}
	}

}