2024-02-10 20:17:33 +02:00
|
|
|
package tests_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http/httptest"
|
|
|
|
|
|
|
|
"github.com/pikami/cosmium/api"
|
2024-02-21 23:40:54 +02:00
|
|
|
"github.com/pikami/cosmium/api/config"
|
2024-12-18 19:39:57 +02:00
|
|
|
"github.com/pikami/cosmium/internal/repositories"
|
2024-02-10 20:17:33 +02:00
|
|
|
)
|
|
|
|
|
2024-12-18 19:39:57 +02:00
|
|
|
type TestServer struct {
|
|
|
|
Server *httptest.Server
|
|
|
|
Repository *repositories.DataRepository
|
|
|
|
URL string
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
2024-02-21 23:40:54 +02:00
|
|
|
|
2024-12-18 19:39:57 +02:00
|
|
|
return runTestServerCustomConfig(config)
|
2024-02-10 20:17:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
testAccountKey = "account-key"
|
|
|
|
testDatabaseName = "test-db"
|
|
|
|
testCollectionName = "test-coll"
|
|
|
|
)
|