Skip to content

Standardise entry points for Complement tests#669

Merged
kegsay merged 5 commits into
mainfrom
kegan/standardise-entry-points
Oct 12, 2023
Merged

Standardise entry points for Complement tests#669
kegsay merged 5 commits into
mainfrom
kegan/standardise-entry-points

Conversation

@kegsay
Copy link
Copy Markdown
Member

@kegsay kegsay commented Oct 12, 2023

Every test package that wants to use Complement needs some bootstrapping boilerplate code to do things like read the env vars and clean up old containers in case of an ungraceful shutdown. There is a convenient TestMain function which is part of standard Go tests which we can use for this.

We also had a helper function called Deploy which would deploy a set of containers and return the docker.Deployment for tests to use. This helper function is actually boilerplate as well, but has still historically been defined for each test package unnecessarily.

This PR cleans up these entry points in the following way:

  • Always use the helper functions when writing entry points. Previously, only MSC packages did this. This was just an omission from Remove msc build tags. Add msc packages. #666
  • Moves entry point functions from the helpers package to the top-level complement package. Why: this signals to test writers where to look when they want to hook into Complement machinery as it serves as the entry point functions. This ends up reading very nicely as deployment := complement.Deploy(t, b.BlueprintAlice).
  • Remove the useless proxy function Deploy(...) which just called the previous line.

This now means that out-of-repo tests (which need to call somepackage.Deploy) and in-repo tests look identical, and bootstrapping boilerplate is as small as possible:

package tests

import (
	"testing"

	"github.com/matrix-org/complement"
)

func TestMain(m *testing.M) {
	complement.TestMain(m, "package-name-goes-here")
}

This reads much more nicely and clearly shows the entry point for
testing with complement.
This ensures consistency with in-repo and out-of-repo tests, which
need to refer to the complement package.
@kegsay kegsay requested review from a team as code owners October 12, 2023 11:11
Copy link
Copy Markdown
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clean commit history. Seems sane to me.

@kegsay kegsay merged commit f5a143c into main Oct 12, 2023
@kegsay kegsay deleted the kegan/standardise-entry-points branch October 12, 2023 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants