From 819199a6bd987c2dc09fe7c4bc018bec633906ae Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Mon, 23 Dec 2024 03:21:35 +0530 Subject: [PATCH] Some Test Written --- src/interfaces/admin-user.entity_test.go | 1 + src/interfaces/base-entity_test.go | 36 ++++++++++++++---------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/interfaces/admin-user.entity_test.go b/src/interfaces/admin-user.entity_test.go index 56123d3..5779616 100644 --- a/src/interfaces/admin-user.entity_test.go +++ b/src/interfaces/admin-user.entity_test.go @@ -37,6 +37,7 @@ func TestAdminUserEntity(t *testing.T) { if e.UserRolesInterface.Role != ROLE_ADMIN { t.Fatalf("UserRolesInterface Role is not ROLE_ADMIN") } + testBaseEntityCreateNewId(t, e.BaseEntity) t.Run("password match", func(t *testing.T) { if !e.MatchPassword("password") { t.Fatalf("Password does not match") diff --git a/src/interfaces/base-entity_test.go b/src/interfaces/base-entity_test.go index 32ac05b..d6675f6 100644 --- a/src/interfaces/base-entity_test.go +++ b/src/interfaces/base-entity_test.go @@ -5,30 +5,36 @@ import ( "time" ) +func testBaseEntityCreateNewId(t *testing.T, c *BaseEntity) { + + if c.ID == "" { + t.Fatalf("Id is empty") + } + + if c.CreatedAt.IsZero() { + t.Fatalf("CreatedAt is empty") + } + if c.ModifiedAt.IsZero() { + t.Fatalf("ModifiedAt is empty") + } + if !c.CreatedAtExported.IsZero() { + t.Fatalf("CreatedAtExported is not empty %d", c.CreatedAtExported.Unix()) + } + if !c.ModifiedAtExported.IsZero() { + t.Fatalf("ModifiedAtExported is not empty") + } +} + func TestBaseEntity(t *testing.T) { c := &BaseEntity{} c.createNewId() t.Run("Create New ID", func(t *testing.T) { id := c.ID c.createNewId() - if c.ID == "" { - t.Fatalf("Id is empty") - } if c.ID == id { t.Fatalf("Id Should Be Different") } - if c.CreatedAt.IsZero() { - t.Fatalf("CreatedAt is empty") - } - if c.ModifiedAt.IsZero() { - t.Fatalf("ModifiedAt is empty") - } - if !c.CreatedAtExported.IsZero() { - t.Fatalf("CreatedAtExported is not empty %d", c.CreatedAtExported.Unix()) - } - if !c.ModifiedAtExported.IsZero() { - t.Fatalf("ModifiedAtExported is not empty") - } + testBaseEntityCreateNewId(t, c) }) t.Run("AddTimeStamps", func(t *testing.T) { now := time.Now()