fixed doc env vars + mongo v2 migration

This commit is contained in:
Stephan D
2026-01-31 00:26:42 +01:00
parent cbb7bd8ba6
commit 1aa7e287fb
356 changed files with 1705 additions and 1729 deletions

View File

@@ -7,10 +7,10 @@ import (
"github.com/tech/sendico/pkg/db/storable"
"github.com/tech/sendico/pkg/model"
mutil "github.com/tech/sendico/pkg/mutil/db"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)
func (db *PoliciesDB) All(ctx context.Context, organizationRef primitive.ObjectID) ([]model.PolicyDescription, error) {
func (db *PoliciesDB) All(ctx context.Context, organizationRef bson.ObjectID) ([]model.PolicyDescription, error) {
// all documents
filter := repository.Query().Or(
repository.Filter(storable.OrganizationRefField, nil),

View File

@@ -5,7 +5,7 @@ import (
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/model"
"github.com/tech/sendico/pkg/mservice"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/mongo"
)
type PoliciesDB struct {

View File

@@ -14,17 +14,19 @@ import (
"github.com/tech/sendico/pkg/db/repository"
"github.com/tech/sendico/pkg/db/repository/builder"
"github.com/tech/sendico/pkg/merrors"
// Model package (contains PolicyDescription + Describable)
"github.com/tech/sendico/pkg/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tech/sendico/pkg/model"
// Testcontainers
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/mongodb"
"github.com/testcontainers/testcontainers-go/wait"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
"go.uber.org/zap"
)
@@ -114,7 +116,7 @@ func TestPoliciesDB(t *testing.T) {
cleanupCollection(t, ctx, db)
// Attempt to get a non-existent ID
nonExistentID := primitive.NewObjectID()
nonExistentID := bson.NewObjectID()
result := &model.PolicyDescription{}
err := pdb.Get(ctx, nonExistentID, result)
assert.Error(t, err)
@@ -234,8 +236,8 @@ func TestPoliciesDB(t *testing.T) {
cleanupCollection(t, ctx, db)
// Insert some policies (orgA, orgB, nil org)
orgA := primitive.NewObjectID()
orgB := primitive.NewObjectID()
orgA := bson.NewObjectID()
orgB := bson.NewObjectID()
descA := "Org A policy"
policyA := &model.PolicyDescription{
@@ -272,7 +274,7 @@ func TestPoliciesDB(t *testing.T) {
require.NoError(t, err)
require.Len(t, resultsA, 2) // orgA + built-in
var idsA []primitive.ObjectID
var idsA []bson.ObjectID
for _, r := range resultsA {
idsA = append(idsA, r.ID)
}
@@ -284,7 +286,7 @@ func TestPoliciesDB(t *testing.T) {
require.NoError(t, err)
require.Len(t, resultsB, 2) // orgB + built-in
var idsB []primitive.ObjectID
var idsB []bson.ObjectID
for _, r := range resultsB {
idsB = append(idsB, r.ID)
}
@@ -322,11 +324,11 @@ func TestPoliciesDB(t *testing.T) {
require.NoError(t, pdb.Create(ctx, pol3))
// 1) Request pol1, pol2
results12, err := pdb.Policies(ctx, []primitive.ObjectID{pol1.ID, pol2.ID})
results12, err := pdb.Policies(ctx, []bson.ObjectID{pol1.ID, pol2.ID})
require.NoError(t, err)
require.Len(t, results12, 2)
// IDs might be out of order, so we do a set-like check
var set12 []primitive.ObjectID
var set12 []bson.ObjectID
for _, r := range results12 {
set12 = append(set12, r.ID)
}
@@ -334,11 +336,11 @@ func TestPoliciesDB(t *testing.T) {
assert.Contains(t, set12, pol2.ID)
// 2) Request pol1, pol3, plus a random ID
fakeID := primitive.NewObjectID()
results13Fake, err := pdb.Policies(ctx, []primitive.ObjectID{pol1.ID, pol3.ID, fakeID})
fakeID := bson.NewObjectID()
results13Fake, err := pdb.Policies(ctx, []bson.ObjectID{pol1.ID, pol3.ID, fakeID})
require.NoError(t, err)
require.Len(t, results13Fake, 2) // pol1 + pol3 only
var set13Fake []primitive.ObjectID
var set13Fake []bson.ObjectID
for _, r := range results13Fake {
set13Fake = append(set13Fake, r.ID)
}
@@ -346,7 +348,7 @@ func TestPoliciesDB(t *testing.T) {
assert.Contains(t, set13Fake, pol3.ID)
// 3) Request with empty slice => expect no results
resultsEmpty, err := pdb.Policies(ctx, []primitive.ObjectID{})
resultsEmpty, err := pdb.Policies(ctx, []bson.ObjectID{})
require.NoError(t, err)
assert.Len(t, resultsEmpty, 0)
})

View File

@@ -6,10 +6,10 @@ import (
"github.com/tech/sendico/pkg/db/repository"
"github.com/tech/sendico/pkg/model"
mutil "github.com/tech/sendico/pkg/mutil/db"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)
func (db *PoliciesDB) Policies(ctx context.Context, refs []primitive.ObjectID) ([]model.PolicyDescription, error) {
func (db *PoliciesDB) Policies(ctx context.Context, refs []bson.ObjectID) ([]model.PolicyDescription, error) {
if len(refs) == 0 {
return []model.PolicyDescription{}, nil
}