diff --git a/internal/chunk/control/control.go b/internal/chunk/control/control.go index ab4ff2a1..69d19354 100644 --- a/internal/chunk/control/control.go +++ b/internal/chunk/control/control.go @@ -107,7 +107,7 @@ type Error struct { } func (e Error) Error() string { - return fmt.Sprintf("controller error in %s on %s: %v", e.Subroutine, e.Stage, e.Err) + return fmt.Sprintf("controller error in subroutine %s on stage %s: %v", e.Subroutine, e.Stage, e.Err) } func (c *Controller) Run(ctx context.Context, list *structures.EntityList) error { diff --git a/internal/chunk/directory.go b/internal/chunk/directory.go index 1dc6c309..f2282eea 100644 --- a/internal/chunk/directory.go +++ b/internal/chunk/directory.go @@ -16,7 +16,7 @@ import ( "github.com/slack-go/slack" ) -const ext = ".json.gz" +const chunkExt = ".json.gz" // common filenames const ( @@ -119,7 +119,7 @@ func (d *Directory) Channels() ([]slack.Channel, error) { if err != nil { return err } - if !strings.HasSuffix(path, ext) { + if !strings.HasSuffix(path, chunkExt) { return nil } else if de.IsDir() { return nil @@ -145,6 +145,7 @@ func (d *Directory) Name() string { return d.dir } +// loadChanInfo loads the channel info from the file with full path. func (d *Directory) loadChanInfo(fullpath string) ([]slack.Channel, error) { f, err := d.openRAW(fullpath) if err != nil { @@ -255,7 +256,7 @@ func openfile(filename string) (*os.File, error) { // filename returns the full path of the chunk file with the given fileID. func (d *Directory) filename(id FileID) string { - return filepath.Join(d.dir, string(id)+ext) + return filepath.Join(d.dir, string(id)+chunkExt) } // Create creates the chunk file with the given name. Extension is appended diff --git a/internal/chunk/file.go b/internal/chunk/file.go index 9339f089..b1a1290b 100644 --- a/internal/chunk/file.go +++ b/internal/chunk/file.go @@ -136,6 +136,9 @@ func caller(steps int) string { return name } +// ensure ensures that the file index was generated. +// +// TODO: maybe it shouldn't panic. func (f *File) ensure() { if f.idx == nil { log.Panicf("internal error: %s called before File.Open", caller(1)) @@ -267,9 +270,20 @@ func (p *File) AllChannels() ([]slack.Channel, error) { // info API. func (f *File) AllChannelInfos() ([]slack.Channel, error) { f.ensure() - return allForOffsets(f, f.idx.offsetsWithPrefix(chanInfoPrefix), func(c *Chunk) []slack.Channel { + chans, err := allForOffsets(f, f.idx.offsetsWithPrefix(chanInfoPrefix), func(c *Chunk) []slack.Channel { return []slack.Channel{*c.Channel} }) + if err != nil { + return nil, err + } + for i := range chans { + members, err := f.ChannelUsers(chans[i].ID) + if err != nil { + return nil, err + } + chans[i].Members = members + } + return chans, nil } // AllChannelInfoWithMembers returns all channels with Members populated. diff --git a/internal/chunk/file_test.go b/internal/chunk/file_test.go index 679a5529..7b4cb4c7 100644 --- a/internal/chunk/file_test.go +++ b/internal/chunk/file_test.go @@ -713,6 +713,12 @@ func mkindex(rs io.ReadSeeker) index { } func TestFile_AllChannelInfos(t *testing.T) { + c0wus := *testChunks[0].Channel + c0wus.Members = testChunks[1].ChannelUsers + + c6wus := *testChunks[6].Channel + c6wus.Members = testChunks[7].ChannelUsers + type fields struct { rs io.ReadSeeker } @@ -728,8 +734,8 @@ func TestFile_AllChannelInfos(t *testing.T) { rs: marshalChunks(testChunks...), }, []slack.Channel{ - *testChunks[0].Channel, - *testChunks[6].Channel, + c0wus, + c6wus, }, false, }, @@ -745,9 +751,7 @@ func TestFile_AllChannelInfos(t *testing.T) { t.Errorf("File.AllChannelInfos() error = %v, wantErr %v", err, tt.wantErr) return } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("File.AllChannelInfos() = %v, want %v", got, tt.want) - } + assert.Equal(t, tt.want, got) }) } }