Debian Codegraph @

slacktest/types.go

raw symbols SCIP
1 package slacktest
2
3 import (
4 "log"
5 "net/http"
6 "net/http/httptest"
7 "sync"
8
9 "github.com/slack-go/slack"
10 )
11
12 type contextKey string
13
14 // ServerURLContextKey is the context key to store the server's url
15 const ServerURLContextKey contextKey = "__SERVER_URL__"
16
17 // ServerWSContextKey is the context key to store the server's ws url
18 const ServerWSContextKey contextKey = "__SERVER_WS_URL__"
19
20 // ServerBotNameContextKey is the bot name
21 const ServerBotNameContextKey contextKey = "__SERVER_BOTNAME__"
22
23 // ServerBotIDContextKey is the bot userid
24 const ServerBotIDContextKey contextKey = "__SERVER_BOTID__"
25
26 // ServerBotChannelsContextKey is the list of channels associated with the fake server
27 const ServerBotChannelsContextKey contextKey = "__SERVER_CHANNELS__"
28
29 // ServerBotGroupsContextKey is the list of channels associated with the fake server
30 const ServerBotGroupsContextKey contextKey = "__SERVER_GROUPS__"
31
32 // ServerBotHubNameContextKey is the context key for passing along the server name registered in the hub
33 const ServerBotHubNameContextKey contextKey = "__SERVER_HUBNAME__"
34
35 var masterHub = newHub()
36
37 type hub struct {
38 sync.RWMutex
39 serverChannels map[string]*messageChannels
40 }
41
42 type messageChannels struct {
43 seen chan (string)
44 sent chan (string)
45 posted chan (slack.Message)
46 }
47 type messageCollection struct {
48 sync.RWMutex
49 messages []string
50 }
51
52 type serverChannels struct {
53 sync.RWMutex
54 channels []slack.Channel
55 }
56
57 type serverGroups struct {
58 sync.RWMutex
59 channels []slack.Group
60 }
61
62 // Server represents a Slack Test server
63 type Server struct {
64 registered map[string]struct{}
65 server *httptest.Server
66 mux *http.ServeMux
67 Logger *log.Logger
68 BotName string
69 BotID string
70 ServerAddr string
71 SeenFeed chan (string)
72 channels *serverChannels
73 groups *serverGroups
74 seenInboundMessages *messageCollection
75 seenOutboundMessages *messageCollection
76 }
77
78 type fullInfoSlackResponse struct {
79 slack.Info
80 slack.SlackResponse
81 }