Skip to content

Commit c9756a9

Browse files
committed
Remove mock for mountutil tests
Signed-off-by: apostasie <[email protected]>
1 parent 92188e1 commit c9756a9

File tree

5 files changed

+37
-250
lines changed

5 files changed

+37
-250
lines changed

pkg/mountutil/mountutil_linux_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ import (
2222
"testing"
2323

2424
"github.com/opencontainers/runtime-spec/specs-go"
25-
"go.uber.org/mock/gomock"
2625
"gotest.tools/v3/assert"
2726
is "gotest.tools/v3/assert/cmp"
2827

2928
"github.com/containerd/containerd/v2/core/mount"
3029
"github.com/containerd/containerd/v2/pkg/oci"
31-
32-
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/native"
33-
mocks "github.com/containerd/nerdctl/v2/pkg/mountutil/mountutilmock"
3430
)
3531

3632
// TestParseVolumeOptions tests volume options are parsed as expected.
@@ -265,23 +261,6 @@ func TestProcessFlagV(t *testing.T) {
265261
},
266262
}
267263

268-
ctrl := gomock.NewController(t)
269-
defer ctrl.Finish()
270-
271-
mockVolumeStore := mocks.NewMockVolumeStore(ctrl)
272-
mockVolumeStore.
273-
EXPECT().
274-
Get(gomock.Any(), false).
275-
Return(&native.Volume{Name: "test_volume", Mountpoint: "/test/volume", Size: 1024}, nil).
276-
AnyTimes()
277-
mockVolumeStore.
278-
EXPECT().
279-
Create(gomock.Any(), nil).
280-
Return(&native.Volume{Name: "test_volume", Mountpoint: "/test/volume"}, nil).AnyTimes()
281-
282-
mockOs := mocks.NewMockOs(ctrl)
283-
mockOs.EXPECT().Stat(gomock.Any()).Return(nil, nil).AnyTimes()
284-
285264
for _, tt := range tests {
286265
t.Run(tt.rawSpec, func(t *testing.T) {
287266
processedVolSpec, err := ProcessFlagV(tt.rawSpec, mockVolumeStore, false)
@@ -347,16 +326,6 @@ func TestProcessFlagVAnonymousVolumes(t *testing.T) {
347326
},
348327
}
349328

350-
ctrl := gomock.NewController(t)
351-
defer ctrl.Finish()
352-
353-
mockVolumeStore := mocks.NewMockVolumeStore(ctrl)
354-
mockVolumeStore.
355-
EXPECT().
356-
Create(gomock.Any(), []string{}).
357-
Return(&native.Volume{Name: "test_volume", Mountpoint: "/test/volume"}, nil).
358-
AnyTimes()
359-
360329
for _, tt := range tests {
361330
t.Run(tt.rawSpec, func(t *testing.T) {
362331
processedVolSpec, err := ProcessFlagV(tt.rawSpec, mockVolumeStore, true)

pkg/mountutil/mountutil_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package mountutil
18+
19+
import (
20+
"runtime"
21+
22+
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/native"
23+
"github.com/containerd/nerdctl/v2/pkg/mountutil/volumestore"
24+
)
25+
26+
type MockVolumeStore struct {
27+
volumestore.VolumeStore
28+
}
29+
30+
func (mv *MockVolumeStore) CreateWithoutLock(name string, labels []string) (*native.Volume, error) {
31+
if runtime.GOOS == "windows" {
32+
return &native.Volume{Name: "test_volume", Mountpoint: "C:\\test\\directory"}, nil
33+
}
34+
return &native.Volume{Name: "test_volume", Mountpoint: "/test/volume"}, nil
35+
}
36+
37+
var mockVolumeStore = &MockVolumeStore{}

pkg/mountutil/mountutil_windows_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ import (
2222
"testing"
2323

2424
"github.com/opencontainers/runtime-spec/specs-go"
25-
"go.uber.org/mock/gomock"
2625
"gotest.tools/v3/assert"
2726
is "gotest.tools/v3/assert/cmp"
28-
29-
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/native"
30-
mocks "github.com/containerd/nerdctl/v2/pkg/mountutil/mountutilmock"
3127
)
3228

3329
func TestParseVolumeOptions(t *testing.T) {
@@ -268,23 +264,6 @@ func TestProcessFlagV(t *testing.T) {
268264
},
269265
}
270266

271-
ctrl := gomock.NewController(t)
272-
defer ctrl.Finish()
273-
274-
mockVolumeStore := mocks.NewMockVolumeStore(ctrl)
275-
mockVolumeStore.
276-
EXPECT().
277-
Get(gomock.Any(), false).
278-
Return(&native.Volume{Name: "test_volume", Mountpoint: "C:\\test\\directory", Size: 1024}, nil).
279-
AnyTimes()
280-
mockVolumeStore.
281-
EXPECT().
282-
Create(gomock.Any(), nil).
283-
Return(&native.Volume{Name: "test_volume", Mountpoint: "C:\\test\\directory"}, nil).AnyTimes()
284-
285-
mockOs := mocks.NewMockOs(ctrl)
286-
mockOs.EXPECT().Stat(gomock.Any()).Return(nil, nil).AnyTimes()
287-
288267
for _, tt := range tests {
289268
t.Run(tt.rawSpec, func(t *testing.T) {
290269
processedVolSpec, err := ProcessFlagV(tt.rawSpec, mockVolumeStore, true)
@@ -342,16 +321,6 @@ func TestProcessFlagVAnonymousVolumes(t *testing.T) {
342321
},
343322
}
344323

345-
ctrl := gomock.NewController(t)
346-
defer ctrl.Finish()
347-
348-
mockVolumeStore := mocks.NewMockVolumeStore(ctrl)
349-
mockVolumeStore.
350-
EXPECT().
351-
Create(gomock.Any(), []string{}).
352-
Return(&native.Volume{Name: "test_volume", Mountpoint: "C:\\test\\directory"}, nil).
353-
AnyTimes()
354-
355324
for _, tt := range tests {
356325
t.Run(tt.rawSpec, func(t *testing.T) {
357326
processedVolSpec, err := ProcessFlagV(tt.rawSpec, mockVolumeStore, true)

pkg/mountutil/mountutilmock/os.mock.go

Lines changed: 0 additions & 56 deletions
This file was deleted.

pkg/mountutil/mountutilmock/volumestore.mock.go

Lines changed: 0 additions & 132 deletions
This file was deleted.

0 commit comments

Comments
 (0)