From e41e5255cd14d837a0d4c28122a0780a9065ce45 Mon Sep 17 00:00:00 2001 From: streambinder Date: Fri, 6 Sep 2024 18:10:13 +0200 Subject: [PATCH] chore: lint --- cmd/sync.go | 2 +- util/anchor/lot.go | 12 ++++++++---- util/random.go | 19 ------------------- util/random_test.go | 26 -------------------------- 4 files changed, 9 insertions(+), 50 deletions(-) delete mode 100644 util/random.go delete mode 100644 util/random_test.go diff --git a/cmd/sync.go b/cmd/sync.go index b4ee8e2..cd02ae6 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -329,7 +329,7 @@ func routineCollect(ctx context.Context, ch chan error) { // to the (meta)data fetched from upstream func routineCollectAsset(track *entity.Track) func(context.Context, chan error) { return func(ctx context.Context, ch chan error) { - tui.Lot("download").Printf(track.UpstreamURL) + tui.Lot("download").Print(track.UpstreamURL) if err := downloader.Download(track.UpstreamURL, track.Path().Download(), nil); err != nil { tui.AnchorPrintf("download failure: %s", err) ch <- err diff --git a/util/anchor/lot.go b/util/anchor/lot.go index 9dfce0f..7b0ec20 100644 --- a/util/anchor/lot.go +++ b/util/anchor/lot.go @@ -23,12 +23,12 @@ func formatAlias(alias string) string { return fmt.Sprintf("(%s) ", alias) } -func (lot *lot) Printf(format string, a ...any) { +func (lot *lot) Print(message string) { lot.window.lock.Lock() defer lot.window.lock.Unlock() defer cursor.Bottom() - lot.data = fmt.Sprintf(format, a...) + lot.data = message lot.window.up(len(lot.window.lots)) for _, lot := range lot.window.lots { lot.write() @@ -36,13 +36,17 @@ func (lot *lot) Printf(format string, a ...any) { } } +func (lot *lot) Printf(format string, a ...any) { + lot.Print(fmt.Sprintf(format, a...)) +} + func (lot *lot) Wipe() { - lot.Printf(idle) + lot.Print(idle) } func (lot *lot) Close(messages ...string) { lot.style = color.New(color.FgWhite) - lot.Printf(util.First(messages, "done")) + lot.Print(util.First(messages, "done")) } func (lot *lot) write() { diff --git a/util/random.go b/util/random.go deleted file mode 100644 index eff821b..0000000 --- a/util/random.go +++ /dev/null @@ -1,19 +0,0 @@ -package util - -import ( - crand "crypto/rand" - "encoding/binary" - mrand "math/rand" -) - -func init() { - seed() -} - -func seed() { - var b [8]byte - if ErrOnly(crand.Read(b[:])) != nil { - panic("cannot seed math/rand package with cryptographically secure random number generator") - } - mrand.Seed(int64(binary.LittleEndian.Uint64(b[:]))) -} diff --git a/util/random_test.go b/util/random_test.go deleted file mode 100644 index d0c5200..0000000 --- a/util/random_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package util - -import ( - crand "crypto/rand" - "errors" - "testing" - - "github.com/agiledragon/gomonkey/v2" - "github.com/stretchr/testify/assert" -) - -func BenchmarkRandom(b *testing.B) { - for i := 0; i < b.N; i++ { - TestSeed(&testing.T{}) - } -} - -func TestSeed(t *testing.T) { - // monkey patching - defer gomonkey.ApplyFunc(crand.Read, func() (int, error) { - return -1, errors.New("ko") - }).Reset() - - // testing - assert.Panics(t, func() { seed() }) -}