From e0be10bf30a58c66948650bff9ed3a887cfef9e0 Mon Sep 17 00:00:00 2001 From: H1rono Date: Fri, 3 Jan 2025 21:58:47 +0900 Subject: [PATCH] :recycle: Replace `context.Background()` in model tests --- model/admin_impl_test.go | 8 ++--- model/comment_impl_test.go | 9 +++-- model/file_impl_test.go | 21 ++++++------ model/group_impl_test.go | 31 ++++++++--------- model/request_impl_test.go | 49 +++++++++++++-------------- model/request_status_impl_test.go | 3 +- model/request_target_impl_test.go | 7 ++-- model/tag_impl_test.go | 9 +++-- model/transaction_detail_impl_test.go | 9 +++-- model/transaction_impl_test.go | 25 +++++++------- model/user_impl_test.go | 31 ++++++++--------- 11 files changed, 96 insertions(+), 106 deletions(-) diff --git a/model/admin_impl_test.go b/model/admin_impl_test.go index 5ac48115..45561119 100644 --- a/model/admin_impl_test.go +++ b/model/admin_impl_test.go @@ -1,17 +1,17 @@ package model import ( - "context" "testing" "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/traPtitech/Jomon/testutil" "github.com/traPtitech/Jomon/testutil/random" ) func TestEntRepository_GetAdmins(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_admins") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -53,7 +53,7 @@ func TestEntRepository_GetAdmins(t *testing.T) { } func TestEntRepository_AddAdmins(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "add_admins") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -77,7 +77,7 @@ func TestEntRepository_AddAdmins(t *testing.T) { } func TestEntRepository_DeleteAdmins(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "delete_admins") require.NoError(t, err) repo := NewEntRepository(client, storage) diff --git a/model/comment_impl_test.go b/model/comment_impl_test.go index c76c4137..7be9dbb5 100644 --- a/model/comment_impl_test.go +++ b/model/comment_impl_test.go @@ -1,7 +1,6 @@ package model import ( - "context" "testing" "time" @@ -14,7 +13,7 @@ import ( ) func TestEntRepository_GetComments(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_comments") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -83,7 +82,7 @@ func TestEntRepository_GetComments(t *testing.T) { } func TestEntRepository_CreateComment(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "create_comment") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -159,7 +158,7 @@ func TestEntRepository_CreateComment(t *testing.T) { } func TestEntRepository_UpdateComment(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "update_comment") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -285,7 +284,7 @@ func TestEntRepository_UpdateComment(t *testing.T) { } func TestEntRepository_DeleteComment(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "delete_comment") require.NoError(t, err) repo := NewEntRepository(client, storage) diff --git a/model/file_impl_test.go b/model/file_impl_test.go index 8bda6143..ad13dfd4 100644 --- a/model/file_impl_test.go +++ b/model/file_impl_test.go @@ -1,7 +1,6 @@ package model import ( - "context" "testing" "time" @@ -14,14 +13,14 @@ import ( ) func TestEntRepository_CreateFile(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "create_file") require.NoError(t, err) repo := NewEntRepository(client, storage) t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) var tags []*Tag var targets []*RequestTarget @@ -60,7 +59,7 @@ func TestEntRepository_CreateFile(t *testing.T) { t.Run("UnknownRequest", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user, err := repo.CreateUser( ctx, @@ -82,7 +81,7 @@ func TestEntRepository_CreateFile(t *testing.T) { t.Run("MissingName", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) var tags []*Tag var targets []*RequestTarget @@ -109,14 +108,14 @@ func TestEntRepository_CreateFile(t *testing.T) { } func TestEntRepository_GetFile(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_file") require.NoError(t, err) repo := NewEntRepository(client, storage) t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) var tags []*Tag var targets []*RequestTarget @@ -156,7 +155,7 @@ func TestEntRepository_GetFile(t *testing.T) { t.Run("UnknownFile", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) _, err = repo.GetFile(ctx, uuid.New()) assert.Error(t, err) @@ -164,14 +163,14 @@ func TestEntRepository_GetFile(t *testing.T) { } func TestEntRepository_DeleteFile(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "delete_file") require.NoError(t, err) repo := NewEntRepository(client, storage) t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) var tags []*Tag var targets []*RequestTarget @@ -207,7 +206,7 @@ func TestEntRepository_DeleteFile(t *testing.T) { t.Run("UnknownFile", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) err = repo.DeleteFile(ctx, uuid.New()) assert.Error(t, err) diff --git a/model/group_impl_test.go b/model/group_impl_test.go index 4969748f..38e7522e 100644 --- a/model/group_impl_test.go +++ b/model/group_impl_test.go @@ -1,7 +1,6 @@ package model import ( - "context" "testing" "time" @@ -14,7 +13,7 @@ import ( ) func TestEntRepository_GetGroups(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_groups") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -47,7 +46,7 @@ func TestEntRepository_GetGroups(t *testing.T) { } func TestEntRepository_GetGroup(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_group") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -76,7 +75,7 @@ func TestEntRepository_GetGroup(t *testing.T) { } func TestEntRepository_CreateGroup(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "create_group") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -131,7 +130,7 @@ func TestEntRepository_CreateGroup(t *testing.T) { } func TestEntRepository_UpdateGroup(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "update_group") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -227,7 +226,7 @@ func TestEntRepository_UpdateGroup(t *testing.T) { } func TestEntRepository_DeleteGroup(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "delete_group") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -258,7 +257,7 @@ func TestEntRepository_DeleteGroup(t *testing.T) { } func TestEntRepository_GetMembers(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_members") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -306,7 +305,7 @@ func TestEntRepository_GetMembers(t *testing.T) { t.Run("Success2", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) budget := random.Numeric(t, 100000) group, err := repo.CreateGroup( ctx, @@ -322,7 +321,7 @@ func TestEntRepository_GetMembers(t *testing.T) { } func TestEntRepository_CreateMember(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "create_member") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -352,7 +351,7 @@ func TestEntRepository_CreateMember(t *testing.T) { t.Run("UnknownUser", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) budget := random.Numeric(t, 100000) group, err := repo.CreateGroup( ctx, @@ -367,7 +366,7 @@ func TestEntRepository_CreateMember(t *testing.T) { } func TestEntRepository_DeleteMember(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "delete_member") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -397,7 +396,7 @@ func TestEntRepository_DeleteMember(t *testing.T) { } func TestEntRepository_GetOwners(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_owners") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -442,7 +441,7 @@ func TestEntRepository_GetOwners(t *testing.T) { t.Run("Success2", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) budget := random.Numeric(t, 100000) group, err := repo.CreateGroup( ctx, @@ -459,7 +458,7 @@ func TestEntRepository_GetOwners(t *testing.T) { // FIXME: これAddOwnersでは? func TestEntRepository_CreateOwner(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "create_owner") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -489,7 +488,7 @@ func TestEntRepository_CreateOwner(t *testing.T) { t.Run("UnknownUser", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) budget := random.Numeric(t, 100000) group, err := repo.CreateGroup( ctx, @@ -504,7 +503,7 @@ func TestEntRepository_CreateOwner(t *testing.T) { } func TestEntRepository_DeleteOwner(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "delete_owner") require.NoError(t, err) repo := NewEntRepository(client, storage) diff --git a/model/request_impl_test.go b/model/request_impl_test.go index 643d6c50..08ea811c 100644 --- a/model/request_impl_test.go +++ b/model/request_impl_test.go @@ -1,7 +1,6 @@ package model import ( - "context" "testing" "time" @@ -31,7 +30,7 @@ func (rd *RequestDetail) toExpectedRequestResponse(t *testing.T) *RequestRespons } func TestEntRepository_GetRequests(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_requests") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -62,7 +61,7 @@ func TestEntRepository_GetRequests(t *testing.T) { t.Run("SuccessWithSortCreatedAt", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user1, err := repo.CreateUser( ctx, random.AlphaNumeric(t, 20), @@ -130,7 +129,7 @@ func TestEntRepository_GetRequests(t *testing.T) { t.Run("SuccessWithReverseSortCreatedAt", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user1, err := repo2.CreateUser( ctx, random.AlphaNumeric(t, 20), @@ -198,7 +197,7 @@ func TestEntRepository_GetRequests(t *testing.T) { t.Run("SuccessWithSortTitle", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user1, err := repo3.CreateUser( ctx, random.AlphaNumeric(t, 20), @@ -265,7 +264,7 @@ func TestEntRepository_GetRequests(t *testing.T) { t.Run("SuccessWithReverseSortTitle", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user1, err := repo4.CreateUser( ctx, random.AlphaNumeric(t, 20), @@ -332,7 +331,7 @@ func TestEntRepository_GetRequests(t *testing.T) { t.Run("SuccessWithQueryTarget", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user1, err := repo5.CreateUser( ctx, random.AlphaNumeric(t, 20), @@ -397,7 +396,7 @@ func TestEntRepository_GetRequests(t *testing.T) { t.Run("SuccessWithQuerySince", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user1, err := repo6.CreateUser( ctx, random.AlphaNumeric(t, 20), @@ -459,7 +458,7 @@ func TestEntRepository_GetRequests(t *testing.T) { t.Run("SuccessWithQueryUntil", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user1, err := repo7.CreateUser( ctx, random.AlphaNumeric(t, 20), @@ -522,7 +521,7 @@ func TestEntRepository_GetRequests(t *testing.T) { t.Run("SuccessWithQueryStatus", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user1, err := repo8.CreateUser( ctx, random.AlphaNumeric(t, 20), @@ -591,7 +590,7 @@ func TestEntRepository_GetRequests(t *testing.T) { t.Run("SuccessWithQueryCreatedBy", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user1, err := repo9.CreateUser( ctx, random.AlphaNumeric(t, 20), @@ -649,7 +648,7 @@ func TestEntRepository_GetRequests(t *testing.T) { } func TestEntRepository_CreateRequest(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "create_request") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -665,7 +664,7 @@ func TestEntRepository_CreateRequest(t *testing.T) { t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) title := random.AlphaNumeric(t, 40) content := random.AlphaNumeric(t, 100) user, err := repo.CreateUser( @@ -723,7 +722,7 @@ func TestEntRepository_CreateRequest(t *testing.T) { t.Run("UnknownUser", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) title := random.AlphaNumeric(t, 40) content := random.AlphaNumeric(t, 100) tag, err := repo2.CreateTag(ctx, random.AlphaNumeric(t, 20)) @@ -747,7 +746,7 @@ func TestEntRepository_CreateRequest(t *testing.T) { t.Run("UnknownTag", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) title := random.AlphaNumeric(t, 40) content := random.AlphaNumeric(t, 100) user, err := repo3.CreateUser( @@ -783,7 +782,7 @@ func TestEntRepository_CreateRequest(t *testing.T) { t.Run("UnknownGroup", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) title := random.AlphaNumeric(t, 40) content := random.AlphaNumeric(t, 100) user, err := repo4.CreateUser( @@ -816,7 +815,7 @@ func TestEntRepository_CreateRequest(t *testing.T) { } func TestEntRepository_GetRequest(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_request") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -826,7 +825,7 @@ func TestEntRepository_GetRequest(t *testing.T) { t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user, err := repo.CreateUser( ctx, random.AlphaNumeric(t, 20), @@ -862,14 +861,14 @@ func TestEntRepository_GetRequest(t *testing.T) { t.Run("UnknownRequest", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) _, err := repo2.GetRequest(ctx, uuid.New()) assert.Error(t, err) }) } func TestEntRepository_UpdateRequest(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "update_request") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -888,7 +887,7 @@ func TestEntRepository_UpdateRequest(t *testing.T) { t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user, err := repo.CreateUser( ctx, random.AlphaNumeric(t, 20), @@ -949,7 +948,7 @@ func TestEntRepository_UpdateRequest(t *testing.T) { t.Run("Success2", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user, err := repo2.CreateUser( ctx, random.AlphaNumeric(t, 20), @@ -1011,7 +1010,7 @@ func TestEntRepository_UpdateRequest(t *testing.T) { t.Run("Success3", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user, err := repo3.CreateUser( ctx, random.AlphaNumeric(t, 20), @@ -1072,7 +1071,7 @@ func TestEntRepository_UpdateRequest(t *testing.T) { t.Run("UnknownTag", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user, err := repo4.CreateUser( ctx, random.AlphaNumeric(t, 20), @@ -1117,7 +1116,7 @@ func TestEntRepository_UpdateRequest(t *testing.T) { t.Run("UnknownGroup", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user, err := repo5.CreateUser( ctx, random.AlphaNumeric(t, 20), diff --git a/model/request_status_impl_test.go b/model/request_status_impl_test.go index f5eee7e2..0f64f9dd 100644 --- a/model/request_status_impl_test.go +++ b/model/request_status_impl_test.go @@ -1,7 +1,6 @@ package model import ( - "context" "testing" "time" @@ -14,7 +13,7 @@ import ( ) func TestEntRepository_CreateStatus(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "create_status") require.NoError(t, err) repo := NewEntRepository(client, storage) diff --git a/model/request_target_impl_test.go b/model/request_target_impl_test.go index c81210a2..ca4a08d2 100644 --- a/model/request_target_impl_test.go +++ b/model/request_target_impl_test.go @@ -1,7 +1,6 @@ package model import ( - "context" "testing" "time" @@ -13,7 +12,7 @@ import ( ) func TestEntRepository_GetRequestTargets(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_request_targets") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -89,7 +88,7 @@ func TestEntRepository_GetRequestTargets(t *testing.T) { } func TestEntRepository_createRequestTargets(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "create_request_targets") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -139,7 +138,7 @@ func TestEntRepository_createRequestTargets(t *testing.T) { } func TestEntRepository_deleteRequestTargets(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "delete_request_targets") require.NoError(t, err) repo := NewEntRepository(client, storage) diff --git a/model/tag_impl_test.go b/model/tag_impl_test.go index d734d002..c8f04045 100644 --- a/model/tag_impl_test.go +++ b/model/tag_impl_test.go @@ -1,7 +1,6 @@ package model import ( - "context" "testing" "time" @@ -13,7 +12,7 @@ import ( ) func TestEntRepository_GetTags(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_tags") assert.NoError(t, err) repo := NewEntRepository(client, storage) @@ -46,7 +45,7 @@ func TestEntRepository_GetTags(t *testing.T) { } func TestEntRepository_CreateTag(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "create_tag") assert.NoError(t, err) repo := NewEntRepository(client, storage) @@ -79,7 +78,7 @@ func TestEntRepository_CreateTag(t *testing.T) { } func TestEntRepository_UpdateTag(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "update_tag") assert.NoError(t, err) repo := NewEntRepository(client, storage) @@ -130,7 +129,7 @@ func TestEntRepository_UpdateTag(t *testing.T) { } func TestEntRepository_DeleteTag(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "delete_tag") assert.NoError(t, err) repo := NewEntRepository(client, storage) diff --git a/model/transaction_detail_impl_test.go b/model/transaction_detail_impl_test.go index bc118967..0ad15a17 100644 --- a/model/transaction_detail_impl_test.go +++ b/model/transaction_detail_impl_test.go @@ -1,7 +1,6 @@ package model import ( - "context" "testing" "time" @@ -13,14 +12,14 @@ import ( ) func TestEntRepository_createTransactionDetail(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "create_transaction_detail") require.NoError(t, err) repo := NewEntRepository(client, storage) t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) tx, err := client.Tx(ctx) require.NoError(t, err) defer func() { @@ -52,14 +51,14 @@ func TestEntRepository_createTransactionDetail(t *testing.T) { } func TestEntRepository_updateTransactionDetail(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "update_transaction_detail") require.NoError(t, err) repo := NewEntRepository(client, storage) t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) tx, err := client.Tx(ctx) require.NoError(t, err) defer func() { diff --git a/model/transaction_impl_test.go b/model/transaction_impl_test.go index e9bd4795..145c6802 100644 --- a/model/transaction_impl_test.go +++ b/model/transaction_impl_test.go @@ -1,7 +1,6 @@ package model import ( - "context" "testing" "time" @@ -14,7 +13,7 @@ import ( ) func TestEntRepository_GetTransactions(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_transactions") require.NoError(t, err) repo := NewEntRepository(client, storage) @@ -177,7 +176,7 @@ func TestEntRepository_GetTransactions(t *testing.T) { t.Run("SuccessWithSortAmountDesc", func(t *testing.T) { err := dropAll(t, ctx, client) require.NoError(t, err) - ctx := context.Background() + ctx := testutil.NewContext(t) // Create user // nolint:contextcheck @@ -501,13 +500,13 @@ func TestEntRepository_GetTransactions(t *testing.T) { } func TestEntRepository_GetTransaction(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_transaction") require.NoError(t, err) repo := NewEntRepository(client, storage) t.Run("Success", func(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) // Create user user, err := repo.CreateUser( @@ -542,14 +541,14 @@ func TestEntRepository_GetTransaction(t *testing.T) { } func TestEntRepository_CreateTransaction(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "create_transaction") require.NoError(t, err) repo := NewEntRepository(client, storage) t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) amount := random.Numeric(t, 100000) @@ -608,7 +607,7 @@ func TestEntRepository_CreateTransaction(t *testing.T) { t.Run("SuccessWithoutTags", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) title := random.AlphaNumeric(t, 20) amount := random.Numeric(t, 100000) @@ -660,7 +659,7 @@ func TestEntRepository_CreateTransaction(t *testing.T) { t.Run("SuccessWithoutGroup", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) title := random.AlphaNumeric(t, 20) amount := random.Numeric(t, 100000) @@ -711,7 +710,7 @@ func TestEntRepository_CreateTransaction(t *testing.T) { t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) // Create Transactions title := random.AlphaNumeric(t, 20) @@ -739,7 +738,7 @@ func TestEntRepository_CreateTransaction(t *testing.T) { t.Run("SuccessWithNegativeAmount", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) // Create Transactions title := random.AlphaNumeric(t, 20) @@ -766,14 +765,14 @@ func TestEntRepository_CreateTransaction(t *testing.T) { } func TestEntRepository_UpdateTransaction(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "update_transaction") require.NoError(t, err) repo := NewEntRepository(client, storage) t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) title := random.AlphaNumeric(t, 20) amount := random.Numeric(t, 100000) diff --git a/model/user_impl_test.go b/model/user_impl_test.go index 50be2632..a37df27a 100644 --- a/model/user_impl_test.go +++ b/model/user_impl_test.go @@ -1,7 +1,6 @@ package model import ( - "context" "testing" "time" @@ -13,7 +12,7 @@ import ( ) func TestEntRepository_GetUsers(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_user") assert.NoError(t, err) repo := NewEntRepository(client, storage) @@ -23,7 +22,7 @@ func TestEntRepository_GetUsers(t *testing.T) { t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) got, err := repo.GetUsers(ctx) assert.NoError(t, err) @@ -32,7 +31,7 @@ func TestEntRepository_GetUsers(t *testing.T) { t.Run("Success2", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) user1, err := repo2.CreateUser(ctx, "user1", "user1", true) assert.NoError(t, err) @@ -53,14 +52,14 @@ func TestEntRepository_GetUsers(t *testing.T) { } func TestEntRepository_CreateUser(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "create_user") assert.NoError(t, err) repo := NewEntRepository(client, storage) t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) name := random.AlphaNumeric(t, 20) dn := random.AlphaNumeric(t, 20) @@ -83,7 +82,7 @@ func TestEntRepository_CreateUser(t *testing.T) { t.Run("MissingName", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) name := "" dn := random.AlphaNumeric(t, 20) @@ -95,7 +94,7 @@ func TestEntRepository_CreateUser(t *testing.T) { } func TestEntRepository_GetUserByName(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_user_by_name") assert.NoError(t, err) repo := NewEntRepository(client, storage) @@ -105,7 +104,7 @@ func TestEntRepository_GetUserByName(t *testing.T) { t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) name := random.AlphaNumeric(t, 20) dn := random.AlphaNumeric(t, 20) admin := random.Numeric(t, 2) == 1 @@ -121,14 +120,14 @@ func TestEntRepository_GetUserByName(t *testing.T) { t.Run("UnknownName", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) _, err = repo2.GetUserByName(ctx, random.AlphaNumeric(t, 20)) assert.Error(t, err) }) } func TestEntRepository_GetUserByID(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "get_user_by_id") assert.NoError(t, err) repo := NewEntRepository(client, storage) @@ -138,7 +137,7 @@ func TestEntRepository_GetUserByID(t *testing.T) { t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) name := random.AlphaNumeric(t, 20) dn := random.AlphaNumeric(t, 20) admin := random.Numeric(t, 2) == 1 @@ -154,21 +153,21 @@ func TestEntRepository_GetUserByID(t *testing.T) { t.Run("UnknownUserID", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) _, err := repo2.GetUserByID(ctx, uuid.New()) assert.Error(t, err) }) } func TestEntRepository_UpdateUser(t *testing.T) { - ctx := context.Background() + ctx := testutil.NewContext(t) client, storage, err := setup(t, ctx, "update_user") assert.NoError(t, err) repo := NewEntRepository(client, storage) t.Run("Success", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) name := random.AlphaNumeric(t, 20) dn := random.AlphaNumeric(t, 20) @@ -196,7 +195,7 @@ func TestEntRepository_UpdateUser(t *testing.T) { t.Run("MissingName", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := testutil.NewContext(t) name := random.AlphaNumeric(t, 20) dn := random.AlphaNumeric(t, 20)