diff --git a/internals/overlord/planstate/manager_test.go b/internals/overlord/planstate/manager_test.go index ef28f43d..3da0debf 100644 --- a/internals/overlord/planstate/manager_test.go +++ b/internals/overlord/planstate/manager_test.go @@ -45,52 +45,6 @@ var loadLayers = []string{` summary: Svc1 override: replace command: echo svc1 -`, ` - summary: Layer 2 - description: Layer 2 desc. - services: - svc2: - summary: Svc2 - override: replace - command: echo svc2 -`} - -func (ps *planSuite) TestLoadLayers(c *C) { - var err error - ps.planMgr, err = planstate.NewManager(ps.layersDir) - c.Assert(err, IsNil) - // Write layers - for _, l := range loadLayers { - ps.writeLayer(c, string(reindent(l))) - } - // Load the plan from the /layers directory - err = ps.planMgr.Load() - c.Assert(err, IsNil) - plan := ps.planMgr.Plan() - out, err := yaml.Marshal(plan) - c.Assert(err, IsNil) - c.Assert(len(plan.Layers), Equals, 2) - c.Assert(string(out), Equals, ` -services: - svc1: - summary: Svc1 - override: replace - command: echo svc1 - svc2: - summary: Svc2 - override: replace - command: echo svc2 -`[1:]) -} - -var extLoadLayers = []string{` - summary: Layer 1 - description: Layer 1 desc. - services: - svc1: - summary: Svc1 - override: replace - command: echo svc1 test-field: test1: override: merge @@ -109,15 +63,14 @@ var extLoadLayers = []string{` b: something else `} -func (ps *planSuite) TestExtLoadLayers(c *C) { +func (ps *planSuite) TestLoadLayers(c *C) { plan.RegisterExtension(testField, testExtension{}) defer plan.UnregisterExtension(testField) - var err error ps.planMgr, err = planstate.NewManager(ps.layersDir) c.Assert(err, IsNil) // Write layers - for _, l := range extLoadLayers { + for _, l := range loadLayers { ps.writeLayer(c, string(reindent(l))) } // Load the plan from the /layers directory @@ -146,89 +99,8 @@ test-field: } func (ps *planSuite) TestAppendLayers(c *C) { - var err error - ps.planMgr, err = planstate.NewManager(ps.layersDir) - c.Assert(err, IsNil) - - // Append a layer when there are no layers. - layer := ps.parseLayer(c, 0, "label1", ` -services: - svc1: - override: replace - command: /bin/sh -`) - err = ps.planMgr.AppendLayer(layer) - c.Assert(err, IsNil) - c.Assert(layer.Order, Equals, 1) - c.Assert(ps.planYAML(c), Equals, ` -services: - svc1: - override: replace - command: /bin/sh -`[1:]) - ps.planLayersHasLen(c, 1) - - // Try to append a layer when that label already exists. - layer = ps.parseLayer(c, 0, "label1", ` -services: - svc1: - override: foobar - command: /bin/bar -`) - err = ps.planMgr.AppendLayer(layer) - c.Assert(err.(*planstate.LabelExists).Label, Equals, "label1") - c.Assert(ps.planYAML(c), Equals, ` -services: - svc1: - override: replace - command: /bin/sh -`[1:]) - ps.planLayersHasLen(c, 1) - - // Append another layer on top. - layer = ps.parseLayer(c, 0, "label2", ` -services: - svc1: - override: replace - command: /bin/bash -`) - err = ps.planMgr.AppendLayer(layer) - c.Assert(err, IsNil) - c.Assert(layer.Order, Equals, 2) - c.Assert(ps.planYAML(c), Equals, ` -services: - svc1: - override: replace - command: /bin/bash -`[1:]) - ps.planLayersHasLen(c, 2) - - // Append a layer with a different service. - layer = ps.parseLayer(c, 0, "label3", ` -services: - svc2: - override: replace - command: /bin/foo -`) - err = ps.planMgr.AppendLayer(layer) - c.Assert(err, IsNil) - c.Assert(layer.Order, Equals, 3) - c.Assert(ps.planYAML(c), Equals, ` -services: - svc1: - override: replace - command: /bin/bash - svc2: - override: replace - command: /bin/foo -`[1:]) - ps.planLayersHasLen(c, 3) -} - -func (ps *planSuite) TestExtAppendLayers(c *C) { plan.RegisterExtension(testField, testExtension{}) defer plan.UnregisterExtension(testField) - var err error ps.planMgr, err = planstate.NewManager(ps.layersDir) c.Assert(err, IsNil) @@ -344,131 +216,8 @@ test-field: } func (ps *planSuite) TestCombineLayers(c *C) { - var err error - ps.planMgr, err = planstate.NewManager(ps.layersDir) - c.Assert(err, IsNil) - - // "Combine" layer with no layers should just append. - layer := ps.parseLayer(c, 0, "label1", ` -services: - svc1: - override: replace - command: /bin/sh -`) - err = ps.planMgr.CombineLayer(layer) - c.Assert(err, IsNil) - c.Assert(layer.Order, Equals, 1) - c.Assert(ps.planYAML(c), Equals, ` -services: - svc1: - override: replace - command: /bin/sh -`[1:]) - ps.planLayersHasLen(c, 1) - - // Combine layer with different label should just append. - layer = ps.parseLayer(c, 0, "label2", ` -services: - svc2: - override: replace - command: /bin/foo -`) - err = ps.planMgr.CombineLayer(layer) - c.Assert(err, IsNil) - c.Assert(layer.Order, Equals, 2) - c.Assert(ps.planYAML(c), Equals, ` -services: - svc1: - override: replace - command: /bin/sh - svc2: - override: replace - command: /bin/foo -`[1:]) - ps.planLayersHasLen(c, 2) - - // Combine layer with first layer. - layer = ps.parseLayer(c, 0, "label1", ` -services: - svc1: - override: replace - command: /bin/bash -`) - err = ps.planMgr.CombineLayer(layer) - c.Assert(err, IsNil) - c.Assert(layer.Order, Equals, 1) - c.Assert(ps.planYAML(c), Equals, ` -services: - svc1: - override: replace - command: /bin/bash - svc2: - override: replace - command: /bin/foo -`[1:]) - ps.planLayersHasLen(c, 2) - - // Combine layer with second layer. - layer = ps.parseLayer(c, 0, "label2", ` -services: - svc2: - override: replace - command: /bin/bar -`) - err = ps.planMgr.CombineLayer(layer) - c.Assert(err, IsNil) - c.Assert(layer.Order, Equals, 2) - c.Assert(ps.planYAML(c), Equals, ` -services: - svc1: - override: replace - command: /bin/bash - svc2: - override: replace - command: /bin/bar -`[1:]) - ps.planLayersHasLen(c, 2) - - // One last append for good measure. - layer = ps.parseLayer(c, 0, "label3", ` -services: - svc1: - override: replace - command: /bin/a - svc2: - override: replace - command: /bin/b -`) - err = ps.planMgr.CombineLayer(layer) - c.Assert(err, IsNil) - c.Assert(layer.Order, Equals, 3) - c.Assert(ps.planYAML(c), Equals, ` -services: - svc1: - override: replace - command: /bin/a - svc2: - override: replace - command: /bin/b -`[1:]) - ps.planLayersHasLen(c, 3) - - // Make sure that layer validation is happening. - layer, err = plan.ParseLayer(0, "label4", []byte(` -checks: - bad-check: - override: replace - level: invalid - tcp: - port: 8080 -`)) - c.Check(err, ErrorMatches, `(?s).*plan check.*must be "alive" or "ready".*`) -} - -func (ps *planSuite) TestExtCombineLayers(c *C) { plan.RegisterExtension(testField, testExtension{}) defer plan.UnregisterExtension(testField) - var err error ps.planMgr, err = planstate.NewManager(ps.layersDir) c.Assert(err, IsNil)