func main() { var test = flag.Bool("test", false, "go in test use?") flag.Parse() d.DELETE_DB = *test m.DEBUG = *test m.TEST = *test conf := configuration.ReadConfig() db := d.NewMainDb(conf.Main.Database.ConnString, conf.Main.Database.Name) log.Printf("Is delete DB? [%+v] Is debug? [%v]", d.DELETE_DB, m.DEBUG) if d.DELETE_DB { log.Println("!!!!!!!!!!start at test mode!!!!!!!!!!!!!") conf.Main.Database.Name = conf.Main.Database.Name + "_test" db.Session.DB(conf.Main.Database.Name).DropDatabase() db = d.NewMainDb(conf.Main.Database.ConnString, conf.Main.Database.Name) } InsertTestUser(db, "test", "test") InsertTestUser(db, "test1", "test1") InsertTestUser(db, "test2", "test2") result := make(chan string, 1000) i.StartBot(db, result) }
func main() { conf := c.ReadConfig() handler := db.NewMainDb(conf.Main.Database.ConnString, conf.Main.Database.Name) s.StartAfter(func() (string, bool) { return "", handler.Check() }, func() { log.Printf("connection established....") }) log.Println("Starting migration 1...") users_collection := handler.Session.DB(conf.Main.Database.Name).C("users") users_collection.UpdateAll(bson.M{}, bson.M{"$set": bson.M{"states": bson.M{}}}) }
func main() { msngr.DEBUG = true // my_street := "Российская" my_address_from := "Российская 3" my_street_to := "Российская 28" conf := configuration.ReadConfig() api_data := conf.Taxis["fake"].Api.GetAPIData() s := sedi.NewSediAPI(&api_data) // order_statuses, err := s.GetOrderStatuses() // if err != nil { // log.Printf("order statuses err : %v", err) // return // } // for _, order_status := range order_statuses { // log.Printf("order status : %+v \n", order_status) // } log.Println(s) address_from := s.AddressesAutocomplete(my_address_from) adress_to := s.AddressesAutocomplete(my_street_to) log.Printf("\nFrom %+v\nTo %+v\n", address_from, adress_to) // order := taxi.NewOrderInfo{ // Delivery:taxi.Delivery{Street:my_street, House:"3"}, // Destinations:[]taxi.Destination{taxi.Destination{Street:my_street, House:"28"}}, // Phone:"+79811064022", // } // res, mes := s.CalcOrderCost(order) // log.Printf("calc res: %v, mes: %s", res, mes) // // ans := s.NewOrder(order) // log.Printf("ans of new order response: %+v", ans) // // for { // orders := s.Orders() // for i, order := range orders { // log.Printf("%v\t%v\n", i, order) // } // time.Sleep(10 * time.Second) // } // // if ans.IsSuccess { // fmt.Println(s.CancelOrder(ans.Content.Id)) // } }
func main() { config := c.ReadConfig() tc, ok := config.Taxis["fake"] if !ok { panic("not fake taxi in config!!!") } inf := i.GetTestInfAPI(tc.Api) log.Printf("inf: %+v", inf) log.Printf("connected? %v", inf.IsConnected()) log.Printf("orders: %+v", inf.Orders()) log.Printf("cars: %+v", inf.GetCarsInfo()) as := i.GetInfinityAddressSupplier(tc.Api, "test") log.Printf("is connected? %v", as.IsConnected()) log.Printf("adress result: %+v", as.AddressesAutocomplete("Никол").Rows) }
func main() { conf := c.ReadConfig() qs := q.NewQuestStorage(conf.Main.Database.ConnString, conf.Main.Database.Name) users, err := qs.GetAllUsers() if err != nil { log.Printf("Error: %v", err) return } for _, user := range users { if user.Name == "" && user.Phone == "" && user.EMail == "" { err = qs.Users.RemoveId(user.ID) if err != nil { log.Printf("Error: %v", err) } } } }
func TestBot(t *testing.T) { conf := c.ReadConfig() var test = flag.Bool("test", false, "go in test use?") flag.Parse() DEBUG = true d.DELETE_DB = *test log.Printf("Is test? [%+v] Will delete db? [%+v]", *test, d.DELETE_DB) if d.DELETE_DB { log.Println("!start at test mode!") conf.Main.Database.Name = conf.Main.Database.Name + "_test" } db := d.NewMainDb(conf.Main.Database.ConnString, conf.Main.Database.Name) for _, shop_conf := range conf.Shops { bot_context := sh.FormShopCommands(db, &shop_conf) shop_controller := FormBotController(bot_context) shop_route := fmt.Sprintf("/shop/%v", shop_conf.Name) log.Println("will wait requests at :", shop_route) http.HandleFunc(shop_route, shop_controller) } server_address := fmt.Sprintf(":%v", conf.Main.Port) s.StartAfter(func() (string, bool) { return "", db.Check() }, func() { log.Printf("\nStart listen and serving at: %v\n", server_address) server := &http.Server{ Addr: server_address, } log.Fatal(server.ListenAndServe()) }) log.Printf("will send requests....") addr := fmt.Sprintf("http://localhost:%v/shop/test_shop", conf.Main.Port) send_post("shop_balance_ok.json", addr) send_post("shop_balance_error.json", addr) send_post("request_commands.json", addr) t.Log("test ended...") }
func main() { conf := c.ReadConfig() handler := db.NewMainDb(conf.Main.Database.ConnString, conf.Main.Database.Name) s.StartAfter(func() (string, bool) { return "", handler.Check() }, func() { log.Printf("connection established....") }) log.Println("Starting migration 0...") orders_collection := handler.Session.DB(conf.Main.Database.Name).C("orders") err := orders_collection.DropIndex("order_id") if err != nil { panic(err) } err = orders_collection.EnsureIndex(mgo.Index{ Key: []string{"order_id"}, Background: true, Unique: false, DropDups: true, }) log.Printf("Index for order_id field is recreated...%v", err) }
func StartBot(db *d.MainDb, result chan string) c.Configuration { conf := c.ReadConfig() log.Printf("configuration for db:\nconnection string: %+v\ndatabase name: %+v", conf.Main.Database.ConnString, conf.Main.Database.Name) log.Printf("configuration for conf db:\nconnection string: %+v\ndatabase name: %+v", conf.Main.ConfigDatabase.ConnString, conf.Main.ConfigDatabase.Name) db.Users.AddOrUpdateUserObject(d.UserData{ UserId: "alesha", UserName: "******", Password: utils.PHash("sederfes100500"), Role: users.MANAGER, BelongsTo: "klichat", }) configStorage := d.NewConfigurationStorage(conf.Main.ConfigDatabase) questStorage := q.NewQuestStorage(conf.Main.Database.ConnString, conf.Main.Database.Name) fs := http.FileServer(http.Dir("static")) http.Handle("/static/", http.StripPrefix("/static/", fs)) for taxi_name, taxi_conf := range conf.Taxis { log.Printf("taxi api configuration for %+v:\n%v", taxi_conf.Name, taxi_conf.Api) external_api, external_address_supplier, err := GetTaxiAPIInstruments(taxi_conf.Api, taxi_name) if err != nil { log.Printf("Skip this taxi api [%+v]\nBecause: %v", taxi_conf.Api, err) continue } apiMixin := t.ExternalApiMixin{API: external_api} carsCache := t.NewCarsCache(external_api) notifier := n.NewNotifier(conf.Main.CallbackAddr, taxi_conf.Chat.Key, db) address_handler, address_supplier := GetAddressInstruments(conf, taxi_name, external_address_supplier) botContext := t.FormTaxiBotContext(&apiMixin, db, configStorage, taxi_conf, address_handler, carsCache) controller := m.FormBotController(botContext, db) log.Printf("Was create bot context: %+v\n", botContext) http.HandleFunc(fmt.Sprintf("/taxi/%v", taxi_conf.Name), controller) go func() { api, err := GetTaxiAPI(taxi_conf.Api, taxi_name+"_watch") if err != nil { log.Printf("Error at get api: %v for %v, will not use order watching", err, taxi_name) } cc := t.NewCarsCache(api) taxiContext := t.TaxiContext{API: api, DataBase: db, Cars: cc, Notifier: notifier} log.Printf("Will start order watcher for [%v]", botContext.Name) t.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) }) if m.TEST { http.HandleFunc(fmt.Sprintf("/taxi/%v/streets/ext", taxi_conf.Name), func(w http.ResponseWriter, r *http.Request) { geo.StreetsSearchController(w, r, external_address_supplier) }) } configStorage.SetChatConfig(taxi_conf.Chat, false) result <- fmt.Sprintf("taxi_%v", taxi_name) } for _, shop_conf := range conf.Shops { bot_context := sh.FormShopCommands(db, &shop_conf) shop_controller := m.FormBotController(bot_context, db) http.HandleFunc(fmt.Sprintf("/shop/%v", shop_conf.Name), shop_controller) result <- fmt.Sprintf("shops_%v", shop_conf.Name) } if conf.RuPost.WorkUrl != "" { log.Printf("will start ru post controller at: %v and will send requests to: %v", conf.RuPost.WorkUrl, conf.RuPost.ExternalUrl) rp_bot_context := rp.FormRPBotContext(conf) rp_controller := m.FormBotController(rp_bot_context, db) http.HandleFunc(conf.RuPost.WorkUrl, rp_controller) result <- "rupost" } for _, qConf := range conf.Quests { q_name := qConf.Chat.CompanyId log.Printf("Will handling quests controller for quest: %v", q_name) qb_controller := q.FormQuestBotContext(conf, qConf, questStorage, db, configStorage) q_controller := m.FormBotController(qb_controller, db) route := fmt.Sprintf("/quest/%v", q_name) log.Printf("Quest %v will handle at %v", q_name, route) http.HandleFunc(route, q_controller) configStorage.SetChatConfig(qConf.Chat, false) questStorage.SetMessageConfiguration(q.QuestMessageConfiguration{CompanyId: qConf.Chat.CompanyId}, false) result <- fmt.Sprintf("quest_%v", q_name) } if conf.Console.WebPort != "" && conf.Console.Chat.Key != "" { log.Printf("Will handling requests from /console at %v", conf.Console.WebPort) bc := cnsl.FormConsoleBotContext(conf, db, configStorage) cc := m.FormBotController(bc, db) http.HandleFunc("/console", cc) web.DefaultUrlMap.AddAccessory("klichat", "/klichat") configStorage.SetChatConfig(conf.Console.Chat, false) result <- "console" } if conf.Vote.DictUrl != "" { vdh, _ := v.NewVotingHandler(conf.Main.Database.ConnString, conf.Main.Database.Name) http.HandleFunc("/autocomplete/vote/name", func(w http.ResponseWriter, r *http.Request) { v.AutocompleteController(w, r, vdh, "name", []string{}) }) http.HandleFunc("/autocomplete/vote/city", func(w http.ResponseWriter, r *http.Request) { v.AutocompleteController(w, r, vdh, "city", conf.Vote.Cities) }) http.HandleFunc("/autocomplete/vote/service", func(w http.ResponseWriter, r *http.Request) { v.AutocompleteController(w, r, vdh, "service", conf.Vote.Services) }) http.HandleFunc("/autocomplete/vote/role", func(w http.ResponseWriter, r *http.Request) { v.AutocompleteController(w, r, vdh, "vote.voters.role", conf.Vote.Roles) }) voteBot := v.FormVoteBotContext(conf, db) voteBotController := m.FormBotController(voteBot, db) log.Printf("Will handling requests for /vote") http.HandleFunc("/vote", voteBotController) result <- "vote" } if len(conf.Coffee) > 0 { for _, coffee_conf := range conf.Coffee { c_store := coffee.NewCoffeeConfigHandler(db) c_store.LoadFromConfig(coffee_conf) coffeeHouseConfiguration := coffee.NewCHCFromConfig(coffee_conf) cbc := coffee.FormBotCoffeeContext(coffee_conf, db, coffeeHouseConfiguration, configStorage) cntrl := m.FormBotController(cbc, db) route := fmt.Sprintf("/bot/coffee/%v", coffee_conf.Chat.CompanyId) http.HandleFunc(route, cntrl) log.Printf("will handling bot messages for coffee %v at %v", coffee_conf.Chat.CompanyId, route) http.HandleFunc(fmt.Sprintf("/autocomplete/coffee/%v/drink", coffee_conf.Chat.CompanyId), func(w http.ResponseWriter, r *http.Request) { coffee.AutocompleteController(w, r, c_store, "drinks", coffee_conf.Chat.CompanyId) }) http.HandleFunc(fmt.Sprintf("/autocomplete/coffee/%v/volume", coffee_conf.Chat.CompanyId), func(w http.ResponseWriter, r *http.Request) { coffee.AutocompleteController(w, r, c_store, "volumes", coffee_conf.Chat.CompanyId) }) http.HandleFunc(fmt.Sprintf("/autocomplete/coffee/%v/bake", coffee_conf.Chat.CompanyId), func(w http.ResponseWriter, r *http.Request) { coffee.AutocompleteController(w, r, c_store, "bakes", coffee_conf.Chat.CompanyId) }) http.HandleFunc(fmt.Sprintf("/autocomplete/coffee/%v/additive", coffee_conf.Chat.CompanyId), func(w http.ResponseWriter, r *http.Request) { coffee.AutocompleteController(w, r, c_store, "additives", coffee_conf.Chat.CompanyId) }) var salt string if coffee_conf.Chat.UrlSalt != "" { salt = fmt.Sprintf("%v-%v", coffee_conf.Chat.CompanyId, coffee_conf.Chat.UrlSalt) } else { salt = coffee_conf.Chat.CompanyId } notifier := n.NewNotifier(conf.Main.CallbackAddr, coffee_conf.Chat.Key, db) notifier.SetFrom(coffee_conf.Chat.CompanyId) webRoute := fmt.Sprintf("/web/coffee/%v", salt) http.Handle(webRoute, coffee.GetChatMainHandler(webRoute, notifier, db, coffee_conf.Chat)) web.DefaultUrlMap.AddAccessory(coffee_conf.Chat.CompanyId, webRoute) sr := func(s string) string { return fmt.Sprintf("%v%v", webRoute, s) } http.Handle(sr("/send"), chat.GetChatSendHandler(sr("/send"), notifier, db, coffee_conf.Chat, chat.NewChatStorage(db))) http.Handle(sr("/unread_messages"), chat.GetChatUnreadMessagesHandler(sr("/unread_messages"), notifier, db, coffee_conf.Chat)) http.Handle(sr("/messages_read"), chat.GetChatMessageReadHandler(sr("/messages_read"), notifier, db, coffee_conf.Chat)) http.Handle(sr("/contacts_change"), chat.GetChatContactsChangeHandler(sr("/contacts_change"), notifier, db, coffee_conf.Chat)) http.Handle(sr("/delete_messages"), chat.GetChatDeleteMessagesHandler(sr("/delete_messages"), db, coffee_conf.Chat)) http.Handle(sr("/config"), coffee.GetChatConfigHandler(sr("/config"), webRoute, db, coffee_conf.Chat)) http.Handle(sr("/contacts"), coffee.GetChatContactsHandler(sr("/contacts"), notifier, db, coffee_conf.Chat)) http.Handle(sr("/message_function"), coffee.GetMessageAdditionalFunctionsHandler(sr("/message_function"), notifier, db, coffee_conf.Chat, coffeeHouseConfiguration)) //http.Handle(sr("/order_page"), coffee.GetOrdersPageFunctionHandler(sr("/order_page"), webRoute, db, coffee_conf.Chat, coffee_conf.Chat.CompanyId)) //http.Handle(sr("/order_page_supply"), coffee.GetOrdersPageSupplierFunctionHandler(sr("/order_page_supply"), webRoute, db, coffee_conf.Chat, coffee_conf.Chat.CompanyId)) http.Handle(sr("/logout"), coffee.GetChatLogoutHandler(sr("/logout"), webRoute, db, coffee_conf.Chat)) log.Printf("I will handling web requests for coffee %v at : [%v]", coffee_conf.Chat.CompanyId, webRoute) db.Users.AddOrUpdateUserObject(d.UserData{ UserId: coffee_conf.Chat.User, UserName: coffee_conf.Chat.User, ShowedName: coffee_conf.Chat.Name, Password: utils.PHash(coffee_conf.Chat.Password), BelongsTo: coffee_conf.Chat.CompanyId, ReadRights: []string{coffee_conf.Chat.CompanyId}, WriteRights: []string{coffee_conf.Chat.CompanyId}, }) configStorage.SetChatConfig(coffee_conf.Chat, false) } result <- "coffee" } if len(conf.Chats) > 0 { for _, chat_conf := range conf.Chats { chatBotContext := chat.FormChatBotContext(db, configStorage, chat_conf.CompanyId) chatBotController := m.FormBotController(chatBotContext, db) route := fmt.Sprintf("/bot/chat/%v", chat_conf.CompanyId) http.HandleFunc(route, chatBotController) log.Printf("I will serving message for chat bot at : [%v]", route) notifier := n.NewNotifier(conf.Main.CallbackAddr, chat_conf.Key, db) notifier.SetFrom(chat_conf.CompanyId) var salt string if chat_conf.UrlSalt != "" { salt = fmt.Sprintf("%v-%v", chat_conf.CompanyId, chat_conf.UrlSalt) } else { salt = chat_conf.CompanyId } webRoute := fmt.Sprintf("/web/chat/%v", salt) http.Handle(webRoute, chat.GetChatMainHandler(webRoute, notifier, db, chat_conf)) web.DefaultUrlMap.AddAccessory(chat_conf.CompanyId, webRoute) sr := func(s string) string { return fmt.Sprintf("%v%v", webRoute, s) } http.Handle(sr("/send"), chat.GetChatSendHandler(sr("/send"), notifier, db, chat_conf, chat.NewChatStorage(db))) http.Handle(sr("/unread_messages"), chat.GetChatUnreadMessagesHandler(sr("/unread_messages"), notifier, db, chat_conf)) http.Handle(sr("/messages_read"), chat.GetChatMessageReadHandler(sr("/messages_read"), notifier, db, chat_conf)) http.Handle(sr("/contacts"), chat.GetChatContactsHandler(sr("/contacts"), notifier, db, chat_conf)) http.Handle(sr("/contacts_change"), chat.GetChatContactsChangeHandler(sr("/contacts_change"), notifier, db, chat_conf)) http.Handle(sr("/config"), chat.GetChatConfigHandler(sr("/config"), webRoute, db, chat_conf)) http.Handle(sr("/delete_messages"), chat.GetChatDeleteMessagesHandler(sr("/delete_messages"), db, chat_conf)) http.Handle(sr("/logout"), chat.GetChatLogoutHandler(sr("/logout"), webRoute, db, chat_conf)) log.Printf("I will handling web requests for chat at : [%v]", webRoute) db.Users.AddOrUpdateUserObject(d.UserData{ UserName: chat_conf.User, Password: utils.PHash(chat_conf.Password), UserId: chat_conf.User, BelongsTo: chat_conf.CompanyId, ReadRights: []string{chat_conf.CompanyId}, WriteRights: []string{chat_conf.CompanyId}, }) configStorage.SetChatConfig(chat_conf, false) } result <- "chat" } go n.WatchUnreadMessages(db, configStorage, conf.Main.CallbackAddrMembers) go autoanswers.WatchNotAnsweredMessages(db, configStorage, conf.Main.CallbackAddr) server_address := fmt.Sprintf(":%v", conf.Main.Port) log.Printf("\nStart listen and serving at: %v\n", server_address) server := &http.Server{ Addr: server_address, } result <- "listen" http.Handle("/", web.NewSessionAuthorisationHandler(db)) log.Fatal(server.ListenAndServe()) return conf }
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, ) // //} }
import ( "encoding/json" "fmt" "log" c "msngr/configuration" s "msngr/structs" g "msngr/taxi/geo" "msngr/utils" "msngr/utils/set" ) const ( taxi_name = "fake" ) var config = c.ReadConfig() var address = fmt.Sprintf("http://localhost:%v/taxi/%v", config.Main.Port, taxi_name) var address_str = fmt.Sprintf("http://localhost:%v/taxi/%v/streets", config.Main.Port, taxi_name) var userData = s.InUserData{Phone: "TESTPHONE", Name: "TESTNAME"} func get_streets(name string) []g.DictItem { res, err := utils.GET(address_str, &map[string]string{"q": name}) if err != nil { log.Printf("Error at get streets", err) panic(err) } s_res := []g.DictItem{} err = json.Unmarshal(*res, &s_res) if err != nil { log.Printf(err.Error()) }
package console import ( "log" cfg "msngr/configuration" d "msngr/db" t "msngr/taxi" "fmt" "github.com/tealeg/xlsx" "gopkg.in/mgo.v2/bson" "msngr/utils" ) var config = cfg.ReadConfig() func getDbsWithOrders() []string { dbHelper := d.NewDbHelper(config.Main.Database.ConnString, "local") result := []string{} if names, err := dbHelper.Session.DatabaseNames(); err == nil { for _, dbName := range names { collections, err := dbHelper.Session.DB(dbName).CollectionNames() if err != nil { continue } if utils.InS("orders", collections) { result = append(result, dbName) } } } return result
func TestLogInOut(t *testing.T) { conf := c.ReadConfig() d.DELETE_DB = true if d.DELETE_DB { log.Println("!start at test mode!") conf.Main.Database.Name = conf.Main.Database.Name + "_test" } user, pwd := "test", "test" db := d.NewMainDb(conf.Main.Database.ConnString, conf.Main.Database.Name) err := db.Users.SetUserPassword(user, pwd) if err != nil { go func() { for err == nil { time.Sleep(1 * time.Second) err = db.Users.SetUserPassword(user, pwd) log.Printf("trying add user for test shops... now we have err:%+v", err) } }() } for _, shop_conf := range conf.Shops { if shop_conf.Name != "test_shop" { continue } db := d.NewMainDb(conf.Main.Database.ConnString, conf.Main.Database.Name) for !db.IsConnected() { log.Printf("wait wile db is connected...") time.Sleep(1 * time.Second) } bot_context := FormShopCommands(db, &shop_conf) request_commands := bot_context.RequestProcessors message_commands := bot_context.MessageProcessors in := s.InPkg{From: "TEST", UserData: &s.InUserData{Phone: "TEST123"}, Request: &s.InRequest{ID: "1234", Type: "get"}} in.Request.Query.Action = "COMMANDS" request_result := request_commands["commands"].ProcessRequest(&in) rr_commands := *request_result.Commands log.Printf("request commands result: %#v", reflect.DeepEqual(rr_commands, NOT_AUTH_COMMANDS)) if !reflect.DeepEqual(rr_commands, NOT_AUTH_COMMANDS) { t.Errorf("before auth commands is auth") } in_auth := s.InPkg{ From: "TEST", UserData: &s.InUserData{Phone: "TEST123"}, Message: &s.InMessage{Commands: &[]s.InCommand{ s.InCommand{ Action: "authorise", Form: s.InForm{ Fields: []s.InField{ s.InField{ Name: "username", Data: s.InFieldData{ Value: "test", }, }, s.InField{ Name: "password", Data: s.InFieldData{ Value: "test", }, }, }}, }, }}} auth_result := message_commands["authorise"].ProcessMessage(&in_auth) ar_commnads := *auth_result.Commands log.Printf("auth commands result: %v", reflect.DeepEqual(ar_commnads, AUTH_COMMANDS)) if !reflect.DeepEqual(ar_commnads, AUTH_COMMANDS) { t.Errorf("after auth result commands is not aut") } log.Println("request commands next...") request_result = request_commands["commands"].ProcessRequest(&in) rr_commands = *request_result.Commands log.Printf("request commands result: %#v", reflect.DeepEqual(rr_commands, AUTH_COMMANDS)) if !reflect.DeepEqual(rr_commands, AUTH_COMMANDS) { t.Errorf("after auth commands not auth") } } }