@@ -10,6 +10,20 @@ import (
1010 "github.com/google/uuid"
1111)
1212
13+ func compareTimePtr (t * testing.T , actual * time.Time , expected * time.Time ) {
14+ t .Helper ()
15+ if actual == nil && expected == nil {
16+ return
17+ }
18+ if actual == nil || expected == nil {
19+ t .Fatalf ("expected %v, got %v" , expected , actual )
20+ }
21+ // Compare with some tolerance for database timestamp precision
22+ if actual .Unix () != expected .Unix () {
23+ t .Fatalf ("expected %v, got %v" , expected , actual )
24+ }
25+ }
26+
1327func validateRetrievedResources (t * testing.T , actualResources []* oapi.Resource , expectedResources []* oapi.Resource ) {
1428 t .Helper ()
1529 if len (actualResources ) != len (expectedResources ) {
@@ -76,15 +90,15 @@ func validateRetrievedResources(t *testing.T, actualResources []*oapi.Resource,
7690 }
7791
7892 // Validate timestamps (basic presence check)
79- if actualResource .CreatedAt == "" {
93+ if actualResource .CreatedAt . IsZero () {
8094 t .Fatalf ("expected resource created_at to be set" )
8195 }
82- compareStrPtr (t , actualResource .LockedAt , expectedResource .LockedAt )
96+ compareTimePtr (t , actualResource .LockedAt , expectedResource .LockedAt )
8397 // Note: updated_at can be set by DB on update, so we just check if expected is set
8498 if expectedResource .UpdatedAt != nil && actualResource .UpdatedAt == nil {
8599 t .Fatalf ("expected resource updated_at to be set" )
86100 }
87- compareStrPtr (t , actualResource .DeletedAt , expectedResource .DeletedAt )
101+ compareTimePtr (t , actualResource .DeletedAt , expectedResource .DeletedAt )
88102 }
89103}
90104
@@ -100,7 +114,7 @@ func TestDBResources_BasicWrite(t *testing.T) {
100114
101115 id := uuid .New ().String ()
102116 name := fmt .Sprintf ("test-resource-%s" , id [:8 ])
103- createdAt := time .Now (). Format ( time . RFC3339 )
117+ createdAt := time .Now ()
104118 resource := & oapi.Resource {
105119 Id : id ,
106120 Version : "v1" ,
@@ -150,7 +164,7 @@ func TestDBResources_BasicWriteAndDelete(t *testing.T) {
150164
151165 id := uuid .New ().String ()
152166 name := fmt .Sprintf ("test-resource-%s" , id [:8 ])
153- createdAt := time .Now (). Format ( time . RFC3339 )
167+ createdAt := time .Now ()
154168 resource := & oapi.Resource {
155169 Id : id ,
156170 Version : "v1" ,
@@ -221,7 +235,7 @@ func TestDBResources_BasicWriteAndUpdate(t *testing.T) {
221235
222236 id := uuid .New ().String ()
223237 name := fmt .Sprintf ("test-resource-%s" , id [:8 ])
224- createdAt := time .Now (). Format ( time . RFC3339 )
238+ createdAt := time .Now ()
225239 resource := & oapi.Resource {
226240 Id : id ,
227241 Version : "v1" ,
@@ -296,7 +310,7 @@ func TestDBResources_MetadataUpdate(t *testing.T) {
296310
297311 id := uuid .New ().String ()
298312 name := fmt .Sprintf ("test-resource-%s" , id [:8 ])
299- createdAt := time .Now (). Format ( time . RFC3339 )
313+ createdAt := time .Now ()
300314 resource := & oapi.Resource {
301315 Id : id ,
302316 Version : "v1" ,
@@ -366,7 +380,7 @@ func TestDBResources_EmptyMetadata(t *testing.T) {
366380
367381 id := uuid .New ().String ()
368382 name := fmt .Sprintf ("test-resource-%s" , id [:8 ])
369- createdAt := time .Now (). Format ( time . RFC3339 )
383+ createdAt := time .Now ()
370384 resource := & oapi.Resource {
371385 Id : id ,
372386 Version : "v1" ,
@@ -409,9 +423,9 @@ func TestDBResources_WithTimestamps(t *testing.T) {
409423
410424 id := uuid .New ().String ()
411425 name := fmt .Sprintf ("test-resource-%s" , id [:8 ])
412- createdAt := time .Now ().Add (- 24 * time .Hour ). Format ( time . RFC3339 )
413- lockedAt := time .Now ().Add (- 1 * time .Hour ). Format ( time . RFC3339 )
414- updatedAt := time .Now (). Format ( time . RFC3339 )
426+ createdAt := time .Now ().Add (- 24 * time .Hour )
427+ lockedAt := time .Now ().Add (- 1 * time .Hour )
428+ updatedAt := time .Now ()
415429 resource := & oapi.Resource {
416430 Id : id ,
417431 Version : "v1" ,
@@ -456,7 +470,7 @@ func TestDBResources_ComplexConfig(t *testing.T) {
456470
457471 id := uuid .New ().String ()
458472 name := fmt .Sprintf ("test-resource-%s" , id [:8 ])
459- createdAt := time .Now (). Format ( time . RFC3339 )
473+ createdAt := time .Now ()
460474 resource := & oapi.Resource {
461475 Id : id ,
462476 Version : "v1" ,
@@ -505,7 +519,7 @@ func TestDBResources_NonexistentWorkspaceThrowsError(t *testing.T) {
505519 }
506520 defer tx .Rollback (t .Context ())
507521
508- createdAt := time .Now (). Format ( time . RFC3339 )
522+ createdAt := time .Now ()
509523 resource := & oapi.Resource {
510524 Id : uuid .New ().String (),
511525 Version : "v1" ,
@@ -540,7 +554,7 @@ func TestDBResources_MultipleResources(t *testing.T) {
540554 }
541555 defer tx .Rollback (t .Context ())
542556
543- createdAt := time .Now (). Format ( time . RFC3339 )
557+ createdAt := time .Now ()
544558 resources := []* oapi.Resource {
545559 {
546560 Id : uuid .New ().String (),
@@ -610,7 +624,7 @@ func TestDBResources_WorkspaceIsolation(t *testing.T) {
610624 }
611625 defer tx1 .Rollback (t .Context ())
612626
613- createdAt := time .Now (). Format ( time . RFC3339 )
627+ createdAt := time .Now ()
614628 resource1 := & oapi.Resource {
615629 Id : uuid .New ().String (),
616630 Version : "v1" ,
@@ -697,8 +711,8 @@ func TestDBResources_SoftDeleteFiltering(t *testing.T) {
697711 }
698712 defer tx .Rollback (t .Context ())
699713
700- createdAt := time .Now (). Format ( time . RFC3339 )
701- deletedAt := time .Now (). Format ( time . RFC3339 )
714+ createdAt := time .Now ()
715+ deletedAt := time .Now ()
702716
703717 // Create a resource with deleted_at set (soft deleted)
704718 softDeletedResource := & oapi.Resource {
0 commit comments