Skip to content

Commit

Permalink
extract stream functions from clienter
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Mar 22, 2023
1 parent 923d55c commit 0c9b3ea
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 24 deletions.
119 changes: 104 additions & 15 deletions clienter_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions slackdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,21 @@ type Session struct {
// WorkspaceInfo is an type alias for [slack.AuthTestResponse].
type WorkspaceInfo = slack.AuthTestResponse

// clienter is the interface with some functions of slack.Client with the sole
// purpose of mocking in tests (see client_mock.go)
type clienter interface {
type streamer interface {
GetConversationInfoContext(ctx context.Context, input *slack.GetConversationInfoInput) (*slack.Channel, error)
GetConversationHistoryContext(ctx context.Context, params *slack.GetConversationHistoryParameters) (*slack.GetConversationHistoryResponse, error)
GetConversationRepliesContext(ctx context.Context, params *slack.GetConversationRepliesParameters) (msgs []slack.Message, hasMore bool, nextCursor string, err error)
GetConversationsContext(ctx context.Context, params *slack.GetConversationsParameters) (channels []slack.Channel, nextCursor string, err error)
GetUsersPaginated(options ...slack.GetUsersOption) slack.UserPagination
}

// clienter is the interface with some functions of slack.Client with the sole
// purpose of mocking in tests (see client_mock.go)
type clienter interface {
streamer
GetFile(downloadURL string, writer io.Writer) error
GetTeamInfoContext(ctx context.Context) (*slack.TeamInfo, error)
GetUsersContext(ctx context.Context, options ...slack.GetUsersOption) ([]slack.User, error)
GetEmojiContext(ctx context.Context) (map[string]string, error)
GetUsersPaginated(options ...slack.GetUsersOption) slack.UserPagination
}

// ErrNoUserCache is returned when the user cache is not initialised.
Expand Down
9 changes: 5 additions & 4 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

type Stream struct {
oldest, latest time.Time
client clienter
client streamer
limits rateLimits
}

Expand Down Expand Up @@ -81,7 +81,7 @@ func OptLatest(t time.Time) StreamOption {
}
}

func newChannelStream(cl clienter, l *Limits, opts ...StreamOption) *Stream {
func newChannelStream(cl streamer, l *Limits, opts ...StreamOption) *Stream {
cs := &Stream{
client: cl,
limits: limits(l),
Expand Down Expand Up @@ -463,11 +463,12 @@ func (cs *Stream) channelInfo(ctx context.Context, proc processor.Conversations,
return nil
}

func (cs *Stream) Users(ctx context.Context, proc processor.Users) error {
// Users returns all users in the workspace.
func (cs *Stream) Users(ctx context.Context, proc processor.Users, opt ...slack.GetUsersOption) error {
ctx, task := trace.NewTask(ctx, "Users")
defer task.End()

p := cs.client.GetUsersPaginated()
p := cs.client.GetUsersPaginated(opt...)
var apiErr error
for apiErr == nil {
if apiErr = network.WithRetry(ctx, cs.limits.users, cs.limits.tier.Tier2.Retries, func() error {
Expand Down

0 comments on commit 0c9b3ea

Please sign in to comment.