Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the "Binder" type in slacktest #1176

Closed
kpaulisse opened this issue Feb 27, 2023 · 0 comments · Fixed by #1177
Closed

Expose the "Binder" type in slacktest #1176

kpaulisse opened this issue Feb 27, 2023 · 0 comments · Fixed by #1177

Comments

@kpaulisse
Copy link
Contributor

kpaulisse commented Feb 27, 2023

Description

TL;DR: Please change binder to Binder in slacktest/server.go.

The binder type is defined as such in slacktest/server.go:

type binder func(Customize)

This is only used in the signature of func NewTestServer(custom ...binder) *Server.

Due to the order of initialization of the handlers, once a handler is initialized, calling the Handler method again will be ignored. The NewTestServer function initializes a bunch of handlers.

In one of our tests, we wanted to redefine /conversations.info and some others, and the only way we could do so was to supply them like so:

s := slacktest.NewTestServer(
  func(c slacktest.Customize) {
    c.Handle("/chat.postEphemeral", chatPostEphemeralHandler(...))
  },
  func(c slacktest.Customize) {
    c.Handle("/conversations.info", conversationsInfoHandler(...))
  },
  func(c slacktest.Customize) {
    c.Handle("/chat.postMessage", chatPostMessageHandler(...))
  },
)

However this is not amenable to table-driven tests. We'd like to be able to create our own []slacktest.Binder and pass these to slacktest.NewTestServer running in a subtest.

t.Run(testcase.Name, func(t *testing.T) {
  s := slacktest.NewTestServer(testcase.CustomFuncs...)
  // ...
}

However, because binder is private, there is no way to do this.

With Binder exported we can create []slacktest.Binder as an entry in each row of our table-driven tests and then pass this slice to NewTestServer as we would prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant