initial v0.8 pre-release

This commit is contained in:
Gani Georgiev
2022-10-30 10:28:14 +02:00
parent 9cbb2e750e
commit 90dba45d7c
388 changed files with 21580 additions and 13603 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ import (
)
// DefaultDateLayout specifies the default app date strings layout.
const DefaultDateLayout = "2006-01-02 15:04:05.000"
const DefaultDateLayout = "2006-01-02 15:04:05.000Z"
// NowDateTime returns new DateTime instance with the current local time.
func NowDateTime() DateTime {
+10 -10
View File
@@ -31,8 +31,8 @@ func TestParseDateTime(t *testing.T) {
{"invalid", ""},
{nowDateTime, nowStr},
{nowTime, nowStr},
{1641024040, "2022-01-01 08:00:40.000"},
{"2022-01-01 11:23:45.678", "2022-01-01 11:23:45.678"},
{1641024040, "2022-01-01 08:00:40.000Z"},
{"2022-01-01 11:23:45.678", "2022-01-01 11:23:45.678Z"},
}
for i, s := range scenarios {
@@ -49,7 +49,7 @@ func TestParseDateTime(t *testing.T) {
}
func TestDateTimeTime(t *testing.T) {
str := "2022-01-01 11:23:45.678"
str := "2022-01-01 11:23:45.678Z"
expected, err := time.Parse(types.DefaultDateLayout, str)
if err != nil {
@@ -86,7 +86,7 @@ func TestDateTimeString(t *testing.T) {
t.Fatalf("Expected empty string for zer datetime, got %q", dt0.String())
}
expected := "2022-01-01 11:23:45.678"
expected := "2022-01-01 11:23:45.678Z"
dt1, _ := types.ParseDateTime(expected)
if dt1.String() != expected {
t.Fatalf("Expected %q, got %v", expected, dt1)
@@ -99,7 +99,7 @@ func TestDateTimeMarshalJSON(t *testing.T) {
expected string
}{
{"", `""`},
{"2022-01-01 11:23:45.678", `"2022-01-01 11:23:45.678"`},
{"2022-01-01 11:23:45.678", `"2022-01-01 11:23:45.678Z"`},
}
for i, s := range scenarios {
@@ -128,7 +128,7 @@ func TestDateTimeUnmarshalJSON(t *testing.T) {
{"invalid_json", ""},
{"'123'", ""},
{"2022-01-01 11:23:45.678", ""},
{`"2022-01-01 11:23:45.678"`, "2022-01-01 11:23:45.678"},
{`"2022-01-01 11:23:45.678"`, "2022-01-01 11:23:45.678Z"},
}
for i, s := range scenarios {
@@ -148,8 +148,8 @@ func TestDateTimeValue(t *testing.T) {
}{
{"", ""},
{"invalid", ""},
{1641024040, "2022-01-01 08:00:40.000"},
{"2022-01-01 11:23:45.678", "2022-01-01 11:23:45.678"},
{1641024040, "2022-01-01 08:00:40.000Z"},
{"2022-01-01 11:23:45.678", "2022-01-01 11:23:45.678Z"},
{types.NowDateTime(), types.NowDateTime().String()},
}
@@ -179,8 +179,8 @@ func TestDateTimeScan(t *testing.T) {
{"invalid", ""},
{types.NowDateTime(), now},
{time.Now(), now},
{1641024040, "2022-01-01 08:00:40.000"},
{"2022-01-01 11:23:45.678", "2022-01-01 11:23:45.678"},
{1641024040, "2022-01-01 08:00:40.000Z"},
{"2022-01-01 11:23:45.678", "2022-01-01 11:23:45.678Z"},
}
for i, s := range scenarios {
-4
View File
@@ -23,10 +23,6 @@ func (m JsonArray) MarshalJSON() ([]byte, error) {
// Value implements the [driver.Valuer] interface.
func (m JsonArray) Value() (driver.Value, error) {
if m == nil {
return nil, nil
}
data, err := json.Marshal(m)
return string(data), err
+1 -1
View File
@@ -36,7 +36,7 @@ func TestJsonArrayValue(t *testing.T) {
json types.JsonArray
expected driver.Value
}{
{nil, nil},
{nil, `[]`},
{types.JsonArray{}, `[]`},
{types.JsonArray{1, 2, 3}, `[1,2,3]`},
{types.JsonArray{"test1", "test2", "test3"}, `["test1","test2","test3"]`},
-4
View File
@@ -23,10 +23,6 @@ func (m JsonMap) MarshalJSON() ([]byte, error) {
// Value implements the [driver.Valuer] interface.
func (m JsonMap) Value() (driver.Value, error) {
if m == nil {
return nil, nil
}
data, err := json.Marshal(m)
return string(data), err
+1 -1
View File
@@ -35,7 +35,7 @@ func TestJsonMapValue(t *testing.T) {
json types.JsonMap
expected driver.Value
}{
{nil, nil},
{nil, `{}`},
{types.JsonMap{}, `{}`},
{types.JsonMap{"test1": 123, "test2": "lorem"}, `{"test1":123,"test2":"lorem"}`},
{types.JsonMap{"test": []int{1, 2, 3}}, `{"test":[1,2,3]}`},
+8
View File
@@ -0,0 +1,8 @@
// Package types implements some commonly used db serializable types
// like datetime, json, etc.
package types
// Pointer is a generic helper that returns val as *T.
func Pointer[T any](val T) *T {
return &val
}
+24
View File
@@ -0,0 +1,24 @@
package types_test
import (
"testing"
"github.com/pocketbase/pocketbase/tools/types"
)
func TestPointer(t *testing.T) {
s1 := types.Pointer("")
if s1 == nil || *s1 != "" {
t.Fatalf("Expected empty string pointer, got %#v", s1)
}
s2 := types.Pointer("test")
if s2 == nil || *s2 != "test" {
t.Fatalf("Expected 'test' string pointer, got %#v", s2)
}
s3 := types.Pointer(123)
if s3 == nil || *s3 != 123 {
t.Fatalf("Expected 123 string pointer, got %#v", s3)
}
}
+27
View File
@@ -0,0 +1,27 @@
const { exec } = require('node:child_process');
// you can use any other library for copying directories recursively
const fse = require('fs-extra');
let controller; // this will be used to terminate the PocketBase process
const srcTestDirPath = "./test_pb_data";
const tempTestDirPath = "./temp_test_pb_data";
beforeEach(() => {
// copy test_pb_date to a temp location
fse.copySync(srcTestDirPath, tempTestDirPath);
controller = new AbortController();
// start PocketBase with the test_pb_data
exec('./pocketbase serve --dir=' + tempTestDirPath, { signal: controller.signal});
});
afterEach(() => {
// stop the PocketBase process
controller.abort();
// clean up the temp test directory
fse.removeSync(tempTestDirPath);
});