Skip to content

Commit

Permalink
enable multiple setups in test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Dias committed Dec 12, 2024
1 parent a123242 commit b37bbc8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 49 deletions.
24 changes: 13 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
module github.com/happyhippyhippo/flamingo

go 1.21.4
go 1.23

toolchain go1.23.0

require (
github.com/go-playground/locales v0.14.1
github.com/go-playground/universal-translator v0.18.1
github.com/go-playground/validator/v10 v10.22.1
github.com/go-playground/validator/v10 v10.23.0
github.com/gorilla/mux v1.8.1
github.com/spf13/afero v1.11.0
go.uber.org/dig v1.18.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.5.7
gorm.io/driver/postgres v1.5.9
gorm.io/driver/sqlite v1.5.6
gorm.io/driver/postgres v1.5.11
gorm.io/driver/sqlite v1.5.7
gorm.io/gorm v1.25.12
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
github.com/gabriel-vasile/mimetype v1.4.7 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
Expand All @@ -29,10 +31,10 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-sqlite3 v1.14.24 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
)
40 changes: 20 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
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/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc=
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc=
github.com/gabriel-vasile/mimetype v1.4.7 h1:SKFKl7kD0RiPdbht0s7hFtjl489WcQ1VyPW8ZzUMYCA=
github.com/gabriel-vasile/mimetype v1.4.7/go.mod h1:GDlAgAyIRT27BhFl53XNAFtfjzOkLaF35JdEG0P7LtU=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-playground/validator/v10 v10.23.0 h1:/PwmTwZhS0dPkav3cdK9kV1FsAmrL8sThn8IHr/sO+o=
github.com/go-playground/validator/v10 v10.23.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
Expand Down Expand Up @@ -41,8 +41,8 @@ github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBW
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -52,16 +52,16 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.uber.org/dig v1.18.0 h1:imUL1UiY0Mg4bqbFfsRQO5G4CGRBec/ZujWTvSVp3pw=
go.uber.org/dig v1.18.0/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand All @@ -70,10 +70,10 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8=
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
gorm.io/driver/sqlite v1.5.6 h1:fO/X46qn5NUEEOZtnjJRWRzZMe8nqJiQ9E+0hi+hKQE=
gorm.io/driver/sqlite v1.5.6/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4=
gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=
gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
gorm.io/driver/sqlite v1.5.7 h1:8NvsrhP0ifM7LX9G4zPB97NwovUakUxc+2V2uuf3Z1I=
gorm.io/driver/sqlite v1.5.7/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
10 changes: 5 additions & 5 deletions rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ func newRestLogAdapter(logger Logger) RestLogAdapter {
}

func (r restLogAdapter) Start(id string) error {
return r.logger.Signal(LogInfo, "rest", "Starting rest watchdog ...", Bag{"watchdog": id})
return r.logger.Signal(LogInfo, "rest", "starting rest watchdog ...", Bag{"watchdog": id})
}

func (r restLogAdapter) Error(id string, e error) error {
return r.logger.Signal(LogError, "rest", "Rest watchdog error", Bag{"watchdog": id, "error": e.Error()})
return r.logger.Signal(LogError, "rest", "rest watchdog error", Bag{"watchdog": id, "error": e.Error()})
}

func (r restLogAdapter) Done(id string) error {
return r.logger.Signal(LogInfo, "rest", "Rest watchdog terminated", Bag{"watchdog": id})
return r.logger.Signal(LogInfo, "rest", "rest watchdog terminated", Bag{"watchdog": id})
}

func (r restLogAdapter) ShutdownGracefully(id string) error {
return r.logger.Signal(LogInfo, "rest", "Rest watchdog gracefully shut down", Bag{"watchdog": id})
return r.logger.Signal(LogInfo, "rest", "rest watchdog gracefully shut down", Bag{"watchdog": id})
}

func (r restLogAdapter) ShutdownError(id string, e error) error {
return r.logger.Signal(LogError, "rest", "Error shutting down rest watchdog", Bag{"watchdog": id, "error": e.Error()})
return r.logger.Signal(LogError, "rest", "error shutting down rest watchdog", Bag{"watchdog": id, "error": e.Error()})
}

