func main() { cs := configuration.NewCommandsStorage("localhost:27017", "bot") SUBSCRIBED, _ := cs.LoadCommands(quests.PROVIDER, quests.SUBSCRIBED) log.Printf("SUBSCRIBED COMMANDS: %+v", SUBSCRIBED) UNSUBSCRIBED, _ := cs.LoadCommands(quests.PROVIDER, quests.UNSUBSCRIBED) log.Printf("UNSUBSCRIBED COMMANDS: %+v", UNSUBSCRIBED) for _, here := range QUEST_SUBSCRIBED_COMMANDS { for _, db := range SUBSCRIBED { log.Printf("subscribed : %v\n db: %v, here: %v", here.String() == db.String(), db, here) } } for _, here := range QUEST_NOT_SUBSCRIBED_COMMANDS { for _, db := range UNSUBSCRIBED { log.Printf("unsubscribed: %v\n db: %v, here: %v", here.String() == db.String(), db, here) } } }
func TestMessageProcessor(t *testing.T) { conf := configuration.ReadConfigInRecursive() conf.Main.Database.Name = conf.Main.Database.Name + "_autotest" qs := NewQuestStorage(conf.Main.Database.ConnString, conf.Main.Database.Name) cs := configuration.NewCommandsStorage(conf.Main.Database.ConnString, conf.Main.Database.Name) qp := QuestMessageProcessor{Storage: qs, ConfigStorage: cs} prep_keys(qs) k, d := kd(0, 0) out := qp.ProcessMessage(prep_pack("U1", k)) if !strings.Contains(out.Body, d) { t.Error("First key not found %v", out.Body) } k, d = kd(1, 0) out = qp.ProcessMessage(prep_pack("U1", k)) if !strings.Contains(out.Body, d) { t.Error("Next key not found %v", out.Body) } k, d = kd(0, 0) out = qp.ProcessMessage(prep_pack("U1", k)) if !strings.Contains(out.Body, d) { t.Error("Next key not found %v", out.Body) } k, d = kd(1, 0) out = qp.ProcessMessage(prep_pack("U1", k)) if !strings.Contains(out.Body, d) { t.Error("Next key not found %v", out.Body) } k, d = kd(1, 0) out = qp.ProcessMessage(prep_pack("U1", k)) if !strings.Contains(out.Body, d) { t.Error("Next key not found %v", out.Body) } k, d = kd(0, 1) out = qp.ProcessMessage(prep_pack("U1", k)) if !strings.Contains(out.Body, d) { t.Error("Go to another command err %v", out.Body) } k, d = kd(2, 0) out = qp.ProcessMessage(prep_pack("U1", k)) if strings.Contains(out.Body, d) { t.Error("From ahother command you can not send keys 2 %v", out.Body) } k, d = kd(1, 0) out = qp.ProcessMessage(prep_pack("U1", k)) if strings.Contains(out.Body, d) { t.Error("From ahother command you can not send keys 1 %v", out.Body) } k, d = kd(0, 0) out = qp.ProcessMessage(prep_pack("U1", k)) if !strings.Contains(out.Body, d) { t.Error("Go to first command err %v", out.Body) } k, d = kd(1, 1) out = qp.ProcessMessage(prep_pack("U1", k)) if strings.Contains(out.Body, d) { t.Error("Can not send code of another team %v", out.Body) } k, d = kd(1, 2) out = qp.ProcessMessage(prep_pack("U1", k)) if strings.Contains(out.Body, d) { t.Error("Can not send code of another team %v", out.Body) } k, d = kd(1, 2) out = qp.ProcessMessage(prep_pack("U2", k)) if strings.Contains(out.Body, d) { t.Error("you must register at first 2 %v", out.Body) } k, d = kd(1, 1) out = qp.ProcessMessage(prep_pack("U2", k)) if strings.Contains(out.Body, d) { t.Error("you must register at first 1 %v", out.Body) } k, d = kd(1, 0) out = qp.ProcessMessage(prep_pack("U2", k)) if strings.Contains(out.Body, d) { t.Error("you must register at first 0 %v", out.Body) } k, d = kd(0, 0) out = qp.ProcessMessage(prep_pack("U2", k)) if !strings.Contains(out.Body, d) { t.Error("Next user not adding to team 0 %v", out.Body) } k, d = kd(1, 0) out = qp.ProcessMessage(prep_pack("U2", k)) if !strings.Contains(out.Body, d) { t.Error("Next user can not send next key to team 0 %v", out.Body) } k, d = kd(0, 1) out = qp.ProcessMessage(prep_pack("U2", k)) if !strings.Contains(out.Body, d) { t.Error("Next user go to another team to team 1 %v", out.Body) } }