func TestMain(m *testing.M) { tempdir, err := ioutil.TempDir("", "test_") if err != nil { log.Fatal(err) } os.Mkdir(path.Join(tempdir, "logs"), 0777) storage.Initialize(tempdir) user = storage.NewUser("uuid") channelStore = storage.NewChannelStore() code := m.Run() os.RemoveAll(tempdir) os.Exit(code) }
func (h *wsHandler) init(b []byte) { json.Unmarshal(b, &h.uuid) log.Println(h.addr, "set UUID", h.uuid) sessionLock.Lock() if storedSession, exists := sessions[h.uuid]; exists { sessionLock.Unlock() h.session = storedSession h.session.setWS(h.addr, h.ws) log.Println(h.addr, "attached to", h.session.numIRC(), "existing IRC connections") channels := h.session.user.GetChannels() for i, channel := range channels { channels[i].Topic = channelStore.GetTopic(channel.Server, channel.Name) } h.session.sendJSON("channels", channels) h.session.sendJSON("servers", h.session.user.GetServers()) for _, channel := range channels { h.session.sendJSON("users", Userlist{ Server: channel.Server, Channel: channel.Name, Users: channelStore.GetUsers(channel.Server, channel.Name), }) } } else { h.session = NewSession() h.session.user = storage.NewUser(h.uuid) sessions[h.uuid] = h.session sessionLock.Unlock() h.session.setWS(h.addr, h.ws) h.session.sendJSON("servers", nil) go h.session.write() } }