diff --git a/CHANGELOG.md b/CHANGELOG.md index f9efceea..264a3c45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,22 @@ +## v0.20.3 + +- Fixed the `json` field query comparisons to work correctly with plain JSON values like `null`, `bool` `number`, etc. ([#4068](https://github.com/pocketbase/pocketbase/issues/4068)). + Since there are plans in the future to allow custom SQLite builds and also in some situations it may be useful to be able to distinguish `NULL` from `''`, + for the `json` fields (and for any other future non-standard field) we no longer apply `COALESCE` by default, aka.: + ``` + Dataset: + 1) data: json(null) + 2) data: json('') + + For the filter "data = null" only 1) will resolve to TRUE. + For the filter "data = ''" only 2) will resolve to TRUE. + ``` + +- Minor Go tests improvements + - Sorted the record cascade delete references to ensure that the delete operation will preserve the order of the fired events when running the tests. + - Marked some of the tests as safe for parallel execution to speed up a little the GitHub action build times. + + ## v0.20.2 - Added `sleep(milliseconds)` JSVM binding. diff --git a/cmd/admin_test.go b/cmd/admin_test.go index c3fbbd70..7e2dd6c9 100644 --- a/cmd/admin_test.go +++ b/cmd/admin_test.go @@ -8,6 +8,8 @@ import ( ) func TestAdminCreateCommand(t *testing.T) { + t.Parallel() + app, _ := tests.NewTestApp() defer app.Cleanup() diff --git a/mails/admin_test.go b/mails/admin_test.go index 32bb6fe7..1bfdb3de 100644 --- a/mails/admin_test.go +++ b/mails/admin_test.go @@ -9,6 +9,8 @@ import ( ) func TestSendAdminPasswordReset(t *testing.T) { + t.Parallel() + testApp, _ := tests.NewTestApp() defer testApp.Cleanup() diff --git a/mails/record_test.go b/mails/record_test.go index f885d1f2..00d9cbc1 100644 --- a/mails/record_test.go +++ b/mails/record_test.go @@ -9,6 +9,8 @@ import ( ) func TestSendRecordPasswordReset(t *testing.T) { + t.Parallel() + testApp, _ := tests.NewTestApp() defer testApp.Cleanup() @@ -37,6 +39,8 @@ func TestSendRecordPasswordReset(t *testing.T) { } func TestSendRecordVerification(t *testing.T) { + t.Parallel() + testApp, _ := tests.NewTestApp() defer testApp.Cleanup() @@ -62,6 +66,8 @@ func TestSendRecordVerification(t *testing.T) { } func TestSendRecordChangeEmail(t *testing.T) { + t.Parallel() + testApp, _ := tests.NewTestApp() defer testApp.Cleanup() diff --git a/models/admin_test.go b/models/admin_test.go index 261135dd..6730d229 100644 --- a/models/admin_test.go +++ b/models/admin_test.go @@ -8,6 +8,8 @@ import ( ) func TestAdminTableName(t *testing.T) { + t.Parallel() + m := models.Admin{} if m.TableName() != "_admins" { t.Fatalf("Unexpected table name, got %q", m.TableName()) @@ -15,6 +17,8 @@ func TestAdminTableName(t *testing.T) { } func TestAdminValidatePassword(t *testing.T) { + t.Parallel() + scenarios := []struct { admin models.Admin password string @@ -61,6 +65,8 @@ func TestAdminValidatePassword(t *testing.T) { } func TestAdminSetPassword(t *testing.T) { + t.Parallel() + m := models.Admin{ // 123456 PasswordHash: "$2a$10$SKk/Y/Yc925PBtsSYBvq3Ous9Jy18m4KTn6b/PQQ.Y9QVjy3o/Fv.", @@ -93,6 +99,8 @@ func TestAdminSetPassword(t *testing.T) { } func TestAdminRefreshTokenKey(t *testing.T) { + t.Parallel() + m := models.Admin{TokenKey: "test"} m.RefreshTokenKey() diff --git a/models/base_test.go b/models/base_test.go index 764c26d2..434887f3 100644 --- a/models/base_test.go +++ b/models/base_test.go @@ -7,6 +7,8 @@ import ( ) func TestBaseModelHasId(t *testing.T) { + t.Parallel() + scenarios := []struct { model models.BaseModel expected bool @@ -34,6 +36,8 @@ func TestBaseModelHasId(t *testing.T) { } func TestBaseModelId(t *testing.T) { + t.Parallel() + m := models.BaseModel{} if m.GetId() != "" { @@ -54,6 +58,8 @@ func TestBaseModelId(t *testing.T) { } func TestBaseModelIsNew(t *testing.T) { + t.Parallel() + m0 := models.BaseModel{} m1 := models.BaseModel{Id: ""} m2 := models.BaseModel{Id: "test"} @@ -96,6 +102,8 @@ func TestBaseModelIsNew(t *testing.T) { } func TestBaseModelCreated(t *testing.T) { + t.Parallel() + m := models.BaseModel{} if !m.GetCreated().IsZero() { @@ -110,6 +118,8 @@ func TestBaseModelCreated(t *testing.T) { } func TestBaseModelUpdated(t *testing.T) { + t.Parallel() + m := models.BaseModel{} if !m.GetUpdated().IsZero() { diff --git a/models/collection_test.go b/models/collection_test.go index 5e64f139..ab8c0525 100644 --- a/models/collection_test.go +++ b/models/collection_test.go @@ -11,6 +11,8 @@ import ( ) func TestCollectionTableName(t *testing.T) { + t.Parallel() + m := models.Collection{} if m.TableName() != "_collections" { t.Fatalf("Unexpected table name, got %q", m.TableName()) @@ -18,6 +20,8 @@ func TestCollectionTableName(t *testing.T) { } func TestCollectionBaseFilesPath(t *testing.T) { + t.Parallel() + m := models.Collection{} m.RefreshId() @@ -29,6 +33,8 @@ func TestCollectionBaseFilesPath(t *testing.T) { } func TestCollectionIsBase(t *testing.T) { + t.Parallel() + scenarios := []struct { collection models.Collection expected bool @@ -48,6 +54,8 @@ func TestCollectionIsBase(t *testing.T) { } func TestCollectionIsAuth(t *testing.T) { + t.Parallel() + scenarios := []struct { collection models.Collection expected bool @@ -67,6 +75,8 @@ func TestCollectionIsAuth(t *testing.T) { } func TestCollectionMarshalJSON(t *testing.T) { + t.Parallel() + scenarios := []struct { name string collection models.Collection @@ -109,6 +119,8 @@ func TestCollectionMarshalJSON(t *testing.T) { } func TestCollectionBaseOptions(t *testing.T) { + t.Parallel() + scenarios := []struct { name string collection models.Collection @@ -153,6 +165,8 @@ func TestCollectionBaseOptions(t *testing.T) { } func TestCollectionAuthOptions(t *testing.T) { + t.Parallel() + options := types.JsonMap{"test": 123, "minPasswordLength": 4} expectedSerialization := `{"manageRule":null,"allowOAuth2Auth":false,"allowUsernameAuth":false,"allowEmailAuth":false,"requireEmail":false,"exceptEmailDomains":null,"onlyVerified":false,"onlyEmailDomains":null,"minPasswordLength":4}` @@ -200,6 +214,8 @@ func TestCollectionAuthOptions(t *testing.T) { } func TestCollectionViewOptions(t *testing.T) { + t.Parallel() + options := types.JsonMap{"query": "select id from demo1", "minPasswordLength": 4} expectedSerialization := `{"query":"select id from demo1"}` @@ -247,6 +263,8 @@ func TestCollectionViewOptions(t *testing.T) { } func TestNormalizeOptions(t *testing.T) { + t.Parallel() + scenarios := []struct { name string collection models.Collection @@ -288,6 +306,8 @@ func TestNormalizeOptions(t *testing.T) { } func TestDecodeOptions(t *testing.T) { + t.Parallel() + m := models.Collection{ Options: types.JsonMap{"test": 123}, } @@ -306,6 +326,8 @@ func TestDecodeOptions(t *testing.T) { } func TestSetOptions(t *testing.T) { + t.Parallel() + scenarios := []struct { name string collection models.Collection @@ -357,6 +379,8 @@ func TestSetOptions(t *testing.T) { } func TestCollectionBaseOptionsValidate(t *testing.T) { + t.Parallel() + opt := models.CollectionBaseOptions{} if err := opt.Validate(); err != nil { t.Fatal(err) @@ -364,6 +388,8 @@ func TestCollectionBaseOptionsValidate(t *testing.T) { } func TestCollectionAuthOptionsValidate(t *testing.T) { + t.Parallel() + scenarios := []struct { name string options models.CollectionAuthOptions @@ -451,6 +477,8 @@ func TestCollectionAuthOptionsValidate(t *testing.T) { } func TestCollectionViewOptionsValidate(t *testing.T) { + t.Parallel() + scenarios := []struct { name string options models.CollectionViewOptions diff --git a/models/external_auth_test.go b/models/external_auth_test.go index 26c53b06..7688daa2 100644 --- a/models/external_auth_test.go +++ b/models/external_auth_test.go @@ -7,6 +7,8 @@ import ( ) func TestExternalAuthTableName(t *testing.T) { + t.Parallel() + m := models.ExternalAuth{} if m.TableName() != "_externalAuths" { t.Fatalf("Unexpected table name, got %q", m.TableName()) diff --git a/models/param_test.go b/models/param_test.go index 42291551..0ea03c64 100644 --- a/models/param_test.go +++ b/models/param_test.go @@ -7,6 +7,8 @@ import ( ) func TestParamTableName(t *testing.T) { + t.Parallel() + m := models.Param{} if m.TableName() != "_params" { t.Fatalf("Unexpected table name, got %q", m.TableName()) diff --git a/models/record_test.go b/models/record_test.go index ec620dc1..0bc04cf6 100644 --- a/models/record_test.go +++ b/models/record_test.go @@ -15,6 +15,8 @@ import ( ) func TestNewRecord(t *testing.T) { + t.Parallel() + collection := &models.Collection{ Name: "test_collection", Schema: schema.NewSchema( @@ -37,6 +39,8 @@ func TestNewRecord(t *testing.T) { } func TestNewRecordFromNullStringMap(t *testing.T) { + t.Parallel() + collection := &models.Collection{ Name: "test", Schema: schema.NewSchema( @@ -200,6 +204,8 @@ func TestNewRecordFromNullStringMap(t *testing.T) { } func TestNewRecordsFromNullStringMaps(t *testing.T) { + t.Parallel() + collection := &models.Collection{ Name: "test", Schema: schema.NewSchema( @@ -310,6 +316,8 @@ func TestNewRecordsFromNullStringMaps(t *testing.T) { } func TestRecordTableName(t *testing.T) { + t.Parallel() + collection := &models.Collection{} collection.Name = "test" collection.RefreshId() @@ -322,6 +330,8 @@ func TestRecordTableName(t *testing.T) { } func TestRecordCollection(t *testing.T) { + t.Parallel() + collection := &models.Collection{} collection.RefreshId() @@ -333,6 +343,8 @@ func TestRecordCollection(t *testing.T) { } func TestRecordOriginalCopy(t *testing.T) { + t.Parallel() + m := models.NewRecord(&models.Collection{}) m.Load(map[string]any{"f": "123"}) @@ -360,6 +372,8 @@ func TestRecordOriginalCopy(t *testing.T) { } func TestRecordCleanCopy(t *testing.T) { + t.Parallel() + m := models.NewRecord(&models.Collection{ Name: "cname", Type: models.CollectionTypeAuth, @@ -392,6 +406,8 @@ func TestRecordCleanCopy(t *testing.T) { } func TestRecordSetAndGetExpand(t *testing.T) { + t.Parallel() + collection := &models.Collection{} m := models.NewRecord(collection) @@ -409,6 +425,8 @@ func TestRecordSetAndGetExpand(t *testing.T) { } func TestRecordMergeExpand(t *testing.T) { + t.Parallel() + collection := &models.Collection{} m := models.NewRecord(collection) m.Id = "m" @@ -501,6 +519,8 @@ func TestRecordMergeExpand(t *testing.T) { } func TestRecordMergeExpandNilCheck(t *testing.T) { + t.Parallel() + collection := &models.Collection{} scenarios := []struct { @@ -542,6 +562,8 @@ func TestRecordMergeExpandNilCheck(t *testing.T) { } func TestRecordExpandedRel(t *testing.T) { + t.Parallel() + collection := &models.Collection{} main := models.NewRecord(collection) @@ -574,6 +596,8 @@ func TestRecordExpandedRel(t *testing.T) { } func TestRecordExpandedAll(t *testing.T) { + t.Parallel() + collection := &models.Collection{} main := models.NewRecord(collection) @@ -606,6 +630,8 @@ func TestRecordExpandedAll(t *testing.T) { } func TestRecordSchemaData(t *testing.T) { + t.Parallel() + collection := &models.Collection{ Type: models.CollectionTypeAuth, Schema: schema.NewSchema( @@ -639,6 +665,8 @@ func TestRecordSchemaData(t *testing.T) { } func TestRecordUnknownData(t *testing.T) { + t.Parallel() + collection := &models.Collection{ Schema: schema.NewSchema( &schema.SchemaField{ @@ -719,6 +747,8 @@ func TestRecordUnknownData(t *testing.T) { } func TestRecordSetAndGet(t *testing.T) { + t.Parallel() + collection := &models.Collection{ Schema: schema.NewSchema( &schema.SchemaField{ @@ -799,6 +829,8 @@ func TestRecordSetAndGet(t *testing.T) { } func TestRecordGetBool(t *testing.T) { + t.Parallel() + scenarios := []struct { value any expected bool @@ -830,6 +862,8 @@ func TestRecordGetBool(t *testing.T) { } func TestRecordGetString(t *testing.T) { + t.Parallel() + scenarios := []struct { value any expected string @@ -860,6 +894,8 @@ func TestRecordGetString(t *testing.T) { } func TestRecordGetInt(t *testing.T) { + t.Parallel() + scenarios := []struct { value any expected int @@ -892,6 +928,8 @@ func TestRecordGetInt(t *testing.T) { } func TestRecordGetFloat(t *testing.T) { + t.Parallel() + scenarios := []struct { value any expected float64 @@ -924,6 +962,8 @@ func TestRecordGetFloat(t *testing.T) { } func TestRecordGetTime(t *testing.T) { + t.Parallel() + nowTime := time.Now() testTime, _ := time.Parse(types.DefaultDateLayout, "2022-01-01 08:00:40.000Z") @@ -957,6 +997,8 @@ func TestRecordGetTime(t *testing.T) { } func TestRecordGetDateTime(t *testing.T) { + t.Parallel() + nowTime := time.Now() testTime, _ := time.Parse(types.DefaultDateLayout, "2022-01-01 08:00:40.000Z") @@ -990,6 +1032,8 @@ func TestRecordGetDateTime(t *testing.T) { } func TestRecordGetStringSlice(t *testing.T) { + t.Parallel() + nowTime := time.Now() scenarios := []struct { @@ -1031,6 +1075,8 @@ func TestRecordGetStringSlice(t *testing.T) { } func TestRecordUnmarshalJSONField(t *testing.T) { + t.Parallel() + collection := &models.Collection{ Schema: schema.NewSchema(&schema.SchemaField{ Name: "field", @@ -1086,6 +1132,8 @@ func TestRecordUnmarshalJSONField(t *testing.T) { } func TestRecordBaseFilesPath(t *testing.T) { + t.Parallel() + collection := &models.Collection{} collection.RefreshId() collection.Name = "test" @@ -1102,6 +1150,8 @@ func TestRecordBaseFilesPath(t *testing.T) { } func TestRecordFindFileFieldByFile(t *testing.T) { + t.Parallel() + collection := &models.Collection{ Schema: schema.NewSchema( &schema.SchemaField{ @@ -1159,6 +1209,8 @@ func TestRecordFindFileFieldByFile(t *testing.T) { } func TestRecordLoadAndData(t *testing.T) { + t.Parallel() + collection := &models.Collection{ Schema: schema.NewSchema( &schema.SchemaField{ @@ -1232,6 +1284,8 @@ func TestRecordLoadAndData(t *testing.T) { } func TestRecordColumnValueMap(t *testing.T) { + t.Parallel() + collection := &models.Collection{ Schema: schema.NewSchema( &schema.SchemaField{ @@ -1319,6 +1373,8 @@ func TestRecordColumnValueMap(t *testing.T) { } func TestRecordPublicExportAndMarshalJSON(t *testing.T) { + t.Parallel() + collection := &models.Collection{ Name: "c_name", Schema: schema.NewSchema( @@ -1463,6 +1519,8 @@ func TestRecordPublicExportAndMarshalJSON(t *testing.T) { } func TestRecordUnmarshalJSON(t *testing.T) { + t.Parallel() + collection := &models.Collection{ Schema: schema.NewSchema( &schema.SchemaField{ @@ -1551,6 +1609,8 @@ func TestRecordUnmarshalJSON(t *testing.T) { } func TestRecordReplaceModifers(t *testing.T) { + t.Parallel() + collection := &models.Collection{ Schema: schema.NewSchema( &schema.SchemaField{ @@ -1658,6 +1718,8 @@ func TestRecordReplaceModifers(t *testing.T) { // ------------------------------------------------------------------- func TestRecordUsername(t *testing.T) { + t.Parallel() + scenarios := []struct { collectionType string expectError bool @@ -1699,6 +1761,8 @@ func TestRecordUsername(t *testing.T) { } func TestRecordEmail(t *testing.T) { + t.Parallel() + scenarios := []struct { collectionType string expectError bool @@ -1740,6 +1804,8 @@ func TestRecordEmail(t *testing.T) { } func TestRecordEmailVisibility(t *testing.T) { + t.Parallel() + scenarios := []struct { collectionType string value bool @@ -1782,6 +1848,8 @@ func TestRecordEmailVisibility(t *testing.T) { } func TestRecordEmailVerified(t *testing.T) { + t.Parallel() + scenarios := []struct { collectionType string value bool @@ -1824,6 +1892,8 @@ func TestRecordEmailVerified(t *testing.T) { } func TestRecordTokenKey(t *testing.T) { + t.Parallel() + scenarios := []struct { collectionType string expectError bool @@ -1865,6 +1935,8 @@ func TestRecordTokenKey(t *testing.T) { } func TestRecordRefreshTokenKey(t *testing.T) { + t.Parallel() + scenarios := []struct { collectionType string expectError bool @@ -1904,6 +1976,8 @@ func TestRecordRefreshTokenKey(t *testing.T) { } func TestRecordLastResetSentAt(t *testing.T) { + t.Parallel() + scenarios := []struct { collectionType string expectError bool @@ -1948,6 +2022,8 @@ func TestRecordLastResetSentAt(t *testing.T) { } func TestRecordLastVerificationSentAt(t *testing.T) { + t.Parallel() + scenarios := []struct { collectionType string expectError bool @@ -1992,6 +2068,8 @@ func TestRecordLastVerificationSentAt(t *testing.T) { } func TestRecordPasswordHash(t *testing.T) { + t.Parallel() + m := models.NewRecord(&models.Collection{}) if v := m.PasswordHash(); v != "" { @@ -2006,6 +2084,8 @@ func TestRecordPasswordHash(t *testing.T) { } func TestRecordValidatePassword(t *testing.T) { + t.Parallel() + // 123456 hash := "$2a$10$YKU8mPP8sTE3xZrpuM.xQuq27KJ7aIJB2oUeKPsDDqZshbl5g5cDK" @@ -2034,6 +2114,8 @@ func TestRecordValidatePassword(t *testing.T) { } func TestRecordSetPassword(t *testing.T) { + t.Parallel() + scenarios := []struct { collectionType string password string diff --git a/models/request.go b/models/request.go index 483eb7d8..0b1784c0 100644 --- a/models/request.go +++ b/models/request.go @@ -11,6 +11,7 @@ const ( RequestAuthRecord = "authRecord" ) +// Deprecated: Replaced by the Log model and will be removed in a future version. type Request struct { BaseModel diff --git a/models/request_info_test.go b/models/request_info_test.go index bc5be1e5..157ddac1 100644 --- a/models/request_info_test.go +++ b/models/request_info_test.go @@ -7,6 +7,8 @@ import ( ) func TestRequestInfoHasModifierDataKeys(t *testing.T) { + t.Parallel() + scenarios := []struct { name string requestInfo *models.RequestInfo diff --git a/tokens/admin_test.go b/tokens/admin_test.go index a6f571e5..8826e682 100644 --- a/tokens/admin_test.go +++ b/tokens/admin_test.go @@ -8,6 +8,8 @@ import ( ) func TestNewAdminAuthToken(t *testing.T) { + t.Parallel() + app, _ := tests.NewTestApp() defer app.Cleanup() @@ -31,6 +33,8 @@ func TestNewAdminAuthToken(t *testing.T) { } func TestNewAdminResetPasswordToken(t *testing.T) { + t.Parallel() + app, _ := tests.NewTestApp() defer app.Cleanup() @@ -54,6 +58,8 @@ func TestNewAdminResetPasswordToken(t *testing.T) { } func TestNewAdminFileToken(t *testing.T) { + t.Parallel() + app, _ := tests.NewTestApp() defer app.Cleanup() diff --git a/tokens/record_test.go b/tokens/record_test.go index 04358a6e..82e94fb6 100644 --- a/tokens/record_test.go +++ b/tokens/record_test.go @@ -8,6 +8,8 @@ import ( ) func TestNewRecordAuthToken(t *testing.T) { + t.Parallel() + app, _ := tests.NewTestApp() defer app.Cleanup() @@ -31,6 +33,8 @@ func TestNewRecordAuthToken(t *testing.T) { } func TestNewRecordVerifyToken(t *testing.T) { + t.Parallel() + app, _ := tests.NewTestApp() defer app.Cleanup() @@ -54,6 +58,8 @@ func TestNewRecordVerifyToken(t *testing.T) { } func TestNewRecordResetPasswordToken(t *testing.T) { + t.Parallel() + app, _ := tests.NewTestApp() defer app.Cleanup() @@ -77,6 +83,8 @@ func TestNewRecordResetPasswordToken(t *testing.T) { } func TestNewRecordChangeEmailToken(t *testing.T) { + t.Parallel() + app, _ := tests.NewTestApp() defer app.Cleanup() @@ -100,6 +108,8 @@ func TestNewRecordChangeEmailToken(t *testing.T) { } func TestNewRecordFileToken(t *testing.T) { + t.Parallel() + app, _ := tests.NewTestApp() defer app.Cleanup()