Skip to content

Commit

Permalink
simplify extension registration in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flotter committed Aug 28, 2024
1 parent d2b2ecb commit a1d6300
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 9 additions & 3 deletions internals/overlord/planstate/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ var extLoadLayers = []string{`
`}

func (ps *planSuite) TestExtLoadLayers(c *C) {
plan.RegisterExtension(testField, testExtension{})
defer plan.UnregisterExtension(testField)

var err error
ps.planMgr, err = planstate.NewManager(ps.layersDir)
c.Assert(err, IsNil)
plan.RegisterExtension(testField, testExtension{})
// Write layers
for _, l := range extLoadLayers {
ps.writeLayer(c, string(reindent(l)))
Expand Down Expand Up @@ -224,10 +226,12 @@ services:
}

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)
plan.RegisterExtension(testField, testExtension{})

// Append a layer when there are no layers.
layer := ps.parseLayer(c, 0, "label1", `
Expand Down Expand Up @@ -462,10 +466,12 @@ checks:
}

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)
plan.RegisterExtension(testField, testExtension{})

// "Combine" layer with no layers should just append.
layer := ps.parseLayer(c, 0, "label1", `
Expand Down
8 changes: 3 additions & 5 deletions internals/overlord/planstate/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ type planSuite struct {
var _ = Suite(&planSuite{})

func (ps *planSuite) SetUpTest(c *C) {
plan.UnregisterExtension(testField)

ps.layersDir = filepath.Join(c.MkDir(), "layers")
err := os.Mkdir(ps.layersDir, 0755)
c.Assert(err, IsNil)
Expand Down Expand Up @@ -110,7 +108,7 @@ const testField string = "test-field"
// testExtension implements the LayerSectionExtension interface.
type testExtension struct{}

func (te testExtension) ParseSection(data yaml.Node) (plan.LayerSection, error) {
func (te testExtension) ParseSection(data yaml.Node) (plan.Section, error) {
ts := &testSection{}
err := data.Decode(ts)
if err != nil {
Expand All @@ -125,7 +123,7 @@ func (te testExtension) ParseSection(data yaml.Node) (plan.LayerSection, error)
return ts, nil
}

func (te testExtension) CombineSections(sections ...plan.LayerSection) (plan.LayerSection, error) {
func (te testExtension) CombineSections(sections ...plan.Section) (plan.Section, error) {
ts := &testSection{}
for _, section := range sections {
err := ts.Combine(section)
Expand Down Expand Up @@ -161,7 +159,7 @@ func (ts *testSection) IsZero() bool {
return ts.Entries == nil
}

func (ts *testSection) Combine(other plan.LayerSection) error {
func (ts *testSection) Combine(other plan.Section) error {
otherTSection, ok := other.(*testSection)
if !ok {
return fmt.Errorf("invalid section type")
Expand Down

0 comments on commit a1d6300

Please sign in to comment.