Skip to content

Commit

Permalink
rollback emoji test
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Nov 23, 2024
1 parent d15d0ef commit 5c57406
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 75 deletions.
16 changes: 0 additions & 16 deletions clienter_mock_test.go

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

12 changes: 5 additions & 7 deletions cmd/slackdump/internal/emoji/emojidl/emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"sync"

"github.com/rusq/fsadapter"
"github.com/rusq/slack"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg"
)

Expand All @@ -40,13 +39,12 @@ var fetchFn = fetchEmoji

//go:generate mockgen -source emoji.go -destination emoji_mock_test.go -package emojidl
type emojidumper interface {
// DumpEmojis(ctx context.Context) (map[string]string, error)
DumpEmojisAdmin(ctx context.Context) (map[string]slack.Emoji, error)
DumpEmojis(ctx context.Context) (map[string]string, error)
}

// DlFS downloads all emojis from the workspace and saves them to the fsa.
func DlFS(ctx context.Context, sess emojidumper, fsa fsadapter.FS, failFast bool) error {
emojis, err := sess.DumpEmojisAdmin(ctx)
emojis, err := sess.DumpEmojis(ctx)
if err != nil {
return fmt.Errorf("error during emoji dump: %w", err)
}
Expand All @@ -64,7 +62,7 @@ func DlFS(ctx context.Context, sess emojidumper, fsa fsadapter.FS, failFast bool

// fetch downloads the emojis and saves them to the fsa. It spawns numWorker
// goroutines for getting the files. It will call fetchFn for each emoji.
func fetch(ctx context.Context, fsa fsadapter.FS, emojis map[string]slack.Emoji, failFast bool) error {
func fetch(ctx context.Context, fsa fsadapter.FS, emojis map[string]string, failFast bool) error {
lg := cfg.Log.With("in", "fetch", "dir", emojiDir, "numWorkers", numWorkers, "failFast", failFast)

var (
Expand All @@ -77,11 +75,11 @@ func fetch(ctx context.Context, fsa fsadapter.FS, emojis map[string]slack.Emoji,
// 1. generator, send emojis into the emojiC channel.
go func() {
defer close(emojiC)
for name, em := range emojis {
for name, uri := range emojis {
select {
case <-ctx.Done():
return
case emojiC <- emoji{name, em.URL}:
case emojiC <- emoji{name, uri}:
}
}
}()
Expand Down
15 changes: 7 additions & 8 deletions cmd/slackdump/internal/emoji/emojidl/emoji_mock_test.go

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

27 changes: 13 additions & 14 deletions cmd/slackdump/internal/emoji/emojidl/emoji_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"go.uber.org/mock/gomock"

"github.com/rusq/fsadapter"
"github.com/rusq/slack"
)

type fetchFunc func(ctx context.Context, fsa fsadapter.FS, dir string, name string, uri string) error
Expand Down Expand Up @@ -226,10 +225,10 @@ func Test_fetch(t *testing.T) {
}
}

func generateEmojis(n int) (ret map[string]slack.Emoji) {
ret = make(map[string]slack.Emoji, n)
func generateEmojis(n int) (ret map[string]string) {
ret = make(map[string]string, n)
for i := 0; i < n; i++ {
ret[randString(10)] = slack.Emoji{URL: "https://emoji.slack.com/" + randString(20)}
ret[randString(10)] = "https://emoji.slack.com/" + randString(20)
}
return
}
Expand Down Expand Up @@ -269,9 +268,9 @@ func Test_download(t *testing.T) {
emptyFetchFn,
func(m *Mockemojidumper) {
m.EXPECT().
DumpEmojisAdmin(gomock.Any()).
Return(map[string]slack.Emoji{
"test": {URL: "https://blahblah.png"},
DumpEmojis(gomock.Any()).
Return(map[string]string{
"test": "https://blahblah.png",
}, nil)
},
false,
Expand All @@ -286,9 +285,9 @@ func Test_download(t *testing.T) {
emptyFetchFn,
func(m *Mockemojidumper) {
m.EXPECT().
DumpEmojisAdmin(gomock.Any()).
Return(map[string]slack.Emoji{
"test": {URL: "https://blahblah.png"},
DumpEmojis(gomock.Any()).
Return(map[string]string{
"test": "https://blahblah.png",
}, nil)
},
false,
Expand All @@ -303,9 +302,9 @@ func Test_download(t *testing.T) {
errorFetchFn,
func(m *Mockemojidumper) {
m.EXPECT().
DumpEmojisAdmin(gomock.Any()).
Return(map[string]slack.Emoji{
"test": {URL: "https://blahblah.png"},
DumpEmojis(gomock.Any()).
Return(map[string]string{
"test": "https://blahblah.png",
}, nil)
},
true,
Expand All @@ -320,7 +319,7 @@ func Test_download(t *testing.T) {
errorFetchFn,
func(m *Mockemojidumper) {
m.EXPECT().
DumpEmojisAdmin(gomock.Any()).
DumpEmojis(gomock.Any()).
Return(nil, errors.New("no emojis for you, it's 1991."))
},
true,
Expand Down
22 changes: 0 additions & 22 deletions emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package slackdump

import (
"context"

"github.com/rusq/slack"
)

func (s *Session) DumpEmojis(ctx context.Context) (map[string]string, error) {
Expand All @@ -13,23 +11,3 @@ func (s *Session) DumpEmojis(ctx context.Context) (map[string]string, error) {
}
return emoji, nil
}

func (s *Session) DumpEmojisAdmin(ctx context.Context) (map[string]slack.Emoji, error) {
var ret = make(map[string]slack.Emoji, 100)

p := slack.AdminEmojiListParameters{Cursor: "", Limit: 100}
for {
emoji, next, err := s.client.AdminEmojiList(ctx, p)
if err != nil {
return nil, err
}
for k, v := range emoji {
ret[k] = v
}
if next == "" {
break
}
p.Cursor = next
}
return ret, nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/rusq/fsadapter v1.0.2
github.com/rusq/osenv/v2 v2.0.1
github.com/rusq/rbubbles v0.0.2
github.com/rusq/slack v0.9.6-0.20241122224849-576a79dc22f1
github.com/rusq/slack v0.9.6-0.20241117083852-278084780c45
github.com/rusq/slackauth v0.5.1
github.com/rusq/tagops v0.0.2
github.com/rusq/tracer v1.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ github.com/rusq/secure v0.0.4 h1:svpiZHfHnx89eEDCCFI9OXG1Y8hL9kUWUG6fJbrWUOI=
github.com/rusq/secure v0.0.4/go.mod h1:F1QilMKreuFRjov0UY7DZSIXn77/8RqMVGu2zV0RtqY=
github.com/rusq/slack v0.9.6-0.20241104074952-d9b6e02955fa h1:meNaDH2eLwjAqvOxMlgb5+gaLz3Kufm9rVFkALhsCRs=
github.com/rusq/slack v0.9.6-0.20241104074952-d9b6e02955fa/go.mod h1:9O0zQAFN6W47z4KpTQbe6vOHOzBO76vMg1+gthPwaTI=
github.com/rusq/slack v0.9.6-0.20241117083852-278084780c45 h1:tsZKbEaziqVowGaQ7zRsrxpy9JDk6CCkihR5PrMk48s=
github.com/rusq/slack v0.9.6-0.20241117083852-278084780c45/go.mod h1:9O0zQAFN6W47z4KpTQbe6vOHOzBO76vMg1+gthPwaTI=
github.com/rusq/slack v0.9.6-0.20241122224849-576a79dc22f1 h1:70BrReHUHQ/ERHqGxUgXJrlXKE5jA++bzo+F9Q2b9Pw=
github.com/rusq/slack v0.9.6-0.20241122224849-576a79dc22f1/go.mod h1:9O0zQAFN6W47z4KpTQbe6vOHOzBO76vMg1+gthPwaTI=
github.com/rusq/slackauth v0.5.1 h1:l+Gj96kYzHmljMYglRv76kgzuOJr/QbXDDA8JHyN71Q=
Expand Down
3 changes: 2 additions & 1 deletion internal/edge/emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type adminEmojiListRequest struct {
Paging
}

// AdminEmojiList returns a list of custom emoji for the workspace.
func (cl *Client) AdminEmojiList(ctx context.Context) (EmojiResult, error) {
var res EmojiResult
req := adminEmojiListRequest{
Expand All @@ -64,7 +65,7 @@ func (cl *Client) AdminEmojiList(ctx context.Context) (EmojiResult, error) {
},
WebClientFields: webclientReason("customize-emoji-new-query"),
}
l := tier3.limiter()
l := tier2boost.limiter()
for {
resp, err := cl.Post(ctx, "emoji.adminList", req)
if err != nil {
Expand Down
5 changes: 0 additions & 5 deletions internal/edge/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,3 @@ func (w *Wrapper) SearchMessagesContext(ctx context.Context, query string, param
func (w *Wrapper) SearchFilesContext(ctx context.Context, query string, params slack.SearchParameters) (*slack.SearchFiles, error) {
return w.cl.SearchFilesContext(ctx, query, params)
}

func (w *Wrapper) AdminEmojiList(ctx context.Context, params slack.AdminEmojiListParameters) (map[string]slack.Emoji, string, error) {
// TODO: switch to edge client
return w.cl.AdminEmojiList(ctx, params)
}
1 change: 0 additions & 1 deletion slackdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ type clienter interface {
GetFile(downloadURL string, writer io.Writer) error
GetUsersContext(ctx context.Context, options ...slack.GetUsersOption) ([]slack.User, error)
GetEmojiContext(ctx context.Context) (map[string]string, error)
AdminEmojiList(ctx context.Context, params slack.AdminEmojiListParameters) (map[string]slack.Emoji, string, error)
}

// ErrNoUserCache is returned when the user cache is not initialised.
Expand Down

0 comments on commit 5c57406

Please sign in to comment.