Skip to content

Commit

Permalink
feat: use go string padding (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusprubio authored Jun 26, 2024
1 parent 0504f7e commit 408a3a3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ func Fatal(err error) {

// ReportToLine returns a human-readable representation of the report.
func ReportToLine(r *pkg.Report) string {
// TODO(#40): Use Go string padding.
line := fmt.Sprintf("%s\t%s\t%s", bold(r.ProtocolID), r.Time, r.RHost)
line := fmt.Sprintf("%-15s %-14s %s", bold(r.ProtocolID), r.Time, r.RHost)
suffix := r.Extra
prefix := green("✔")
if r.Error != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ func TestReportToLine(t *testing.T) {
}
t.Run("return success line if no error happened", func(t *testing.T) {
got := ReportToLine(r)
want := "✔ test\t1s\ttest (test)"
want := "✔ test 1s test (test)"
if got != want {
t.Fatalf("got %q, want %q", got, want)
}
})
t.Run("return error line if an error happened", func(t *testing.T) {
r.Error = errors.New("probe error")
got := ReportToLine(r)
want := "✘ test\t1s\ttest (probe error)"
want := "✘ test 1s test (probe error)"
if got != want {
t.Fatalf("got %q, want %q", got, want)
}
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
// TODO(#37): Debug and verbose should not be the same thing.
lvl.Set(slog.LevelDebug)
}
logger.Debug("Starting", "options", opts)
logger.Debug("Starting ...", "options", opts)
protocols := pkg.Protocols
if opts.Protocol != "" {
protocol := internal.ProtocolByID(opts.Protocol)
Expand All @@ -42,7 +42,7 @@ func main() {
}
protocols = []*pkg.Protocol{protocol}
}
logger.Info("Running", "protocols", protocols, "count", opts.Count)
logger.Info("Starting ...", "protocols", protocols, "count", opts.Count)
if opts.Help {
fmt.Fprintf(os.Stderr, "%s\n", internal.AppDesc)
flag.Usage()
Expand Down Expand Up @@ -74,7 +74,7 @@ func main() {
ReportCh: reportCh,
}
go func() {
logger.Debug("Listening for reports")
logger.Debug("Listening for reports ...")
for report := range probe.ReportCh {
logger.Debug("New report", "report", *report)
var line string
Expand All @@ -96,7 +96,7 @@ func main() {
}
}
}()
logger.Debug("Running", "setup", probe)
logger.Debug("Running ...", "setup", probe)
err := probe.Run(ctx)
if err != nil {
internal.Fatal(fmt.Errorf("running probe: %w", err))
Expand Down

0 comments on commit 408a3a3

Please sign in to comment.