0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00

refactor: Cleanup/simplify test cases (#1041)

Signed-off-by: Nicol Draghici <idraghic@cisco.com>
This commit is contained in:
Nicol 2022-12-15 23:22:18 +02:00 committed by GitHub
parent 9136479206
commit 05f75e041c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 311 additions and 494 deletions

File diff suppressed because it is too large Load diff

View file

@ -46,9 +46,9 @@ func TestRoutes(t *testing.T) {
panic(err)
}
go startServer(ctlr)
defer stopServer(ctlr)
test.WaitTillServerReady(baseURL)
cm := test.NewControllerManager(ctlr)
cm.StartAndWait(port)
defer cm.StopServer()
rthdlr := api.NewRouteHandler(ctlr)

View file

@ -167,6 +167,58 @@ func CopyFiles(sourceDir, destDir string) error {
return nil
}
type Controller interface {
Run(ctx context.Context) error
Shutdown()
GetPort() int
}
type ControllerManager struct {
controller Controller
}
func (cm *ControllerManager) StartServer() {
// this blocks
ctx := context.Background()
go func() {
if err := cm.controller.Run(ctx); err != nil {
return
}
}()
}
func (cm *ControllerManager) StopServer() {
cm.controller.Shutdown()
}
func (cm *ControllerManager) WaitServerToBeReady(port string) {
url := GetBaseURL(port)
WaitTillServerReady(url)
}
func (cm *ControllerManager) StartAndWait(port string) {
// this blocks
ctx := context.Background()
go func() {
if err := cm.controller.Run(ctx); err != nil {
return
}
}()
url := GetBaseURL(port)
WaitTillServerReady(url)
}
func NewControllerManager(controller Controller) ControllerManager {
cm := ControllerManager{
controller: controller,
}
return cm
}
func WaitTillServerReady(url string) {
for {
_, err := resty.R().Get(url)