Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: accept any non-empty string as a valid document ID #161

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: added test for document with custom ID
  • Loading branch information
txgruppi committed Jan 12, 2025
commit c8c92bb8b51a4fb9e94b7e1b1c260790bb097cde
25 changes: 25 additions & 0 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,31 @@ func TestCreateCollectionByQuery(t *testing.T) {
})
}

func TestCustomID(t *testing.T) {
runCloverTest(t, func(t *testing.T, db *c.DB) {
collection := "test_custom_id"
err := db.CreateCollection(collection)
require.NoError(t, err)

id := "custom_id"
m := map[string]interface{}{
"_id": id,
"itWorks?": true,
}
doc := d.NewDocument()
doc.SetAll(m)

insertedID, err := db.InsertOne(collection, doc)
require.NoError(t, err)
require.Equal(t, id, insertedID)

foundDoc, err := db.FindById(collection, id)
require.NoError(t, err)
require.NotNil(t, foundDoc)
require.Equal(t, m, foundDoc.AsMap())
})
}

/*
func TestInMemoryMode(t *testing.T) {
db, err := c.Open("clover-db", c.InMemoryMode(true))
Expand Down