forked from pocketbase/pocketbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored Record.data and Record.expand to be concurrent safe
- Loading branch information
1 parent
39df263
commit ae371e8
Showing
38 changed files
with
312 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package models_test | ||
|
||
import ( | ||
"bytes" | ||
"database/sql" | ||
"encoding/json" | ||
"testing" | ||
|
@@ -346,7 +347,7 @@ func TestRecordOriginalCopy(t *testing.T) { | |
t.Fatalf("Expected the initial/original f to be %q, got %q", "123", v) | ||
} | ||
|
||
// Loading new data shouldn't affect the original state | ||
// loading new data shouldn't affect the original state | ||
m.Load(map[string]any{"f": "789"}) | ||
|
||
if v := m.GetString("f"); v != "789" { | ||
|
@@ -358,6 +359,38 @@ func TestRecordOriginalCopy(t *testing.T) { | |
} | ||
} | ||
|
||
func TestRecordCleanCopy(t *testing.T) { | ||
m := models.NewRecord(&models.Collection{ | ||
Name: "cname", | ||
Type: models.CollectionTypeAuth, | ||
}) | ||
m.Load(map[string]any{ | ||
"id": "id1", | ||
"created": "2023-01-01 00:00:00.000Z", | ||
"updated": "2023-01-02 00:00:00.000Z", | ||
"username": "test", | ||
"verified": true, | ||
"email": "[email protected]", | ||
"unknown": "456", | ||
}) | ||
|
||
// make a change to ensure that the latest data is targeted | ||
m.Set("id", "id2") | ||
|
||
// allow the special flags and options to check whether they will be ignored | ||
m.SetExpand(map[string]any{"test": 123}) | ||
m.IgnoreEmailVisibility(true) | ||
m.WithUnkownData(true) | ||
|
||
copy := m.CleanCopy() | ||
copyExport, _ := copy.MarshalJSON() | ||
|
||
expectedExport := []byte(`{"collectionId":"","collectionName":"cname","created":"2023-01-01 00:00:00.000Z","emailVisibility":false,"id":"id2","updated":"2023-01-02 00:00:00.000Z","username":"test","verified":true}`) | ||
if !bytes.Equal(copyExport, expectedExport) { | ||
t.Fatalf("Expected clean export \n%s, \ngot \n%s", expectedExport, copyExport) | ||
} | ||
} | ||
|
||
func TestRecordSetAndGetExpand(t *testing.T) { | ||
collection := &models.Collection{} | ||
m := models.NewRecord(collection) | ||
|
Oops, something went wrong.