Skip to content

Commit

Permalink
♻️ Replace context.Background() in model tests
Browse files Browse the repository at this point in the history
  • Loading branch information
H1rono committed Jan 3, 2025
1 parent 26666f9 commit e0be10b
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 106 deletions.
8 changes: 4 additions & 4 deletions model/admin_impl_test.go
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions model/comment_impl_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package model

import (
"context"
"testing"
"time"

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 10 additions & 11 deletions model/file_impl_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package model

import (
"context"
"testing"
"time"

Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -156,22 +155,22 @@ 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)
})
}

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
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 15 additions & 16 deletions model/group_impl_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package model

import (
"context"
"testing"
"time"

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
Loading

0 comments on commit e0be10b

Please sign in to comment.