github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/cmd/jujud/agent/unit/manifolds_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package unit_test
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	"github.com/juju/utils/set"
     9  	gc "gopkg.in/check.v1"
    10  
    11  	"github.com/juju/juju/agent"
    12  	"github.com/juju/juju/cmd/jujud/agent/unit"
    13  	"github.com/juju/juju/testing"
    14  )
    15  
    16  type ManifoldsSuite struct {
    17  	testing.BaseSuite
    18  }
    19  
    20  var _ = gc.Suite(&ManifoldsSuite{})
    21  
    22  func (s *ManifoldsSuite) TestStartFuncs(c *gc.C) {
    23  	manifolds := unit.Manifolds(unit.ManifoldsConfig{
    24  		Agent: fakeAgent{},
    25  	})
    26  
    27  	for name, manifold := range manifolds {
    28  		c.Logf("checking %q manifold", name)
    29  		c.Check(manifold.Start, gc.NotNil)
    30  	}
    31  }
    32  
    33  func (s *ManifoldsSuite) TestManifoldNames(c *gc.C) {
    34  	config := unit.ManifoldsConfig{}
    35  	manifolds := unit.Manifolds(config)
    36  	expectedKeys := []string{
    37  		"agent",
    38  		"api-config-watcher",
    39  		"api-caller",
    40  		"log-sender",
    41  		"upgrader",
    42  		"migration-fortress",
    43  		"migration-minion",
    44  		"migration-inactive-flag",
    45  		"logging-config-updater",
    46  		"proxy-config-updater",
    47  		"api-address-updater",
    48  		"charm-dir",
    49  		"leadership-tracker",
    50  		"hook-retry-strategy",
    51  		"uniter",
    52  		"metric-spool",
    53  		"meter-status",
    54  		"metric-collect",
    55  		"metric-sender",
    56  	}
    57  	keys := make([]string, 0, len(manifolds))
    58  	for k := range manifolds {
    59  		keys = append(keys, k)
    60  	}
    61  	c.Assert(expectedKeys, jc.SameContents, keys)
    62  }
    63  
    64  func (*ManifoldsSuite) TestMigrationGuards(c *gc.C) {
    65  	exempt := set.NewStrings(
    66  		"agent",
    67  		"machine-lock",
    68  		"api-config-watcher",
    69  		"api-caller",
    70  		"log-sender",
    71  		"upgrader",
    72  		"migration-fortress",
    73  		"migration-minion",
    74  		"migration-inactive-flag",
    75  	)
    76  	config := unit.ManifoldsConfig{}
    77  	manifolds := unit.Manifolds(config)
    78  	for name, manifold := range manifolds {
    79  		c.Logf(name)
    80  		if !exempt.Contains(name) {
    81  			checkContains(c, manifold.Inputs, "migration-inactive-flag")
    82  			checkContains(c, manifold.Inputs, "migration-fortress")
    83  		}
    84  	}
    85  }
    86  
    87  func checkContains(c *gc.C, names []string, seek string) {
    88  	for _, name := range names {
    89  		if name == seek {
    90  			return
    91  		}
    92  	}
    93  	c.Errorf("%q not present in %v", seek, names)
    94  }
    95  
    96  type fakeAgent struct {
    97  	agent.Agent
    98  }