github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/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/core/instance"
    13  	"github.com/juju/juju/testing"
    14  )
    15  
    16  type factorySuite struct {
    17  	testing.BaseSuite
    18  }
    19  
    20  var _ = gc.Suite(&factorySuite{})
    21  
    22  func (*factorySuite) TestNewContainerManager(c *gc.C) {
    23  	for _, test := range []struct {
    24  		containerType instance.ContainerType
    25  		valid         bool
    26  	}{{
    27  		containerType: instance.LXD,
    28  		valid:         true,
    29  	}, {
    30  		containerType: instance.LXD,
    31  		valid:         true,
    32  	}, {
    33  		containerType: instance.KVM,
    34  		valid:         true,
    35  	}, {
    36  		containerType: instance.NONE,
    37  		valid:         false,
    38  	}, {
    39  		containerType: instance.ContainerType("other"),
    40  		valid:         false,
    41  	}} {
    42  		conf := container.ManagerConfig{container.ConfigModelUUID: testing.ModelTag.Id()}
    43  		manager, err := factory.NewContainerManager(test.containerType, conf)
    44  		if test.valid {
    45  			c.Assert(err, jc.ErrorIsNil)
    46  			c.Assert(manager, gc.NotNil)
    47  		} else {
    48  			c.Assert(err, gc.ErrorMatches, `unknown container type: ".*"`)
    49  			c.Assert(manager, gc.IsNil)
    50  		}
    51  	}
    52  }