github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/jujud/agent/caasoperator/manifolds_test.go (about)

     1  // Copyright 2017 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package caasoperator_test
     5  
     6  import (
     7  	"github.com/juju/collections/set"
     8  	jc "github.com/juju/testing/checkers"
     9  	gc "gopkg.in/check.v1"
    10  
    11  	"github.com/juju/juju/agent"
    12  	"github.com/juju/juju/cmd/jujud/agent/agenttest"
    13  	"github.com/juju/juju/cmd/jujud/agent/caasoperator"
    14  	"github.com/juju/juju/testing"
    15  )
    16  
    17  type ManifoldsSuite struct {
    18  	testing.BaseSuite
    19  }
    20  
    21  var _ = gc.Suite(&ManifoldsSuite{})
    22  
    23  func (s *ManifoldsSuite) TestStartFuncs(c *gc.C) {
    24  	manifolds := caasoperator.Manifolds(caasoperator.ManifoldsConfig{
    25  		Agent: fakeAgent{},
    26  	})
    27  
    28  	for name, manifold := range manifolds {
    29  		c.Logf("checking %q manifold", name)
    30  		c.Check(manifold.Start, gc.NotNil)
    31  	}
    32  }
    33  
    34  func (s *ManifoldsSuite) TestManifoldNames(c *gc.C) {
    35  	config := caasoperator.ManifoldsConfig{}
    36  	manifolds := caasoperator.Manifolds(config)
    37  	expectedKeys := []string{
    38  		"agent",
    39  		"api-address-updater",
    40  		"api-caller",
    41  		"api-config-watcher",
    42  		"charm-dir",
    43  		"clock",
    44  		"hook-retry-strategy",
    45  		"operator",
    46  		"logging-config-updater",
    47  		"log-sender",
    48  		"migration-fortress",
    49  		"migration-minion",
    50  		"migration-inactive-flag",
    51  		"upgrade-steps-flag",
    52  		"upgrade-steps-gate",
    53  		// TODO(caas)
    54  		//"metric-spool",
    55  		//"meter-status",
    56  		//"metric-collect",
    57  		//"metric-sender",
    58  	}
    59  	keys := make([]string, 0, len(manifolds))
    60  	for k := range manifolds {
    61  		keys = append(keys, k)
    62  	}
    63  	c.Assert(expectedKeys, jc.SameContents, keys)
    64  }
    65  
    66  func (*ManifoldsSuite) TestMigrationGuards(c *gc.C) {
    67  	exempt := set.NewStrings(
    68  		"agent",
    69  		"clock",
    70  		"machine-lock",
    71  		"api-config-watcher",
    72  		"api-caller",
    73  		"log-sender",
    74  		"upgrader",
    75  		"migration-fortress",
    76  		"migration-minion",
    77  		"migration-inactive-flag",
    78  		"upgrade-steps-gate",
    79  		"upgrade-check-flag",
    80  		"upgrade-steps-runner",
    81  		"upgrade-steps-flag",
    82  		"upgrade-check-gate",
    83  	)
    84  	config := caasoperator.ManifoldsConfig{}
    85  	manifolds := caasoperator.Manifolds(config)
    86  	for name, manifold := range manifolds {
    87  		c.Logf("%v [%v]", name, manifold.Inputs)
    88  		if !exempt.Contains(name) {
    89  			checkContains(c, manifold.Inputs, "migration-inactive-flag")
    90  			checkContains(c, manifold.Inputs, "migration-fortress")
    91  		}
    92  	}
    93  }
    94  
    95  func (s *ManifoldsSuite) TestManifoldsDependencies(c *gc.C) {
    96  	agenttest.AssertManifoldsDependencies(c,
    97  		caasoperator.Manifolds(caasoperator.ManifoldsConfig{
    98  			Agent: fakeAgent{},
    99  		}),
   100  		expectedOperatorManifoldsWithDependencies,
   101  	)
   102  }
   103  
   104  func checkContains(c *gc.C, names []string, seek string) {
   105  	for _, name := range names {
   106  		if name == seek {
   107  			return
   108  		}
   109  	}
   110  	c.Errorf("%q not present in %v", seek, names)
   111  }
   112  
   113  type fakeAgent struct {
   114  	agent.Agent
   115  }
   116  
   117  var expectedOperatorManifoldsWithDependencies = map[string][]string{
   118  
   119  	"agent": {},
   120  
   121  	"api-address-updater": {
   122  		"agent",
   123  		"api-caller",
   124  		"api-config-watcher",
   125  		"migration-fortress",
   126  		"migration-inactive-flag",
   127  		"upgrade-steps-flag",
   128  		"upgrade-steps-gate"},
   129  
   130  	"api-caller": {"agent", "api-config-watcher"},
   131  
   132  	"api-config-watcher": {"agent"},
   133  
   134  	"charm-dir": {
   135  		"agent",
   136  		"api-caller",
   137  		"api-config-watcher",
   138  		"migration-fortress",
   139  		"migration-inactive-flag",
   140  		"upgrade-steps-flag",
   141  		"upgrade-steps-gate"},
   142  
   143  	"hook-retry-strategy": {
   144  		"agent",
   145  		"api-caller",
   146  		"api-config-watcher",
   147  		"migration-fortress",
   148  		"migration-inactive-flag",
   149  		"upgrade-steps-flag",
   150  		"upgrade-steps-gate"},
   151  
   152  	"log-sender": {"agent", "api-caller", "api-config-watcher"},
   153  
   154  	"logging-config-updater": {
   155  		"agent",
   156  		"api-caller",
   157  		"api-config-watcher",
   158  		"migration-fortress",
   159  		"migration-inactive-flag",
   160  		"upgrade-steps-flag",
   161  		"upgrade-steps-gate"},
   162  
   163  	"migration-fortress": {
   164  		"upgrade-steps-flag",
   165  		"upgrade-steps-gate"},
   166  
   167  	"migration-inactive-flag": {
   168  		"agent",
   169  		"api-caller",
   170  		"api-config-watcher"},
   171  
   172  	"migration-minion": {
   173  		"agent",
   174  		"api-caller",
   175  		"api-config-watcher",
   176  		"migration-fortress",
   177  		"upgrade-steps-flag",
   178  		"upgrade-steps-gate"},
   179  
   180  	"upgrade-steps-flag": {"upgrade-steps-gate"},
   181  
   182  	"upgrade-steps-gate": {},
   183  
   184  	"clock": {},
   185  
   186  	"operator": {
   187  		"agent",
   188  		"api-caller",
   189  		"api-config-watcher",
   190  		"charm-dir",
   191  		"clock",
   192  		"hook-retry-strategy",
   193  		"migration-fortress",
   194  		"migration-inactive-flag",
   195  		"upgrade-steps-flag",
   196  		"upgrade-steps-gate"},
   197  }