Skip to content

Commit

Permalink
General clean up of testdbman program + drop Cobra dependency (#266)
Browse files Browse the repository at this point in the history
This one's mainly in pursuit of dropping the Cobra dependency in the
main River package. It's still nice to have Cobra for the River CLI, but
the only reason that top-level River needs it is that `testdbman` (the
command used to drop and raise test databases needs it). Since
`testdbman`'s CLI API is so simple anyway, here we move it off of Cobra
and over to a small internal CLI framework, maintaining an identical
interface as before (with the small change that `--help` is now `-help`
since we're using Go's internal flag module).

This would normally be a dumb thing to do, but I don't expect the
`testdbman` interface to have to get anymore complicated (it hasn't
changed at all since River's inception), the internal framework isn't a
huge amount of code, and I put some test coverage on it to make sure
that everything works as expected.

In addition to that, we do a little housekeeping on the internal code
for `testdbman`:

* Reduce visual noise by stripping extra lines and functions that were
  doing very little, and removing some specific contexts in favor of one
  top-level one for the program.

* Move the core functions and command definitions into one file so that
  quick file find works a little better and it's easier to get a
  holistic view of what everything is doing. Especially after trimming
  code, there's so little code that it all fits together without feeling
  crowded, and previously some of the files like `reset.go` were doing
  practically nothing.

* A single unified error handling schema. Previously some code was
  printing to stderr and aborting the program and some code was
  returning errors. Now everything returns an error with a single
  top-level error handler.

* Make output and error formatting more consistent across commands.

* Tighten up some documentation and comments that'd fallen out of date
  since the program was originally written.

* Remove some helper functions like `dbURL` that were doing more to
  obscure than to help (it had a special path for the management
  database URL and then did a string concatenation otherwise, but it's
  much more clear to just use a constant for the management database URL
  when we know that we want it). Add helpers where appropriate like
  `generateTestDBNames` that let us put a little (very modest amount for
  the time being) test coverage onto the program.
  • Loading branch information
brandur authored Mar 17, 2024
1 parent a939d34 commit 8af4af8
Show file tree
Hide file tree
Showing 8 changed files with 659 additions and 245 deletions.
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ linters-settings:
- id
- j
- mu
- sb # common convention for string builder
- t
- tt # common convention for table tests
- tx
Expand Down
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ require (
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.0.25
github.com/riverqueue/river/rivertype v0.0.25
github.com/robfig/cron/v3 v3.0.1
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.9.0
go.uber.org/goleak v1.3.0
golang.org/x/mod v0.16.0
Expand All @@ -28,12 +27,10 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa h1:s+4MhCQ6YrzisK6hFJUX53drDT4UsSW3DEhKn0ifuHw=
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa/go.mod h1:a/s9Lp5W7n/DD0VrVoyJ00FbP2ytTPDVOivvn2bMlds=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
Expand All @@ -26,11 +23,6 @@ github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
97 changes: 0 additions & 97 deletions internal/cmd/testdbman/create.go

This file was deleted.

102 changes: 0 additions & 102 deletions internal/cmd/testdbman/drop.go

This file was deleted.

Loading

0 comments on commit 8af4af8

Please sign in to comment.