Refactor to support multiple server instances in shared library

This commit is contained in:
Pijus Kamandulis
2024-12-18 19:39:57 +02:00
parent 84c33e3c8e
commit 777034181f
34 changed files with 503 additions and 369 deletions

View File

@@ -5,14 +5,37 @@ import (
"github.com/pikami/cosmium/api"
"github.com/pikami/cosmium/api/config"
"github.com/pikami/cosmium/internal/repositories"
)
func runTestServer() *httptest.Server {
config.Config.AccountKey = config.DefaultAccountKey
config.Config.ExplorerPath = "/tmp/nothing"
config.Config.ExplorerBaseUrlLocation = config.ExplorerBaseUrlLocation
type TestServer struct {
Server *httptest.Server
Repository *repositories.DataRepository
URL string
}
return httptest.NewServer(api.CreateRouter())
func runTestServerCustomConfig(config config.ServerConfig) *TestServer {
repository := repositories.NewDataRepository(repositories.RepositoryOptions{})
api := api.NewApiServer(repository, config)
server := httptest.NewServer(api.GetRouter())
return &TestServer{
Server: server,
Repository: repository,
URL: server.URL,
}
}
func runTestServer() *TestServer {
config := config.ServerConfig{
AccountKey: config.DefaultAccountKey,
ExplorerPath: "/tmp/nothing",
ExplorerBaseUrlLocation: config.ExplorerBaseUrlLocation,
}
return runTestServerCustomConfig(config)
}
const (