mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-19 08:50:46 +00:00
Refactor to support multiple server instances in shared library
This commit is contained in:
@@ -10,24 +10,23 @@ import (
|
||||
"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/pikami/cosmium/internal/repositories"
|
||||
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_Databases(t *testing.T) {
|
||||
ts := runTestServer()
|
||||
defer ts.Close()
|
||||
defer ts.Server.Close()
|
||||
|
||||
client, err := azcosmos.NewClientFromConnectionString(
|
||||
fmt.Sprintf("AccountEndpoint=%s;AccountKey=%s", ts.URL, config.Config.AccountKey),
|
||||
fmt.Sprintf("AccountEndpoint=%s;AccountKey=%s", ts.URL, config.DefaultAccountKey),
|
||||
&azcosmos.ClientOptions{},
|
||||
)
|
||||
assert.Nil(t, err)
|
||||
|
||||
t.Run("Database Create", func(t *testing.T) {
|
||||
t.Run("Should create database", func(t *testing.T) {
|
||||
repositories.DeleteDatabase(testDatabaseName)
|
||||
ts.Repository.DeleteDatabase(testDatabaseName)
|
||||
|
||||
createResponse, err := client.CreateDatabase(context.TODO(), azcosmos.DatabaseProperties{
|
||||
ID: testDatabaseName,
|
||||
@@ -38,7 +37,7 @@ func Test_Databases(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Should return conflict when database exists", func(t *testing.T) {
|
||||
repositories.CreateDatabase(repositorymodels.Database{
|
||||
ts.Repository.CreateDatabase(repositorymodels.Database{
|
||||
ID: testDatabaseName,
|
||||
})
|
||||
|
||||
@@ -58,7 +57,7 @@ func Test_Databases(t *testing.T) {
|
||||
|
||||
t.Run("Database Read", func(t *testing.T) {
|
||||
t.Run("Should read database", func(t *testing.T) {
|
||||
repositories.CreateDatabase(repositorymodels.Database{
|
||||
ts.Repository.CreateDatabase(repositorymodels.Database{
|
||||
ID: testDatabaseName,
|
||||
})
|
||||
|
||||
@@ -72,7 +71,7 @@ func Test_Databases(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Should return not found when database does not exist", func(t *testing.T) {
|
||||
repositories.DeleteDatabase(testDatabaseName)
|
||||
ts.Repository.DeleteDatabase(testDatabaseName)
|
||||
|
||||
databaseResponse, err := client.NewDatabase(testDatabaseName)
|
||||
assert.Nil(t, err)
|
||||
@@ -91,7 +90,7 @@ func Test_Databases(t *testing.T) {
|
||||
|
||||
t.Run("Database Delete", func(t *testing.T) {
|
||||
t.Run("Should delete database", func(t *testing.T) {
|
||||
repositories.CreateDatabase(repositorymodels.Database{
|
||||
ts.Repository.CreateDatabase(repositorymodels.Database{
|
||||
ID: testDatabaseName,
|
||||
})
|
||||
|
||||
@@ -104,7 +103,7 @@ func Test_Databases(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Should return not found when database does not exist", func(t *testing.T) {
|
||||
repositories.DeleteDatabase(testDatabaseName)
|
||||
ts.Repository.DeleteDatabase(testDatabaseName)
|
||||
|
||||
databaseResponse, err := client.NewDatabase(testDatabaseName)
|
||||
assert.Nil(t, err)
|
||||
|
||||
Reference in New Issue
Block a user