Update azcosmos package

This commit is contained in:
Pijus Kamandulis
2025-02-25 20:43:23 +02:00
parent f062e03f0c
commit bd4fe5abec
11 changed files with 24 additions and 28 deletions

View File

@@ -11,10 +11,10 @@ type ApiServer struct {
onServerShutdown chan interface{}
isActive bool
router *gin.Engine
config config.ServerConfig
config *config.ServerConfig
}
func NewApiServer(dataRepository *repositories.DataRepository, config config.ServerConfig) *ApiServer {
func NewApiServer(dataRepository *repositories.DataRepository, config *config.ServerConfig) *ApiServer {
stopChan := make(chan interface{})
onServerShutdownChan := make(chan interface{})

View File

@@ -7,10 +7,10 @@ import (
type Handlers struct {
repository *repositories.DataRepository
config config.ServerConfig
config *config.ServerConfig
}
func NewHandlers(dataRepository *repositories.DataRepository, config config.ServerConfig) *Handlers {
func NewHandlers(dataRepository *repositories.DataRepository, config *config.ServerConfig) *Handlers {
return &Handlers{
repository: dataRepository,
config: config,

View File

@@ -10,7 +10,7 @@ import (
"github.com/pikami/cosmium/internal/logger"
)
func Authentication(config config.ServerConfig) gin.HandlerFunc {
func Authentication(config *config.ServerConfig) gin.HandlerFunc {
return func(c *gin.Context) {
requestUrl := c.Request.URL.String()
if config.DisableAuth ||

View File

@@ -7,7 +7,7 @@ import (
"github.com/pikami/cosmium/api/config"
)
func StripTrailingSlashes(r *gin.Engine, config config.ServerConfig) gin.HandlerFunc {
func StripTrailingSlashes(r *gin.Engine, config *config.ServerConfig) gin.HandlerFunc {
return func(c *gin.Context) {
path := c.Request.URL.Path
if len(path) > 1 && path[len(path)-1] == '/' && !strings.Contains(path, config.ExplorerBaseUrlLocation) {

View File

@@ -27,7 +27,9 @@ func (h *Handlers) GetServerInfo(c *gin.Context) {
"databaseAccountEndpoint": h.config.DatabaseEndpoint,
},
},
"enableMultipleWriteLocations": false,
"enableMultipleWriteLocations": false,
"continuousBackupEnabled": false,
"enableNRegionSynchronousCommit": false,
"userReplicationPolicy": map[string]interface{}{
"asyncReplication": false,
"minReplicaSetSize": 1,

View File

@@ -2,13 +2,11 @@ package tests_test
import (
"context"
"errors"
"fmt"
"io"
"net/http"
"testing"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos"
"github.com/pikami/cosmium/api/config"
"github.com/stretchr/testify/assert"
@@ -47,12 +45,7 @@ func Test_Authentication(t *testing.T) {
azcosmos.DatabaseProperties{ID: testDatabaseName},
&azcosmos.CreateDatabaseOptions{})
var respErr *azcore.ResponseError
if errors.As(err, &respErr) {
assert.Equal(t, respErr.StatusCode, http.StatusUnauthorized)
} else {
panic(err)
}
assert.Contains(t, err.Error(), "401 Unauthorized")
})
t.Run("Should allow unauthorized requests to /_explorer", func(t *testing.T) {
@@ -68,7 +61,7 @@ func Test_Authentication(t *testing.T) {
}
func Test_Authentication_Disabled(t *testing.T) {
ts := runTestServerCustomConfig(config.ServerConfig{
ts := runTestServerCustomConfig(&config.ServerConfig{
AccountKey: config.DefaultAccountKey,
ExplorerPath: "/tmp/nothing",
ExplorerBaseUrlLocation: config.ExplorerBaseUrlLocation,

View File

@@ -15,13 +15,15 @@ type TestServer struct {
URL string
}
func runTestServerCustomConfig(config config.ServerConfig) *TestServer {
func runTestServerCustomConfig(config *config.ServerConfig) *TestServer {
repository := repositories.NewDataRepository(repositories.RepositoryOptions{})
api := api.NewApiServer(repository, config)
server := httptest.NewServer(api.GetRouter())
config.DatabaseEndpoint = server.URL
return &TestServer{
Server: server,
Repository: repository,
@@ -30,7 +32,7 @@ func runTestServerCustomConfig(config config.ServerConfig) *TestServer {
}
func runTestServer() *TestServer {
config := config.ServerConfig{
config := &config.ServerConfig{
AccountKey: config.DefaultAccountKey,
ExplorerPath: "/tmp/nothing",
ExplorerBaseUrlLocation: config.ExplorerBaseUrlLocation,