github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/tools/lxdclient/config_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  // +build go1.3
     5  
     6  package lxdclient_test
     7  
     8  import (
     9  	"github.com/juju/errors"
    10  	jc "github.com/juju/testing/checkers"
    11  	gc "gopkg.in/check.v1"
    12  
    13  	"github.com/juju/juju/tools/lxdclient"
    14  )
    15  
    16  var (
    17  	_ = gc.Suite(&configSuite{})
    18  )
    19  
    20  type configBaseSuite struct {
    21  	lxdclient.BaseSuite
    22  
    23  	remote lxdclient.Remote
    24  }
    25  
    26  func (s *configBaseSuite) SetUpTest(c *gc.C) {
    27  	s.BaseSuite.SetUpTest(c)
    28  
    29  	s.remote = lxdclient.Remote{
    30  		Name:     "my-remote",
    31  		Host:     "some-host",
    32  		Protocol: lxdclient.LXDProtocol,
    33  		Cert:     s.Cert,
    34  	}
    35  }
    36  
    37  type configSuite struct {
    38  	configBaseSuite
    39  }
    40  
    41  func (s *configSuite) TestWithDefaultsOkay(c *gc.C) {
    42  	cfg := lxdclient.Config{
    43  		Remote: s.remote,
    44  	}
    45  	updated, err := cfg.WithDefaults()
    46  	c.Assert(err, jc.ErrorIsNil)
    47  
    48  	c.Check(updated, jc.DeepEquals, cfg)
    49  }
    50  
    51  func (s *configSuite) TestWithDefaultsMissingRemote(c *gc.C) {
    52  	cfg := lxdclient.Config{}
    53  	updated, err := cfg.WithDefaults()
    54  	c.Assert(err, jc.ErrorIsNil)
    55  
    56  	c.Check(updated, jc.DeepEquals, lxdclient.Config{
    57  		Remote: lxdclient.Local,
    58  	})
    59  }
    60  
    61  func (s *configSuite) TestWithDefaultsMissingStream(c *gc.C) {
    62  	cfg := lxdclient.Config{
    63  		Remote: s.remote,
    64  	}
    65  	updated, err := cfg.WithDefaults()
    66  	c.Assert(err, jc.ErrorIsNil)
    67  
    68  	c.Check(updated, jc.DeepEquals, lxdclient.Config{
    69  		Remote: s.remote,
    70  	})
    71  }
    72  
    73  func (s *configSuite) TestValidateOkay(c *gc.C) {
    74  	cfg := lxdclient.Config{
    75  		Remote: s.remote,
    76  	}
    77  	err := cfg.Validate()
    78  
    79  	c.Check(err, jc.ErrorIsNil)
    80  }
    81  
    82  func (s *configSuite) TestValidateOnlyRemote(c *gc.C) {
    83  	cfg := lxdclient.Config{
    84  		Remote: s.remote,
    85  	}
    86  	err := cfg.Validate()
    87  
    88  	c.Check(err, jc.ErrorIsNil)
    89  }
    90  
    91  func (s *configSuite) TestValidateMissingRemote(c *gc.C) {
    92  	cfg := lxdclient.Config{}
    93  	err := cfg.Validate()
    94  
    95  	c.Check(err, jc.Satisfies, errors.IsNotValid)
    96  }
    97  
    98  func (s *configSuite) TestValidateZeroValue(c *gc.C) {
    99  	var cfg lxdclient.Config
   100  	err := cfg.Validate()
   101  
   102  	c.Check(err, jc.Satisfies, errors.IsNotValid)
   103  }