github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/worker/secretbackendrotate/manifold_test.go (about)

     1  // Copyright 2023 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package secretbackendrotate_test
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"github.com/juju/loggo"
     9  	"github.com/juju/testing"
    10  	jc "github.com/juju/testing/checkers"
    11  	gc "gopkg.in/check.v1"
    12  
    13  	"github.com/juju/juju/worker/secretbackendrotate"
    14  )
    15  
    16  type ManifoldConfigSuite struct {
    17  	testing.IsolationSuite
    18  	config secretbackendrotate.ManifoldConfig
    19  }
    20  
    21  var _ = gc.Suite(&ManifoldConfigSuite{})
    22  
    23  func (s *ManifoldConfigSuite) SetUpTest(c *gc.C) {
    24  	s.IsolationSuite.SetUpTest(c)
    25  	s.config = s.validConfig()
    26  }
    27  
    28  func (s *ManifoldConfigSuite) validConfig() secretbackendrotate.ManifoldConfig {
    29  	return secretbackendrotate.ManifoldConfig{
    30  		APICallerName: "api-caller",
    31  		Logger:        loggo.GetLogger("test"),
    32  	}
    33  }
    34  
    35  func (s *ManifoldConfigSuite) TestValid(c *gc.C) {
    36  	c.Check(s.config.Validate(), jc.ErrorIsNil)
    37  }
    38  
    39  func (s *ManifoldConfigSuite) TestMissingAPICallerName(c *gc.C) {
    40  	s.config.APICallerName = ""
    41  	s.checkNotValid(c, "missing APICallerName not valid")
    42  }
    43  
    44  func (s *ManifoldConfigSuite) TestMissingLogger(c *gc.C) {
    45  	s.config.Logger = nil
    46  	s.checkNotValid(c, "nil Logger not valid")
    47  }
    48  
    49  func (s *ManifoldConfigSuite) checkNotValid(c *gc.C, expect string) {
    50  	err := s.config.Validate()
    51  	c.Check(err, gc.ErrorMatches, expect)
    52  	c.Check(err, jc.Satisfies, errors.IsNotValid)
    53  }