github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/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  	"path/filepath"
     8  
     9  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  	"gopkg.in/juju/names.v2"
    12  
    13  	"github.com/juju/juju/storage"
    14  	"github.com/juju/juju/storage/provider"
    15  )
    16  
    17  type providerCommonSuite struct{}
    18  
    19  var _ = gc.Suite(&providerCommonSuite{})
    20  
    21  func (s *providerCommonSuite) TestCommonProvidersExported(c *gc.C) {
    22  	registry := provider.CommonStorageProviders()
    23  	var common []storage.ProviderType
    24  	pTypes, err := registry.StorageProviderTypes()
    25  	c.Assert(err, jc.ErrorIsNil)
    26  	for _, pType := range pTypes {
    27  		common = append(common, pType)
    28  		p, err := registry.StorageProvider(pType)
    29  		c.Assert(err, jc.ErrorIsNil)
    30  		c.Assert(p, gc.NotNil)
    31  	}
    32  	c.Assert(common, jc.SameContents, []storage.ProviderType{
    33  		provider.LoopProviderType,
    34  		provider.RootfsProviderType,
    35  		provider.TmpfsProviderType,
    36  	})
    37  }
    38  
    39  // testDetachFilesystems is a test-case for detaching filesystems that use
    40  // the common "maybeUnmount" method.
    41  func testDetachFilesystems(c *gc.C, commands *mockRunCommand, source storage.FilesystemSource, mounted bool) {
    42  	const testMountPoint = "/in/the/place"
    43  
    44  	cmd := commands.expect("df", "--output=source", filepath.Dir(testMountPoint))
    45  	cmd.respond("headers\n/same/as/rootfs", nil)
    46  	cmd = commands.expect("df", "--output=source", testMountPoint)
    47  	if mounted {
    48  		cmd.respond("headers\n/different/to/rootfs", nil)
    49  		commands.expect("umount", testMountPoint)
    50  	} else {
    51  		cmd.respond("headers\n/same/as/rootfs", nil)
    52  	}
    53  
    54  	results, err := source.DetachFilesystems([]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  }