@@ -32,34 +32,10 @@ import (
3232 "github.com/snapcore/snapd/overlord/state"
3333 "github.com/snapcore/snapd/snap"
3434 "github.com/snapcore/snapd/systemd"
35+ "github.com/snapcore/snapd/systemd/systemdtest"
3536 "github.com/snapcore/snapd/testutil"
3637)
3738
38- type ResultForEnsureMountUnitFile struct {
39- path string
40- err error
41- }
42-
43- type FakeSystemdForMount struct {
44- systemd.Systemd
45-
46- RemoveMountUnitFileCalls []string
47- RemoveMountUnitFileResult error
48-
49- EnsureMountUnitFileCalls []* systemd.MountUnitOptions
50- EnsureMountUnitFileResult ResultForEnsureMountUnitFile
51- }
52-
53- func (s * FakeSystemdForMount ) RemoveMountUnitFile (baseDir string ) error {
54- s .RemoveMountUnitFileCalls = append (s .RemoveMountUnitFileCalls , baseDir )
55- return s .RemoveMountUnitFileResult
56- }
57-
58- func (s * FakeSystemdForMount ) EnsureMountUnitFile (options * systemd.MountUnitOptions ) (string , error ) {
59- s .EnsureMountUnitFileCalls = append (s .EnsureMountUnitFileCalls , options )
60- return s .EnsureMountUnitFileResult .path , s .EnsureMountUnitFileResult .err
61- }
62-
6339func CopyMap (m map [string ]any ) map [string ]any {
6440 cp := make (map [string ]any )
6541 for k , v := range m {
@@ -96,7 +72,7 @@ type mountSuite struct {
9672 mockContext * hookstate.Context
9773 mockHandler * hooktest.MockHandler
9874 hookTask * state.Task
99- sysd * FakeSystemdForMount
75+ sysd * systemdtest. FakeSystemd
10076 // A connection state for a snap using the mount interface with the plug
10177 // properly configured, which we'll be reusing in different test cases
10278 regularConnState map [string ]any
@@ -158,7 +134,7 @@ func (s *mountSuite) SetUpTest(c *C) {
158134 }
159135 s .hookTask = task
160136
161- s .sysd = & FakeSystemdForMount {}
137+ s .sysd = & systemdtest. FakeSystemd {}
162138 s .AddCleanup (systemd .MockNewSystemd (func (be systemd.Backend , roodDir string , mode systemd.InstanceMode , meter systemd.Reporter ) systemd.Systemd {
163139 return s .sysd
164140 }))
@@ -308,7 +284,7 @@ func (s *mountSuite) TestMissingProperPlug(c *C) {
308284func (s * mountSuite ) TestUnitCreationFailure (c * C ) {
309285 s .injectSnapWithProperPlug (c )
310286
311- s .sysd .EnsureMountUnitFileResult = ResultForEnsureMountUnitFile { "" , errors .New ("creation error" )}
287+ s .sysd .EnsureMountUnitFileResult . Err = errors .New ("creation error" )
312288
313289 _ , _ , err := ctlcmd .Run (s .mockContext , []string {"mount" , "-t" , "ext4" , "/src" , "/dest" }, 0 , nil )
314290 c .Check (err , ErrorMatches , `cannot ensure mount unit: creation error` )
@@ -328,7 +304,7 @@ func (s *mountSuite) TestUnitCreationFailure(c *C) {
328304func (s * mountSuite ) TestHappy (c * C ) {
329305 s .injectSnapWithProperPlug (c )
330306
331- s .sysd .EnsureMountUnitFileResult = ResultForEnsureMountUnitFile { "/path/unit.mount" , nil }
307+ s .sysd .EnsureMountUnitFileResult . Path = "/path/unit.mount"
332308
333309 _ , _ , err := ctlcmd .Run (s .mockContext , []string {"mount" , "--persistent" , "-t" , "ext4" , "-o" , "sync,rw" , "/src" , "/dest" }, 0 , nil )
334310 c .Check (err , IsNil )
@@ -349,7 +325,7 @@ func (s *mountSuite) TestHappy(c *C) {
349325func (s * mountSuite ) TestHappyWithVariableExpansion (c * C ) {
350326 s .injectSnapWithProperPlug (c )
351327
352- s .sysd .EnsureMountUnitFileResult = ResultForEnsureMountUnitFile { "/path/unit.mount" , nil }
328+ s .sysd .EnsureMountUnitFileResult . Path = "/path/unit.mount"
353329
354330 // Now try with $SNAP_* variables in the paths
355331 snapDataDir := filepath .Join (dirs .SnapDataDir , "snap1" , "1" )
@@ -372,7 +348,7 @@ func (s *mountSuite) TestHappyWithVariableExpansion(c *C) {
372348func (s * mountSuite ) TestHappyWithCommasInPath (c * C ) {
373349 s .injectSnapWithProperPlug (c )
374350
375- s .sysd .EnsureMountUnitFileResult = ResultForEnsureMountUnitFile { "/path/unit.mount" , nil }
351+ s .sysd .EnsureMountUnitFileResult . Path = "/path/unit.mount"
376352
377353 // Now try with commas in the paths
378354 _ , _ , err := ctlcmd .Run (s .mockContext , []string {"mount" , "-o" , "ro" , "/dev/dma_heap/qcom,qseecom" , "/dest,with,commas" }, 0 , nil )
@@ -393,7 +369,7 @@ func (s *mountSuite) TestHappyWithCommasInPath(c *C) {
393369func (s * mountSuite ) TestHappyNFS (c * C ) {
394370 s .injectSnapWithProperPlug (c )
395371
396- s .sysd .EnsureMountUnitFileResult = ResultForEnsureMountUnitFile { "/path/unit.mount" , nil }
372+ s .sysd .EnsureMountUnitFileResult . Path = "/path/unit.mount"
397373
398374 // Now try with commas in the paths
399375 _ , _ , err := ctlcmd .Run (s .mockContext , []string {"mount" , "-o" , "rw" , "-t" , "nfs" , "localhost:/var/share" , "/nfs-dest" }, 0 , nil )
@@ -415,7 +391,7 @@ func (s *mountSuite) TestHappyNFS(c *C) {
415391func (s * mountSuite ) TestHappyCIFS (c * C ) {
416392 s .injectSnapWithProperPlug (c )
417393
418- s .sysd .EnsureMountUnitFileResult = ResultForEnsureMountUnitFile { "/path/unit.mount" , nil }
394+ s .sysd .EnsureMountUnitFileResult . Path = "/path/unit.mount"
419395
420396 // Now try with commas in the paths
421397 _ , _ , err := ctlcmd .Run (s .mockContext , []string {"mount" , "-o" , "rw,guest" , "-t" , "cifs" , "//10.0.0.1/share/path" , "/cifs-dest" }, 0 , nil )
@@ -437,7 +413,7 @@ func (s *mountSuite) TestHappyCIFS(c *C) {
437413func (s * mountSuite ) TestEnsureMountUnitFailed (c * C ) {
438414 s .injectSnapWithProperPlug (c )
439415
440- s .sysd .EnsureMountUnitFileResult = ResultForEnsureMountUnitFile { "" , errors .New ("some error" )}
416+ s .sysd .EnsureMountUnitFileResult . Err = errors .New ("some error" )
441417
442418 _ , _ , err := ctlcmd .Run (s .mockContext , []string {"mount" , "--persistent" , "-t" , "ext4" , "-o" , "sync,rw" , "/src" , "/dest" }, 0 , nil )
443419 c .Check (err , ErrorMatches , `cannot ensure mount unit: some error` )
@@ -460,7 +436,7 @@ func (s *mountSuite) TestEnsureMountUnitFailed(c *C) {
460436func (s * mountSuite ) TestEnsureMountUnitFailedRemoveFailed (c * C ) {
461437 s .injectSnapWithProperPlug (c )
462438
463- s .sysd .EnsureMountUnitFileResult = ResultForEnsureMountUnitFile { "" , errors .New ("some error" )}
439+ s .sysd .EnsureMountUnitFileResult . Err = errors .New ("some error" )
464440 s .sysd .RemoveMountUnitFileResult = errors .New ("some other error" )
465441
466442 _ , _ , err := ctlcmd .Run (s .mockContext , []string {"mount" , "--persistent" , "-t" , "ext4" , "-o" , "sync,rw" , "/src" , "/dest" }, 0 , nil )
0 commit comments