github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/storage/provider/common_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package provider_test 5 6 import ( 7 "os" 8 "path/filepath" 9 10 "github.com/juju/names/v5" 11 jc "github.com/juju/testing/checkers" 12 gc "gopkg.in/check.v1" 13 14 "github.com/juju/juju/environs/context" 15 "github.com/juju/juju/storage" 16 "github.com/juju/juju/storage/provider" 17 ) 18 19 type providerCommonSuite struct{} 20 21 var _ = gc.Suite(&providerCommonSuite{}) 22 23 func (s *providerCommonSuite) TestCommonProvidersExported(c *gc.C) { 24 registry := provider.CommonStorageProviders() 25 var common []storage.ProviderType 26 pTypes, err := registry.StorageProviderTypes() 27 c.Assert(err, jc.ErrorIsNil) 28 for _, pType := range pTypes { 29 common = append(common, pType) 30 p, err := registry.StorageProvider(pType) 31 c.Assert(err, jc.ErrorIsNil) 32 c.Assert(p, gc.NotNil) 33 } 34 c.Assert(common, jc.SameContents, []storage.ProviderType{ 35 provider.LoopProviderType, 36 provider.RootfsProviderType, 37 provider.TmpfsProviderType, 38 }) 39 } 40 41 // testDetachFilesystems is a test-case for detaching filesystems that use 42 // the common "maybeUnmount" method. 43 func testDetachFilesystems( 44 c *gc.C, commands *mockRunCommand, 45 source storage.FilesystemSource, 46 callCtx context.ProviderCallContext, 47 mounted bool, 48 etcDir, fstab string, 49 ) { 50 if mounted { 51 commands.expect("umount", testMountPoint) 52 } 53 54 results, err := source.DetachFilesystems(callCtx, []storage.FilesystemAttachmentParams{{ 55 Filesystem: names.NewFilesystemTag("0/0"), 56 FilesystemId: "filesystem-0-0", 57 AttachmentParams: storage.AttachmentParams{ 58 Machine: names.NewMachineTag("0"), 59 InstanceId: "inst-id", 60 }, 61 Path: testMountPoint, 62 }}) 63 c.Assert(err, jc.ErrorIsNil) 64 c.Assert(results, gc.HasLen, 1) 65 c.Assert(results[0], jc.ErrorIsNil) 66 67 data, err := os.ReadFile(filepath.Join(etcDir, "fstab")) 68 if os.IsNotExist(err) { 69 c.Assert(fstab, gc.Equals, "") 70 return 71 } 72 c.Assert(err, jc.ErrorIsNil) 73 c.Assert(string(data), gc.Equals, fstab) 74 }