-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #923 from im-kulikov/socketmode-pass-context
[socketmode] Add methods with passing context
- Loading branch information
Showing
4 changed files
with
79 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// +build go1.13 | ||
|
||
package socketmode | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
"time" | ||
|
||
"github.com/slack-go/slack" | ||
"github.com/slack-go/slack/slacktest" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_passContext(t *testing.T) { | ||
s := slacktest.NewTestServer() | ||
go s.Start() | ||
|
||
api := slack.New("ABCDEFG", slack.OptionAPIURL(s.GetAPIURL())) | ||
cli := New(api) | ||
|
||
ctx, cancel := context.WithTimeout(context.TODO(), time.Nanosecond) | ||
defer cancel() | ||
|
||
t.Run("RunWithContext", func(t *testing.T) { | ||
// should fail imidiatly. | ||
assert.EqualError(t, cli.RunContext(ctx), context.DeadlineExceeded.Error()) | ||
}) | ||
|
||
t.Run("openAndDial", func(t *testing.T) { | ||
_, _, err := cli.openAndDial(ctx, func(_ string) error { return nil }) | ||
|
||
// should fail imidiatly. | ||
assert.EqualError(t, errors.Unwrap(err), context.DeadlineExceeded.Error()) | ||
}) | ||
|
||
t.Run("OpenWithContext", func(t *testing.T) { | ||
_, _, err := cli.OpenContext(ctx) | ||
|
||
// should fail imidiatly. | ||
assert.EqualError(t, errors.Unwrap(err), context.DeadlineExceeded.Error()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters