slacktest

package
Version: v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2021 License: BSD-2-Clause Imports: 13 Imported by: 3

README

slacktest

This package was copied from https://github.com/lusis/slack-test for historical reasons.
This package's license is the following.


Copyright 2018 @lusis

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

View Source
const (
	// ErrEmptyServerToHub is the error when attempting an empty server address to the hub
	ErrEmptyServerToHub = errorsx.String("Unable to add an empty server address to hub")
	// ErrPassedEmptyServerAddr is the error when being passed an empty server address
	ErrPassedEmptyServerAddr = errorsx.String("Passed an empty server address")
	// ErrNoQueuesRegisteredForServer is the error when there are no queues for a server in the hub
	ErrNoQueuesRegisteredForServer = errorsx.String("No queues registered for server")
)
View Source
const ServerBotChannelsContextKey contextKey = "__SERVER_CHANNELS__"

ServerBotChannelsContextKey is the list of channels associated with the fake server

View Source
const ServerBotGroupsContextKey contextKey = "__SERVER_GROUPS__"

ServerBotGroupsContextKey is the list of channels associated with the fake server

View Source
const ServerBotHubNameContextKey contextKey = "__SERVER_HUBNAME__"

ServerBotHubNameContextKey is the context key for passing along the server name registered in the hub

View Source
const ServerBotIDContextKey contextKey = "__SERVER_BOTID__"

ServerBotIDContextKey is the bot userid

View Source
const ServerBotNameContextKey contextKey = "__SERVER_BOTNAME__"

ServerBotNameContextKey is the bot name

View Source
const ServerURLContextKey contextKey = "__SERVER_URL__"

ServerURLContextKey is the context key to store the server's url

View Source
const ServerWSContextKey contextKey = "__SERVER_WS_URL__"

ServerWSContextKey is the context key to store the server's ws url

Variables

This section is empty.

Functions

func BotIDFromContext

func BotIDFromContext(ctx context.Context) string

BotIDFromContext returns the bot userid from a provided context

func BotNameFromContext

func BotNameFromContext(ctx context.Context) string

BotNameFromContext returns the botname from a provided context

func RTMConnectHandler

func RTMConnectHandler(w http.ResponseWriter, r *http.Request)

RTMConnectHandler generates a valid connection

func RTMRespEventType

func RTMRespEventType(c *websocket.Conn) (t string, m json.RawMessage, err error)

RTMRespEventType retrieve the event type from the next message

func RTMRespPong

func RTMRespPong(c *websocket.Conn, m json.RawMessage) (err error)

RTMRespPong decode a ping and respond with a pong event.

func RTMServerSendGoodbye

func RTMServerSendGoodbye(c *websocket.Conn) error

RTMServerSendGoodbye send a goodbye event

func Websocket

func Websocket(delegate func(c *websocket.Conn)) func(w http.ResponseWriter, r *http.Request)

Websocket handler

Types

type Customize

type Customize interface {
	Handle(pattern string, handler http.HandlerFunc)
}

Customize the server's responses.

type GroupConversationResponse added in v0.6.6

type GroupConversationResponse struct {
	Ok      bool                    `json:"ok"`
	Channel slack.GroupConversation `json:"channel"`
}

type Server

type Server struct {
	Logger     *log.Logger
	BotName    string
	BotID      string
	ServerAddr string
	SeenFeed   chan (string)
	// contains filtered or unexported fields
}

Server represents a Slack Test server

func NewTestServer

func NewTestServer(custom ...binder) *Server

NewTestServer returns a slacktest.Server ready to be started

func (*Server) GetAPIURL

func (sts *Server) GetAPIURL() string

GetAPIURL returns the api url you can pass to slack.SLACK_API

func (*Server) GetChannels

func (sts *Server) GetChannels() []slack.Channel

GetChannels returns all the fake channels registered

func (*Server) GetGroups

func (sts *Server) GetGroups() []slack.Group

GetGroups returns all the fake groups registered

func (*Server) GetSeenInboundMessages

func (sts *Server) GetSeenInboundMessages() []string

GetSeenInboundMessages returns all messages seen via websocket excluding pings

func (*Server) GetSeenOutboundMessages

func (sts *Server) GetSeenOutboundMessages() []string

GetSeenOutboundMessages returns all messages seen via websocket excluding pings

func (*Server) GetTestRTMInstance

func (sts *Server) GetTestRTMInstance() *slack.RTM

GetTestRTMInstance will give you an RTM instance in the context of the current fake server

func (*Server) GetWSURL

func (sts *Server) GetWSURL() string

GetWSURL returns the websocket url

func (*Server) Handle

func (sts *Server) Handle(pattern string, handler http.HandlerFunc)

Handle allow for customizing endpoints

func (*Server) SawMessage

func (sts *Server) SawMessage(msg string) bool

SawMessage checks if an incoming message was seen

func (*Server) SawOutgoingMessage

func (sts *Server) SawOutgoingMessage(msg string) bool

SawOutgoingMessage checks if a message was sent to connected websocket clients

func (*Server) SendBotChannelInvite

func (sts *Server) SendBotChannelInvite()

SendBotChannelInvite invites the bot to a channel

func (*Server) SendBotGroupInvite

func (sts *Server) SendBotGroupInvite()

SendBotGroupInvite invites the bot to a channel

func (*Server) SendDirectMessageToBot

func (sts *Server) SendDirectMessageToBot(msg string)

SendDirectMessageToBot sends a direct message to the bot

func (*Server) SendMessageToBot

func (sts *Server) SendMessageToBot(channel, msg string)

SendMessageToBot sends a message addressed to the Bot

func (*Server) SendMessageToChannel

func (sts *Server) SendMessageToChannel(channel, msg string)

SendMessageToChannel sends a message to a channel

func (*Server) SendToWebsocket

func (sts *Server) SendToWebsocket(s string)

SendToWebsocket send `s` as is to connected clients. This is useful for sending your own custom json to the websocket

func (*Server) SetBotName

func (sts *Server) SetBotName(b string)

SetBotName sets a custom botname

func (*Server) Start

func (sts *Server) Start()

Start starts the test server

func (*Server) Stop

func (sts *Server) Stop()

Stop stops the test server

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL