Tests: use separate controller listening ports to prevent conflicts (#58)

This commit is contained in:
Nikolay Edigaryev 2023-03-24 21:22:58 +04:00 committed by GitHub
parent 63ba8b5532
commit 49753ebf4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View File

@ -78,6 +78,7 @@ func CreateDevControllerAndWorker(devDataDirPath string) (*controller.Controller
devController, err := controller.New(
controller.WithDataDir(dataDir),
controller.WithListenAddr(":0"),
controller.WithInsecureAuthDisabled(),
controller.WithLogger(logger),
)

View File

@ -161,8 +161,11 @@ func (controller *Controller) Run(ctx context.Context) error {
}
func (controller *Controller) Address() string {
if strings.HasPrefix(controller.listenAddr, ":") {
return fmt.Sprintf("http://localhost%s", controller.listenAddr)
hostPort := strings.ReplaceAll(controller.listener.Addr().String(), "[::]", "127.0.0.1")
if controller.tlsConfig != nil {
return fmt.Sprintf("https://%s", hostPort)
}
return controller.listenAddr
return fmt.Sprintf("http://%s", hostPort)
}

View File

@ -175,7 +175,7 @@ func StartIntegrationTestEnvironment(t *testing.T) *client.Client {
time.Sleep(5 * time.Second)
devClient, err := client.New()
devClient, err := client.New(client.WithAddress(devController.Address()))
if err != nil {
t.Fatal(err)
}