diff --git a/internal/app/app.go b/internal/app/app.go index 6572186b..2a931703 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -148,7 +148,8 @@ func (app *App) saveText(filename string, m *slackdump.Conversation) error { return m.ToText(app.sd, f) } -// listEntities queries lists the supported entities, and writes the output to output. +// listEntities queries lists the supported entities, and writes the output to +// the output defined in the app.cfg. func (app *App) listEntities(ctx context.Context) error { f, err := createFile(app.cfg.Output.Filename) if err != nil { @@ -207,7 +208,7 @@ func (app *App) fetchEntity(ctx context.Context, listFlags ListFlags) (rep slack return } -// formatEntity formats the entity according to output specification. +// formatEntity formats the entity according to output parameter value. func (app *App) formatEntity(w io.Writer, rep slackdump.Reporter, output Output) error { switch output.Format { case OutputTypeText: diff --git a/internal/app/timevalue.go b/internal/app/timevalue.go index 387f6d7b..bcef015b 100644 --- a/internal/app/timevalue.go +++ b/internal/app/timevalue.go @@ -17,7 +17,7 @@ func (tv *TimeValue) Set(s string) error { if s == "" { return nil } - if t, err := time.Parse(s, timeFmt); err != nil { + if t, err := time.Parse(timeFmt, s); err != nil { return err } else { *tv = TimeValue(t) diff --git a/internal/app/timevalue_test.go b/internal/app/timevalue_test.go new file mode 100644 index 00000000..b0b57d0e --- /dev/null +++ b/internal/app/timevalue_test.go @@ -0,0 +1,43 @@ +package app + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func tv(t time.Time) *TimeValue { + tv := TimeValue(t) + return &tv +} + +func TestTimeValue_Set(t *testing.T) { + type args struct { + s string + } + tests := []struct { + name string + tv *TimeValue + args args + wantTime *TimeValue + wantErr bool + }{ + { + "valid value", + &TimeValue{}, + args{"2009-09-16T20:30:40"}, + tv(time.Date(2009, 9, 16, 20, 30, 40, 0, time.UTC)), + false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tv := &TimeValue{} + if err := tv.Set(tt.args.s); (err != nil) != tt.wantErr { + t.Errorf("TimeValue.Set() error = %v, wantErr %v", err, tt.wantErr) + } + assert.Equal(t, tt.wantTime, tv) + }) + } +}