github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/state/lease/store_validation_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package lease_test
     5  
     6  import (
     7  	"time" // Only used for time types.
     8  
     9  	gc "gopkg.in/check.v1"
    10  
    11  	corelease "github.com/juju/juju/core/lease"
    12  	"github.com/juju/juju/state/lease"
    13  )
    14  
    15  // StoreValidationSuite sends bad data into all of Store's methods.
    16  type StoreValidationSuite struct {
    17  	FixtureSuite
    18  }
    19  
    20  var _ = gc.Suite(&StoreValidationSuite{})
    21  
    22  func (s *StoreValidationSuite) TestNewStoreId(c *gc.C) {
    23  	fix := s.EasyFixture(c)
    24  	fix.Config.Id = "$bad"
    25  	_, err := lease.NewStore(fix.Config)
    26  	c.Check(err, gc.ErrorMatches, "invalid id: string contains forbidden characters")
    27  }
    28  
    29  func (s *StoreValidationSuite) TestNewStoreNamespace(c *gc.C) {
    30  	fix := s.EasyFixture(c)
    31  	fix.Config.Namespace = "$bad"
    32  	_, err := lease.NewStore(fix.Config)
    33  	c.Check(err, gc.ErrorMatches, "invalid namespace: string contains forbidden characters")
    34  }
    35  
    36  func (s *StoreValidationSuite) TestNewStoreCollection(c *gc.C) {
    37  	fix := s.EasyFixture(c)
    38  	fix.Config.Collection = "$bad"
    39  	_, err := lease.NewStore(fix.Config)
    40  	c.Check(err, gc.ErrorMatches, "invalid collection: string contains forbidden characters")
    41  }
    42  
    43  func (s *StoreValidationSuite) TestNewStoreMongo(c *gc.C) {
    44  	fix := s.EasyFixture(c)
    45  	fix.Config.Mongo = nil
    46  	_, err := lease.NewStore(fix.Config)
    47  	c.Check(err, gc.ErrorMatches, "missing mongo")
    48  }
    49  
    50  func (s *StoreValidationSuite) TestNewStoreLocalClock(c *gc.C) {
    51  	fix := s.EasyFixture(c)
    52  	fix.Config.LocalClock = nil
    53  	_, err := lease.NewStore(fix.Config)
    54  	c.Check(err, gc.ErrorMatches, "missing local clock")
    55  }
    56  
    57  func (s *StoreValidationSuite) TestNewStoreGlobalClock(c *gc.C) {
    58  	fix := s.EasyFixture(c)
    59  	fix.Config.GlobalClock = nil
    60  	_, err := lease.NewStore(fix.Config)
    61  	c.Check(err, gc.ErrorMatches, "missing global clock")
    62  }
    63  
    64  func (s *StoreValidationSuite) TestClaimLeaseName(c *gc.C) {
    65  	fix := s.EasyFixture(c)
    66  	err := fix.Store.ClaimLease(key("$name"), corelease.Request{"holder", time.Minute})
    67  	c.Check(err, gc.ErrorMatches, "invalid name: string contains forbidden characters")
    68  }
    69  
    70  func (s *StoreValidationSuite) TestClaimLeaseHolder(c *gc.C) {
    71  	fix := s.EasyFixture(c)
    72  	err := fix.Store.ClaimLease(key("name"), corelease.Request{"$holder", time.Minute})
    73  	c.Check(err, gc.ErrorMatches, "invalid request: invalid holder: string contains forbidden characters")
    74  }
    75  
    76  func (s *StoreValidationSuite) TestClaimLeaseDuration(c *gc.C) {
    77  	fix := s.EasyFixture(c)
    78  	err := fix.Store.ClaimLease(key("name"), corelease.Request{"holder", 0})
    79  	c.Check(err, gc.ErrorMatches, "invalid request: invalid duration")
    80  }
    81  
    82  func (s *StoreValidationSuite) TestExtendLeaseName(c *gc.C) {
    83  	fix := s.EasyFixture(c)
    84  	err := fix.Store.ExtendLease(key("$name"), corelease.Request{"holder", time.Minute})
    85  	c.Check(err, gc.ErrorMatches, "invalid name: string contains forbidden characters")
    86  }
    87  
    88  func (s *StoreValidationSuite) TestExtendLeaseHolder(c *gc.C) {
    89  	fix := s.EasyFixture(c)
    90  	err := fix.Store.ExtendLease(key("name"), corelease.Request{"$holder", time.Minute})
    91  	c.Check(err, gc.ErrorMatches, "invalid request: invalid holder: string contains forbidden characters")
    92  }
    93  
    94  func (s *StoreValidationSuite) TestExtendLeaseDuration(c *gc.C) {
    95  	fix := s.EasyFixture(c)
    96  	err := fix.Store.ExtendLease(key("name"), corelease.Request{"holder", 0})
    97  	c.Check(err, gc.ErrorMatches, "invalid request: invalid duration")
    98  }
    99  
   100  func (s *StoreValidationSuite) TestExpireLeaseName(c *gc.C) {
   101  	fix := s.EasyFixture(c)
   102  	err := fix.Store.ExpireLease(key("$name"))
   103  	c.Check(err, gc.ErrorMatches, "invalid name: string contains forbidden characters")
   104  }