github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/core/lxdprofile/validate_test.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package lxdprofile_test
     5  
     6  import (
     7  	"github.com/golang/mock/gomock"
     8  	"github.com/juju/testing"
     9  	gc "gopkg.in/check.v1"
    10  	charm "gopkg.in/juju/charm.v6"
    11  
    12  	apicharms "github.com/juju/juju/api/charms"
    13  	"github.com/juju/juju/core/lxdprofile"
    14  )
    15  
    16  type LXDProfileSuite struct {
    17  	testing.IsolationSuite
    18  }
    19  
    20  var _ = gc.Suite(&LXDProfileSuite{})
    21  
    22  func (*LXDProfileSuite) TestValidateWithEmptyConfig(c *gc.C) {
    23  	ctrl := gomock.NewController(c)
    24  	defer ctrl.Finish()
    25  
    26  	profile := &charm.LXDProfile{}
    27  
    28  	lxdprofiler := NewMockLXDProfiler(ctrl)
    29  	lxdprofiler.EXPECT().LXDProfile().Return(profile)
    30  
    31  	err := lxdprofile.ValidateLXDProfile(lxdprofiler)
    32  	c.Assert(err, gc.IsNil)
    33  }
    34  
    35  func (*LXDProfileSuite) TestValidateWithInvalidConfig(c *gc.C) {
    36  	ctrl := gomock.NewController(c)
    37  	defer ctrl.Finish()
    38  
    39  	profile := &charm.LXDProfile{
    40  		Config: map[string]string{
    41  			"boot": "foobar",
    42  		},
    43  	}
    44  
    45  	lxdprofiler := NewMockLXDProfiler(ctrl)
    46  	lxdprofiler.EXPECT().LXDProfile().Return(profile)
    47  
    48  	err := lxdprofile.ValidateLXDProfile(lxdprofiler)
    49  	c.Assert(err, gc.NotNil)
    50  }
    51  
    52  func (*LXDProfileSuite) TestValidateCharmInfoWithEmptyConfig(c *gc.C) {
    53  	info := &apicharms.CharmInfo{}
    54  
    55  	err := lxdprofile.ValidateCharmInfoLXDProfile(info)
    56  	c.Assert(err, gc.IsNil)
    57  }
    58  
    59  func (*LXDProfileSuite) TestValidateCharmInfoWithInvalidConfig(c *gc.C) {
    60  	info := &apicharms.CharmInfo{
    61  		LXDProfile: &charm.LXDProfile{
    62  			Config: map[string]string{
    63  				"boot": "foobar",
    64  			},
    65  		},
    66  	}
    67  
    68  	err := lxdprofile.ValidateCharmInfoLXDProfile(info)
    69  	c.Assert(err, gc.NotNil)
    70  }