github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/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  	"github.com/juju/names"
    10  	jc "github.com/juju/testing/checkers"
    11  	gc "gopkg.in/check.v1"
    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  	var common []storage.ProviderType
    23  	for pType, p := range provider.CommonProviders() {
    24  		common = append(common, pType)
    25  		_, ok := p.(storage.Provider)
    26  		c.Check(ok, jc.IsTrue)
    27  	}
    28  	c.Assert(common, jc.SameContents, []storage.ProviderType{
    29  		provider.LoopProviderType,
    30  		provider.RootfsProviderType,
    31  		provider.TmpfsProviderType,
    32  	})
    33  }
    34  
    35  // testDetachFilesystems is a test-case for detaching filesystems that use
    36  // the common "maybeUnmount" method.
    37  func testDetachFilesystems(c *gc.C, commands *mockRunCommand, source storage.FilesystemSource, mounted bool) {
    38  	const testMountPoint = "/in/the/place"
    39  
    40  	cmd := commands.expect("df", "--output=source", filepath.Dir(testMountPoint))
    41  	cmd.respond("headers\n/same/as/rootfs", nil)
    42  	cmd = commands.expect("df", "--output=source", testMountPoint)
    43  	if mounted {
    44  		cmd.respond("headers\n/different/to/rootfs", nil)
    45  		commands.expect("umount", testMountPoint)
    46  	} else {
    47  		cmd.respond("headers\n/same/as/rootfs", nil)
    48  	}
    49  
    50  	results, err := source.DetachFilesystems([]storage.FilesystemAttachmentParams{{
    51  		Filesystem:   names.NewFilesystemTag("0/0"),
    52  		FilesystemId: "filesystem-0-0",
    53  		AttachmentParams: storage.AttachmentParams{
    54  			Machine:    names.NewMachineTag("0"),
    55  			InstanceId: "inst-id",
    56  		},
    57  		Path: testMountPoint,
    58  	}})
    59  	c.Assert(err, jc.ErrorIsNil)
    60  	c.Assert(results, gc.HasLen, 1)
    61  	c.Assert(results[0], jc.ErrorIsNil)
    62  }