github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/container/factory/factory_test.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package factory_test
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  
    10  	"github.com/juju/juju/container"
    11  	"github.com/juju/juju/container/factory"
    12  	"github.com/juju/juju/container/lxd"
    13  	"github.com/juju/juju/instance"
    14  	"github.com/juju/juju/testing"
    15  )
    16  
    17  type factorySuite struct {
    18  	testing.BaseSuite
    19  }
    20  
    21  var _ = gc.Suite(&factorySuite{})
    22  
    23  func (*factorySuite) TestNewContainerManager(c *gc.C) {
    24  	for _, test := range []struct {
    25  		containerType instance.ContainerType
    26  		valid         bool
    27  	}{{
    28  		containerType: instance.LXC,
    29  		valid:         true,
    30  	}, {
    31  		containerType: instance.LXD,
    32  		valid:         true,
    33  	}, {
    34  		containerType: instance.KVM,
    35  		valid:         true,
    36  	}, {
    37  		containerType: instance.NONE,
    38  		valid:         false,
    39  	}, {
    40  		containerType: instance.ContainerType("other"),
    41  		valid:         false,
    42  	}} {
    43  		/* LXD isn't available in go 1.2 */
    44  		if test.containerType == instance.LXD && !lxd.HasLXDSupport() {
    45  			continue
    46  		}
    47  
    48  		conf := container.ManagerConfig{container.ConfigName: "test"}
    49  		manager, err := factory.NewContainerManager(test.containerType, conf, nil)
    50  		if test.valid {
    51  			c.Assert(err, jc.ErrorIsNil)
    52  			c.Assert(manager, gc.NotNil)
    53  		} else {
    54  			c.Assert(err, gc.ErrorMatches, `unknown container type: ".*"`)
    55  			c.Assert(manager, gc.IsNil)
    56  		}
    57  	}
    58  }