Skip to content

Commit 46d7851

Browse files
committed
2 parents 02e8cd8 + c1d6c20 commit 46d7851

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

Diff for: benchmarks/bench_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ func envOrDefault(key string, def string) string {
2222

2323
func dbURL() string {
2424
return fmt.Sprintf(
25-
"postgres://%s:%s@0.0.0.0:5432/%s?sslmode=disable",
25+
"postgres://%s:%s@%s/%s?sslmode=disable",
2626
envOrDefault("DBUSER", "testing"),
2727
envOrDefault("DBPASS", "testing"),
28+
envOrDefault("DBHOST", "0.0.0.0:5432"),
2829
envOrDefault("DBNAME", "testing"),
2930
)
3031
}

Diff for: common_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ func envOrDefault(key string, def string) string {
1919

2020
func openTestDB() (*sql.DB, error) {
2121
return sql.Open("postgres", fmt.Sprintf(
22-
"postgres://%s:%s@0.0.0.0:5432/%s?sslmode=disable",
22+
"postgres://%s:%s@%s/%s?sslmode=disable",
2323
envOrDefault("DBUSER", "testing"),
2424
envOrDefault("DBPASS", "testing"),
25+
envOrDefault("DBHOST", "0.0.0.0:5432"),
2526
envOrDefault("DBNAME", "testing"),
2627
))
2728
}

Diff for: model.go

+2-14
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package kallax
22

33
import (
44
"bytes"
5+
"crypto/rand"
56
"database/sql"
67
"database/sql/driver"
78
"encoding/hex"
89
"fmt"
9-
"math/rand"
10-
"sync"
1110
"time"
1211

1312
"github.com/oklog/ulid"
@@ -227,13 +226,6 @@ type Record interface {
227226
Saveable
228227
}
229228

230-
var randPool = &sync.Pool{
231-
New: func() interface{} {
232-
seed := time.Now().UnixNano() + rand.Int63()
233-
return rand.NewSource(seed)
234-
},
235-
}
236-
237229
// ULID is an ID type provided by kallax that is a lexically sortable UUID.
238230
// The internal representation is an ULID (https://github.com/oklog/ulid).
239231
// It already implements sql.Scanner and driver.Valuer, so it's perfectly
@@ -242,11 +234,7 @@ type ULID uuid.UUID
242234

243235
// NewULID returns a new ULID, which is a lexically sortable UUID.
244236
func NewULID() ULID {
245-
entropy := randPool.Get().(rand.Source)
246-
id := ULID(ulid.MustNew(ulid.Timestamp(time.Now()), rand.New(entropy)))
247-
randPool.Put(entropy)
248-
249-
return id
237+
return ULID(ulid.MustNew(ulid.Timestamp(time.Now()), rand.Reader))
250238
}
251239

252240
// NewULIDFromText creates a new ULID from its string representation. Will

Diff for: types/slices_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,10 @@ func envOrDefault(key string, def string) string {
217217

218218
func openTestDB() (*sql.DB, error) {
219219
return sql.Open("postgres", fmt.Sprintf(
220-
"postgres://%s:%s@0.0.0.0:5432/%s?sslmode=disable",
220+
"postgres://%s:%s@%s/%s?sslmode=disable",
221221
envOrDefault("DBUSER", "testing"),
222222
envOrDefault("DBPASS", "testing"),
223+
envOrDefault("DBHOST", "0.0.0.0:5432"),
223224
envOrDefault("DBNAME", "testing"),
224225
))
225226
}

Diff for: types/types_test.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ func TestNullable(t *testing.T) {
139139
PtrDuration *time.Duration
140140
)
141141
tim := time.Now().UTC()
142-
tim = time.Date(tim.Year(), tim.Month(), tim.Day(), tim.Hour(), tim.Minute(), tim.Second(), 0, tim.Location())
142+
tim = time.Date(tim.Year(), tim.Month(), tim.Day(), tim.Hour(),
143+
tim.Minute(), tim.Second(), 0, tim.Location())
143144
s := require.New(t)
144145
url, err := url.Parse("http://foo.me")
145146
s.NoError(err)
@@ -431,7 +432,14 @@ func TestNullable(t *testing.T) {
431432
if c.isPtr {
432433
elem = elem.Elem()
433434
}
434-
s.Equal(c.nonNullInput, elem.Interface(), c.name)
435+
436+
result := elem.Interface()
437+
switch v := result.(type) {
438+
case time.Time:
439+
result = v.UTC()
440+
}
441+
442+
s.Equal(c.nonNullInput, result, c.name)
435443

436444
_, err = db.Exec("DROP TABLE foo")
437445
s.Nil(err, c.name)

0 commit comments

Comments
 (0)