func TestAdditionalCommands(test *testing.T) { auth := authenticate.NewMemoryAuthenticator() cmds := handlers.GenerateAdditionalCommands(auth) reg := get(cmds, "register") unreg := get(cmds, "unregister") set := get(cmds, "set") unset := get(cmds, "unset") tags := get(cmds, "tags") // the client parameter is not used. if res := reg(nil, []string{"1,2,3,4", "token"}); res != "" { test.Log(res) test.FailNow() } if res := set(nil, []string{"a,b,c,d", "token"}); res != "" { test.Log(res) test.FailNow() } if tags := tags(nil, []string{"token"}); tags == "" { test.Log("wrong tags were returned") test.FailNow() } if res := unset(nil, []string{"a,b,c,d", "token"}); res != "" { test.Log(res) test.FailNow() } if res := unreg(nil, []string{"token"}); res != "" { test.Log(res) test.FailNow() } if tags := tags(nil, []string{"token"}); tags != "error Token not found" { test.Log("wrong tags were returned", tags) test.FailNow() } }
func main() { configFile := "" if len(os.Args) > 1 && !strings.HasPrefix(os.Args[1], "-") { configFile = os.Args[1] } defaults := map[string]string{ "tcp_listen_address": "127.0.0.1:1445", "http_listen_address": "127.0.0.1:8080", "log_level": "INFO", "multicast_interface": "eth1", "pg_user": "******", "pg_database": "postgres", "pg_address": "127.0.0.1:5432", } config.Load(defaults, configFile) level := lumber.LvlInt(config.Config["log_level"]) mist := mist.New() api.Name = "MIST" api.Logger = lumber.NewConsoleLogger(level) api.User = mist user := config.Config["pg_user"] database := config.Config["pg_database"] address := config.Config["pg_address"] pgAuth, err := authenticate.NewPostgresqlAuthenticator(user, database, address) if err != nil { api.Logger.Fatal("unable to start postgresql authenticator %v", err) os.Exit(1) } authCommands := handlers.GenerateAdditionalCommands(pgAuth) listen := config.Config["tcp_listen_address"] server, err := mist.Listen(listen, authCommands) if err != nil { api.Logger.Fatal("unable to start mist tcp listener %v", err) os.Exit(1) } defer server.Close() // start discovering other mist nodes on the network discover, err := discovery.NewDiscovery(config.Config["multicast_interface"], "mist", time.Second*2) if err != nil { panic(err) } defer discover.Close() // advertise this nodes listen address discover.Add("mist", listen) // enable replication between mist nodes replicate := handlers.EnableReplication(mist, discover) go replicate.Monitor() // start up the authenticated websocket connection authenticator := authenticate.NewNoopAuthenticator() handlers.LoadWebsocketRoute(authenticator) api.Start(config.Config["http_listen_address"]) }