// RestRegister @todo doc
Expand Down
17 changes: 8 additions & 9 deletions test/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ type runner struct {
app flam.App
expects error
processes []string
setup interface{}
setup []interface{}
test interface{}
checks map[string]interface{}
teardown interface{}
teardown []interface{}
}

// NewRunner @todo doc
Expand Down Expand Up @@ -73,7 +73,7 @@ func (r *runner) WithProcess(id string) Runner {

// WithSetup @todo doc
func (r *runner) WithSetup(f interface{}) Runner {
r.setup = f
r.setup = append(r.setup, f)
return r
}

Expand All @@ -91,14 +91,13 @@ func (r *runner) WithCheck(id string, f interface{}) Runner {

// WithTeardown @todo doc
func (r *runner) WithTeardown(f interface{}) Runner {
r.teardown = f
r.teardown = append(r.teardown, f)
return r
}

// Run @todo doc
func (r *runner) Run() error {
_ = r.app.DI().Invoke(func(kennel flam.WatchdogKennel) {
_ = kennel.DisableProcess("rest")
for _, id := range r.processes {
_ = kennel.EnableProcess(id)
}
Expand Down Expand Up @@ -166,8 +165,8 @@ func (r *runner) loadConfig(file string) (flam.ConfigSource, error) {
}

func (r *runner) runSetup() error {
if r.setup != nil {
if e := r.app.DI().Invoke(r.setup); e != nil {
for _, setup := range r.setup {
if e := r.app.DI().Invoke(setup); e != nil {
r.t.Errorf("error running test setup : %v", e)
}
}
Expand All @@ -193,8 +192,8 @@ func (r *runner) runChecks() {
}

func (r *runner) runTeardown() error {
if r.teardown != nil {
if e := r.app.DI().Invoke(r.teardown); e != nil {
for _, teardown := range r.teardown {
if e := r.app.DI().Invoke(teardown); e != nil {
r.t.Errorf("error running test teardown : %v", e)
}
}
Expand Down
13 changes: 9 additions & 4 deletions watchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ func newWatchdogLogAdapter(logger Logger) WatchdogLogAdapter {
}

func (la watchdogLogAdapter) Start(id string) error {
return la.logger.Signal(LogInfo, "watchdog", "Watchdog starting ...", Bag{"watchdog": id})
return la.logger.Signal(LogInfo, "watchdog", "watchdog starting ...", Bag{"watchdog": id})
}

func (la watchdogLogAdapter) Error(id string, e error) error {
return la.logger.Signal(LogError, "watchdog", "Watchdog error", Bag{"watchdog": id, "error": e})
return la.logger.Signal(LogError, "watchdog", "watchdog error", Bag{"watchdog": id, "error": e})
}

func (la watchdogLogAdapter) Done(id string) error {
return la.logger.Signal(LogInfo, "watchdog", "Watchdog terminated", Bag{"watchdog": id})
return la.logger.Signal(LogInfo, "watchdog", "watchdog terminated", Bag{"watchdog": id})
}

type watchdog struct {
Expand Down Expand Up @@ -115,6 +115,7 @@ type watchdogKennel struct {
type WatchdogKennel interface {
AddProcess(process WatchdogProcess) error
GetProcess(id string) (WatchdogProcess, error)
IsProcessEnabled(id string) bool
EnableProcess(id string) error
DisableProcess(id string) error
Run() error
Expand Down Expand Up @@ -163,6 +164,10 @@ func (k *watchdogKennel) GetProcess(id string) (WatchdogProcess, error) {
return p.process, nil
}

func (k *watchdogKennel) IsProcessEnabled(id string) bool {
return k.config.Bool(fmt.Sprintf("%s.enabled", id), false)
}

func (k *watchdogKennel) EnableProcess(id string) error {
return k.config.Set(fmt.Sprintf("%s.enabled", id), true)
}
Expand All @@ -178,7 +183,7 @@ func (k *watchdogKennel) Run() error {
var result error
wg := sync.WaitGroup{}
for id, reg := range k.regs {
if k.config.Bool(fmt.Sprintf("%s.enabled", id), false) == false {
if k.IsProcessEnabled(id) == false {
continue
}

Expand Down

0 comments on commit b37bbc8

Please sign in to comment.