func TestAddBracelet(t *testing.T) { // id := "865581020526375" id := "867293022970357" serv, _ := s.Init("./config.json") serv.Registrator.Connect() for { if err := serv.RpcClients["T**s"].Connect(); err != nil { fmt.Println(err) time.Sleep(time.Second * 5) continue } break } serv.RpcClients["Mxa"] = &s.RpcClient{Address: "localhost:7778", HTTP: true} for { if err := serv.RpcClients["Mxa"].Connect(); err != nil { fmt.Println(err) time.Sleep(time.Second * 5) continue } break } br := &s.Bracelet{Id: id, Server: serv} serv.Bracelets[id] = br if err := serv.Registrator.AddBracelet(id, "620353523587437655"); err != nil { t.Error(err) } }
func TestRemoveBracelet(t *testing.T) { id := "865581020526383" serv, _ := s.Init("./config.json") serv.Registrator.Connect() for { if err := serv.RpcClients["T**s"].Connect(); err != nil { fmt.Println(err) time.Sleep(time.Second * 5) continue } break } serv.RpcClients["Mxa"] = &s.RpcClient{Address: "localhost:7778", HTTP: true} for { if err := serv.RpcClients["Mxa"].Connect(); err != nil { fmt.Println(err) time.Sleep(time.Second * 5) continue } break } br := &s.Bracelet{Id: id, Server: serv} serv.Bracelets[id] = br if err := serv.Registrator.RemoveBracelet("14430159541424117"); err != nil { t.Error(err) } }
func TestGetUsers(t *testing.T) { // serv := &s.Server{RpcClients: make(map[string]*s.RpcClient)} // serv.Registrator = serv.CreateRegistrator("sergeyk", "4576") serv, _ := s.Init("./config.json") serv.Registrator.Connect() for i := 0; i < 10; i++ { clients, err := serv.Registrator.GetUsers("590890911395826551") if err != nil { t.Error(err) } fmt.Println(clients) } }
func TestHarvest(t *testing.T) { // serv := &s.Server{RpcClients: make(map[string]*s.RpcClient)} // serv.Registrator = serv.CreateRegistrator("sergeyk", "4576") serv, _ := s.Init("./config.json") fmt.Println(serv.Registrator) err := serv.Registrator.Connect() // s.SendMsg(serv.Registrator, fmt.Sprintf("<iq type=\"get\" id=\"addressbook\" index=\"%d\"></iq>", 0)) // s.SendMsg(serv.Registrator, fmt.Sprintf("<AddImGroup><ownerId>%s</ownerId><name>%s</name><private>%s</private></AddImGroup>", "43892772337280164", "services", "false")) // time.Sleep(time.Second * 5) // serv.Registrator.AddToGroup("43892770819391850", "620353523587437655") // serv.Registrator.AddToGroup("43892771683909469", "620353523587437655") // data, _ := serv.Registrator.GetUsers("620353523587437655") // fmt.Println(data) // time.Sleep(time.Second * 5) // return clients, phones, err := serv.Registrator.HarvestDataForBracelet("43892770819391850", "620353523587437655") br := s.Bracelet{ Id: "867293022970357", Server: serv, POIs: &s.POI{}, Login: "******", Password: "******", GroupId: "620353523587437655", } data := s.BraceletData{ Id: br.Id, Clients: clients, Phones: phones, } fmt.Printf("%#v\n", data) if err := br.SaveData(data); err != nil { t.Error(err) } if err != nil { t.Error(err) } fmt.Println(phones, clients) }
func TestSaveData(t *testing.T) { serv, _ := s.Init("./config.json") fmt.Println(serv.Registrator) serv.Registrator.Connect() // serv := &s.Server{RpcClients: make(map[string]*s.RpcClient)} serv.RpcClients["T**s"] = &s.RpcClient{Address: "localhost:7777", HTTP: true} for { if err := serv.RpcClients["T**s"].Connect(); err != nil { fmt.Println(err) time.Sleep(time.Second * 5) continue } break } br := s.Bracelet{Id: "865581020166156", Server: serv, POIs: &s.POI{}, Login: "******", Password: "******", GroupId: "590890911395826551"} data := s.BraceletData{ Id: br.Id, Clients: []s.Client{ s.Client{Position: "1", Avatar: "1", Id: "14430159621632068", TextImage: "Максим"}, s.Client{Position: "2", Avatar: "3", Id: "14430158950689761", TextImage: "Андрей"}, s.Client{Position: "3", Avatar: "4", Id: "14430160235733607", TextImage: "180"}, s.Client{Position: "4", Avatar: "5", Id: "14430159541424117", TextImage: "383"}, }, Phones: []s.Phone{ s.Phone{Position: "1", Number: "+79857621518", Avatar: "4", TextImage: "Андрей1"}, s.Phone{Position: "2", Number: "+79647829211", Avatar: "3", TextImage: "Андрей2"}, s.Phone{Position: "3", Number: "+79160252646", Avatar: "2", TextImage: "Сергей"}, s.Phone{Position: "4", Number: "+79670238554", Avatar: "1", TextImage: "Максим"}, }, } if err := br.SaveData(data); err != nil { t.Error(err) } clients, phones, _ := serv.Registrator.HarvestDataForBracelet("43892770819391850", "620353523587437655") br = s.Bracelet{ Id: "867293022970357", Server: serv, POIs: &s.POI{}, Login: "******", Password: "******", GroupId: "620353523587437655", } data = s.BraceletData{ Id: br.Id, Clients: clients, Phones: phones, } fmt.Printf("%#v\n", data) if err := br.SaveData(data); err != nil { t.Error(err) } br = s.Bracelet{Id: "865581020526383", Server: serv, POIs: &s.POI{}, Login: "******", Password: "******", GroupId: "590890911395826551"} data = s.BraceletData{ Id: br.Id, Clients: []s.Client{ s.Client{Position: "1", Avatar: "1", Id: "14430159621632068", TextImage: "Максим"}, s.Client{Position: "2", Avatar: "3", Id: "14430158950689761", TextImage: "Андрей"}, s.Client{Position: "3", Avatar: "4", Id: "14430160235733607", TextImage: "180"}, s.Client{Position: "4", Avatar: "5", Id: "14430159373335405", TextImage: "156"}, }, Phones: []s.Phone{ s.Phone{Position: "1", Number: "+79857621518", Avatar: "4", TextImage: "Андрей1"}, s.Phone{Position: "2", Number: "+79647829211", Avatar: "3", TextImage: "Андрей2"}, s.Phone{Position: "3", Number: "+79160252646", Avatar: "2", TextImage: "Сергей"}, s.Phone{Position: "4", Number: "+79670238554", Avatar: "1", TextImage: "Максим"}, }, } if err := br.SaveData(data); err != nil { t.Error(err) } br = s.Bracelet{Id: "865581020166180", Server: serv, POIs: &s.POI{}, Login: "******", Password: "******", GroupId: "590890911395826551"} data = s.BraceletData{ Id: br.Id, Clients: []s.Client{ s.Client{Position: "1", Avatar: "1", Id: "14430159621632068", TextImage: "Максим"}, s.Client{Position: "2", Avatar: "3", Id: "14430158950689761", TextImage: "Андрей"}, s.Client{Position: "3", Avatar: "4", Id: "14430159373335405", TextImage: "156"}, s.Client{Position: "4", Avatar: "5", Id: "14430159541424117", TextImage: "383"}, }, Phones: []s.Phone{ s.Phone{Position: "1", Number: "+79857621518", Avatar: "4", TextImage: "Андрей1"}, s.Phone{Position: "2", Number: "+79647829211", Avatar: "3", TextImage: "Андрей2"}, s.Phone{Position: "3", Number: "+79160252646", Avatar: "2", TextImage: "Сергей"}, s.Phone{Position: "4", Number: "+79670238554", Avatar: "1", TextImage: "Максим"}, }, } if err := br.SaveData(data); err != nil { t.Error(err) } }