| 1 | //go:build go1.13 |
| 2 | // +build go1.13 |
| 3 | |
| 4 | package socketmode |
| 5 | |
| 6 | import ( |
| 7 | "context" |
| 8 | "errors" |
| 9 | "testing" |
| 10 | "time" |
| 11 | |
| 12 | "github.com/slack-go/slack" |
| 13 | "github.com/slack-go/slack/slacktest" |
| 14 | |
| 15 | "github.com/stretchr/testify/assert" |
| 16 | ) |
| 17 | |
| 18 | func Test_passContext(t *testing.T) { |
| 19 | s := slacktest.NewTestServer() |
| 20 | go s.Start() |
| 21 | |
| 22 | api := slack.New("ABCDEFG", slack.OptionAPIURL(s.GetAPIURL())) |
| 23 | cli := New(api) |
| 24 | |
| 25 | ctx, cancel := context.WithTimeout(context.TODO(), time.Nanosecond) |
| 26 | defer cancel() |
| 27 | |
| 28 | t.Run("RunWithContext", func(t *testing.T) { |
| 29 | // should fail imidiatly. |
| 30 | assert.EqualError(t, cli.RunContext(ctx), context.DeadlineExceeded.Error()) |
| 31 | }) |
| 32 | |
| 33 | t.Run("openAndDial", func(t *testing.T) { |
| 34 | _, _, err := cli.openAndDial(ctx, func(_ string) error { return nil }) |
| 35 | |
| 36 | // should fail imidiatly. |
| 37 | assert.EqualError(t, errors.Unwrap(err), context.DeadlineExceeded.Error()) |
| 38 | }) |
| 39 | |
| 40 | t.Run("OpenWithContext", func(t *testing.T) { |
| 41 | _, _, err := cli.OpenContext(ctx) |
| 42 | |
| 43 | // should fail imidiatly. |
| 44 | assert.EqualError(t, errors.Unwrap(err), context.DeadlineExceeded.Error()) |
| 45 | }) |
| 46 | } |