From 1f21d09721bf0135e470b58c5b40537e67d6c843 Mon Sep 17 00:00:00 2001 From: Jens Teichert Date: Wed, 27 Nov 2024 21:25:02 +0100 Subject: [PATCH] fmt --- collection.go | 4 ---- collection_test.go | 5 ----- database.go | 2 +- document.go | 10 +++++----- document_test.go | 2 +- hooks.go | 2 +- hooks_test.go | 11 ++++++----- indexes.go | 4 ++-- 8 files changed, 16 insertions(+), 24 deletions(-) diff --git a/collection.go b/collection.go index fd8222c..45763ca 100644 --- a/collection.go +++ b/collection.go @@ -8,7 +8,6 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) - type Collection[T Document] struct { collection *mongo.Collection } @@ -52,7 +51,6 @@ func (repo *Collection[T]) UpdateMany(filter interface{}, doc bson.M) error { return err } - func (repo *Collection[T]) DeleteById(id string) error { res, err := repo.collection.DeleteOne(DefaultContext(), bson.M{"_id": id}) @@ -112,8 +110,6 @@ func (repo *Collection[T]) Drop() error { return err } - func (repo *Collection[T]) NewId() primitive.ObjectID { return primitive.NewObjectID() } - diff --git a/collection_test.go b/collection_test.go index bdb57c6..dadfe25 100644 --- a/collection_test.go +++ b/collection_test.go @@ -17,7 +17,6 @@ type testdoc struct { Title string `bson:"title" json:"title"` } - type testdocWithCustomID struct { Doc `bson:",inline"` Title string `bson:"title" json:"title"` @@ -27,7 +26,6 @@ func (pg *testdocWithCustomID) NewID() string { return "test_" + primitive.NewObjectID().Hex() } - func TestCollection_Insert(t *testing.T) { rand.Seed(time.Now().UnixNano()) mockDb.Connect("mongodb://localhost:27017/colt?readPreference=primary&directConnection=true&ssl=false", "colt") @@ -252,7 +250,6 @@ func TestCollection_DeleteById(t *testing.T) { mockDb.Disconnect() } - func TestCollection_CountDocuments(t *testing.T) { rand.Seed(time.Now().UnixNano()) mockDb.Connect("mongodb://localhost:27017/colt?readPreference=primary&directConnection=true&ssl=false", "colt") @@ -281,8 +278,6 @@ func TestCollection_CountDocuments(t *testing.T) { mockDb.Disconnect() } - - func TestCollection_Aggregate(t *testing.T) { rand.Seed(time.Now().UnixNano()) mockDb.Connect("mongodb://localhost:27017/colt?readPreference=primary&directConnection=true&ssl=false", "colt") diff --git a/database.go b/database.go index 6707d46..80e98fa 100644 --- a/database.go +++ b/database.go @@ -42,7 +42,7 @@ func (db *Database) Connect(connectionString string, dbName string) error { } func (db *Database) Disconnect() error { - err := db.client.Disconnect(DefaultContext()); + err := db.client.Disconnect(DefaultContext()) db.db = nil return err } diff --git a/document.go b/document.go index 16da591..5396f92 100644 --- a/document.go +++ b/document.go @@ -14,7 +14,7 @@ type Document interface { } type Doc struct { - ID string `bson:"_id,omitempty" json:"_id,omitempty"` + ID string `bson:"_id,omitempty" json:"_id,omitempty"` } func (doc *Doc) NewID() string { @@ -30,8 +30,8 @@ func (doc *Doc) GetID() string { } type DocWithTimestamps struct { - Doc `bson:",inline"` - CreatedAt time.Time `json:"created_at" bson:"created_at"` + Doc `bson:",inline"` + CreatedAt time.Time `json:"created_at" bson:"created_at"` UpdatedAt *time.Time `json:"updated_at,omitempty" bson:"updated_at,omitempty"` } @@ -41,7 +41,7 @@ func (doc *DocWithTimestamps) BeforeInsert() error { } func (doc *DocWithTimestamps) BeforeUpdate() error { - now := time.Now(); + now := time.Now() doc.UpdatedAt = &now return nil -} \ No newline at end of file +} diff --git a/document_test.go b/document_test.go index f8fe0d4..48e6853 100644 --- a/document_test.go +++ b/document_test.go @@ -50,4 +50,4 @@ func TestCDocument_NewID_Custom(t *testing.T) { assert.NotEmpty(t, doc.NewID()) assert.True(t, strings.HasPrefix(doc.NewID(), "td_")) -} \ No newline at end of file +} diff --git a/hooks.go b/hooks.go index f5eca10..bcdce21 100644 --- a/hooks.go +++ b/hooks.go @@ -6,4 +6,4 @@ type BeforeInsertHook interface { type BeforeUpdateHook interface { BeforeUpdate() error -} \ No newline at end of file +} diff --git a/hooks_test.go b/hooks_test.go index f58c33d..be10d13 100644 --- a/hooks_test.go +++ b/hooks_test.go @@ -7,24 +7,25 @@ import ( ) type testDoc struct { - mock.Mock `bson:"-"` + mock.Mock `bson:"-"` DocWithTimestamps `bson:",inline"` - Title string `bson:"title" json:"title"` + Title string `bson:"title" json:"title"` } -func(t *testDoc) BeforeInsert() error { +func (t *testDoc) BeforeInsert() error { t.DocWithTimestamps.BeforeInsert() args := t.Called() return args.Error(0) } -func(t *testDoc) BeforeUpdate() error { +func (t *testDoc) BeforeUpdate() error { t.DocWithTimestamps.BeforeUpdate() args := t.Called() return args.Error(0) } var mockDb = Database{} + func TestBeforeInsertHook(t *testing.T) { mockDb.Connect("mongodb://localhost:27017/colt?readPreference=primary&directConnection=true&ssl=false", "colt") doc := testDoc{Title: "Test"} @@ -47,4 +48,4 @@ func TestBeforeUpdateHook(t *testing.T) { assert.Nil(t, updateErr) doc.AssertExpectations(t) -} \ No newline at end of file +} diff --git a/indexes.go b/indexes.go index 2c46c1c..8a1cbbe 100644 --- a/indexes.go +++ b/indexes.go @@ -5,9 +5,9 @@ import ( "go.mongodb.org/mongo-driver/mongo" ) -func (repo *Collection[T]) CreateIndex(keys bson.D) error { +func (repo *Collection[T]) CreateIndex(keys bson.D) error { mod := mongo.IndexModel{ - Keys: keys, + Keys: keys, Options: nil, } _, err := repo.collection.Indexes().CreateOne(DefaultContext(), mod)