func TestMain(m *testing.M) { err := os.Setenv("ABOT_ENV", "test") if err != nil { log.Fatal("failed to set ABOT_ENV.", err) } r, err = core.NewServer() if err != nil { log.Fatal("failed to start abot server.", err) } p, err = plugin.New("testplugin") if err != nil { log.Fatal("failed to build test plugin.", err) } p.Config.Name = "testplugin" p.Trigger = &dt.StructuredInput{ Commands: []string{"get"}, Objects: []string{"result"}, } plugin.SetStates(p, [][]dt.State{ []dt.State{ { OnEntry: func(in *dt.Msg) string { return "entered first" }, OnInput: func(in *dt.Msg) {}, Complete: func(in *dt.Msg) (bool, string) { return true, "" }, }, }, Iterate(p, "", OptsIterate{ IterableMemKey: keyMem, ResultMemKeyIdx: keyRes, }), []dt.State{ { OnEntry: func(in *dt.Msg) string { return "Great!" }, OnInput: func(in *dt.Msg) {}, Complete: func(in *dt.Msg) (bool, string) { return true, "" }, }, }, }) p.SM.SetOnReset(func(in *dt.Msg) { p.DeleteMemory(in, keyMem) p.DeleteMemory(in, keyRes) ResetIterate(p, in) }) if err = plugin.Register(p); err != nil { log.Fatal("failed to register test plugin.", err) } cleanup() exitVal := m.Run() cleanup() os.Exit(exitVal) }
// TestPrepare sets the ABOT_ENV, cleans out the test DB, and initializes the // server for testing. func TestPrepare() *httprouter.Router { if err := os.Setenv("ABOT_ENV", "test"); err != nil { log.Fatal(err) } r, err := core.NewServer() if err != nil { log.Fatal("failed to start abot server.", err) } TestCleanup() return r }