如何在Golang中将数据发送到通道以进行测试?

I'm trying to write unit tests for functions for a project in Go and I'm coming up against a problem I've never encountered before. The function is used in a loop that monitors Slack (the messaging platform) live for certain event structures (defined by a library I'm using) and responds according depending on the event returned (using a switch). Here's (most of) the code:

func botLoop(s *SlackBot) {
    select {
    case rtmEvent := <-s.Rtm.IncomingEvents:
        switch ev := rtmEvent.Data.(type) {
        case *slack.MessageEvent:

            o, err := s.HandleCommand(ev)
            if err != nil {
                fmt.Printf("%s
", err)
                s.Say(ev.Channel, "%s
", err)
                break
            }
            s.Say(ev.Channel, o)

         case *slack.LatencyReport:
             fmt.Printf("Current latency: %v
", ev.Value)

         default:
             // fmt.Printf("Unexpected: %v
", msg.Data)
    }
}

How can I pass "rtmEvents" into the s.Rtm.IncomingEvent channel to trigger my code for testing purposes? Is there any way to reliably do this?

Here's the documentation for the API library I'm using, if that makes things any easier.

I'm guessing Slackbot is the your custom type. Since RTM is an exported type, for testing you could create a new RTM struct with a new chan. Then using a go routine start sending messages to that channel. And run your function in other go routine which will listen for messages.

Also I suggest replying select with range since you are listening on only one chan