Skip to content

Commit

Permalink
chore(server(: upgrade golangci-lint to v1.51
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Feb 14, 2023
1 parent bb1b9cd commit 9c8714b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.49
version: v1.51
args: --timeout=10m
working-directory: server
- name: test
Expand Down
30 changes: 24 additions & 6 deletions server/internal/usecase/interactor/scene_plugin_test.go
Expand Up @@ -7,10 +7,12 @@ import (
"github.com/reearth/reearth/server/internal/infrastructure/fs"
"github.com/reearth/reearth/server/internal/infrastructure/memory"
"github.com/reearth/reearth/server/internal/usecase"
"github.com/reearth/reearth/server/internal/usecase/gateway"
"github.com/reearth/reearth/server/internal/usecase/interfaces"
"github.com/reearth/reearth/server/pkg/id"
"github.com/reearth/reearth/server/pkg/layer"
"github.com/reearth/reearth/server/pkg/plugin"
"github.com/reearth/reearth/server/pkg/plugin/pluginpack"
"github.com/reearth/reearth/server/pkg/property"
"github.com/reearth/reearth/server/pkg/scene"
"github.com/reearth/reearthx/rerror"
Expand Down Expand Up @@ -85,8 +87,9 @@ func TestScene_InstallPlugin(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
// t.Parallel() // avoid data race
assert := assert.New(t)
ctx := context.Background()

Expand All @@ -96,7 +99,6 @@ func TestScene_InstallPlugin(t *testing.T) {
sc.Plugins().Add(p)
}
sr := memory.NewSceneWith(sc)

pl := plugin.New().ID(pid).MustBuild()
pl2 := plugin.New().ID(pid3).Schema(id.NewPropertySchemaID(pid3, "@").Ref()).MustBuild()
pl3 := plugin.New().ID(pid4).MustBuild()
Expand All @@ -105,10 +107,11 @@ func TestScene_InstallPlugin(t *testing.T) {
prr := memory.NewProperty()

uc := &Scene{
sceneRepo: sr,
pluginRepo: pr,
propertyRepo: prr,
transaction: &usecasex.NopTransaction{},
sceneRepo: sr,
pluginRepo: pr,
pluginRegistry: &mockPluginRegistry{},
propertyRepo: prr,
transaction: &usecasex.NopTransaction{},
}

o := tt.args.operator
Expand Down Expand Up @@ -194,6 +197,7 @@ func TestScene_UninstallPlugin(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
assert := assert.New(t)
Expand Down Expand Up @@ -332,6 +336,7 @@ func TestScene_UpgradePlugin(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
assert := assert.New(t)
Expand Down Expand Up @@ -364,6 +369,7 @@ func TestScene_UpgradePlugin(t *testing.T) {
propertySchemaRepo: psr,
layerRepo: lr,
datasetRepo: dsr,
pluginRegistry: &mockPluginRegistry{},
transaction: &usecasex.NopTransaction{},
}

Expand All @@ -389,3 +395,15 @@ func TestScene_UpgradePlugin(t *testing.T) {
})
}
}

type mockPluginRegistry struct {
gateway.PluginRegistry
}

func (g *mockPluginRegistry) FetchPluginPackage(context.Context, id.PluginID) (*pluginpack.Package, error) {
return nil, rerror.ErrNotFound
}

func (g *mockPluginRegistry) NotifyDownload(context.Context, id.PluginID) error {
return nil
}
4 changes: 4 additions & 0 deletions server/internal/usecase/interactor/usecase.go
Expand Up @@ -101,6 +101,10 @@ func Run3[A, B, C any](ctx context.Context, op *usecase.Operator, r *repo.Contai
}

func (u *uc) checkPermission(op *usecase.Operator) error {
if op == nil {
return nil
}

ok := true
if u.readableWorkspaces != nil {
ok = op.IsReadableWorkspace(u.readableWorkspaces...)
Expand Down
21 changes: 11 additions & 10 deletions server/internal/usecase/interactor/usecase_test.go
Expand Up @@ -14,7 +14,7 @@ import (
)

func TestUc_checkPermission(t *testing.T) {
tid := id.NewWorkspaceID()
wid := id.NewWorkspaceID()
sid := id.NewSceneID()

tests := []struct {
Expand All @@ -37,11 +37,11 @@ func TestUc_checkPermission(t *testing.T) {
},
{
name: "can read a workspace",
readableWorkspaces: id.WorkspaceIDList{tid},
readableWorkspaces: id.WorkspaceIDList{wid},
op: &usecase.Operator{
ReadableWorkspaces: id.WorkspaceIDList{tid},
ReadableWorkspaces: id.WorkspaceIDList{wid},
},
wantErr: true,
wantErr: false,
},
{
name: "cannot read a workspace",
Expand All @@ -53,15 +53,15 @@ func TestUc_checkPermission(t *testing.T) {
},
{
name: "can write a workspace",
writableWorkspaces: id.WorkspaceIDList{tid},
writableWorkspaces: id.WorkspaceIDList{wid},
op: &usecase.Operator{
WritableWorkspaces: id.WorkspaceIDList{tid},
WritableWorkspaces: id.WorkspaceIDList{wid},
},
wantErr: true,
wantErr: false,
},
{
name: "cannot write a workspace",
writableWorkspaces: id.WorkspaceIDList{tid},
writableWorkspaces: id.WorkspaceIDList{wid},
op: &usecase.Operator{
WritableWorkspaces: id.WorkspaceIDList{},
},
Expand All @@ -73,7 +73,7 @@ func TestUc_checkPermission(t *testing.T) {
op: &usecase.Operator{
ReadableScenes: id.SceneIDList{sid},
},
wantErr: true,
wantErr: false,
},
{
name: "cannot read a scene",
Expand All @@ -89,7 +89,7 @@ func TestUc_checkPermission(t *testing.T) {
op: &usecase.Operator{
WritableScenes: id.SceneIDList{sid},
},
wantErr: true,
wantErr: false,
},
{
name: "cannot write a scene",
Expand All @@ -102,6 +102,7 @@ func TestUc_checkPermission(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion server/pkg/layer/merged_test.go
Expand Up @@ -367,7 +367,7 @@ func TestMerge(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
// t.Parallel() // avoid data race
actual := Merge(tt.o, tt.p)
assert.Equal(t, tt.want, actual)
})
Expand Down
22 changes: 12 additions & 10 deletions server/pkg/tag/group_test.go
Expand Up @@ -126,11 +126,12 @@ func TestGroup_AddTag(t *testing.T) {
expected: IDList{tid},
},
}
for _, tc := range tests {
t.Run(tc.name, func(tt *testing.T) {
tt.Parallel()
tc.tag.AddTag(tc.input...)
assert.Equal(tt, tc.tag.tags, tc.expected)
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
tt.tag.AddTag(tt.input...)
assert.Equal(t, tt.tag.tags, tt.expected)
})
}
}
Expand All @@ -152,11 +153,12 @@ func TestGroup_RemoveTag(t *testing.T) {
expected: IDList{tid},
},
}
for _, tc := range tests {
t.Run(tc.name, func(tt *testing.T) {
tt.Parallel()
tc.tag.RemoveTag(tc.input...)
assert.Equal(tt, tc.tag.tags, tc.expected)
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
tt.tag.RemoveTag(tt.input...)
assert.Equal(t, tt.tag.tags, tt.expected)
})
}
}

0 comments on commit 9c8714b

Please sign in to comment.