Skip to content

Refactor tests to be runnable on specific backends #78

Open
@shazow

Description

It'd be really useful to run the test suite on specific backends, rather than requiring the suite to run on all-or-nothing, especially since many of the backends require specific system-level package requirements.

Problem

Right now, the test suite hardcodes all the backends in each test scenario. It looks like this:

    tests := map[string]struct {
        repo interface {
            ResolveBranch(string) (vcs.CommitID, error)
        }, ...
    }{
        "git libgit2": {
            repo:         makeGitRepositoryLibGit2(t, gitCommands...), ...
        },
        "git cmd": {
            repo:         makeGitRepositoryCmd(t, gitCommands...), ...
        },
        "hg native": {
            repo:         makeHgRepositoryNative(t, hgCommands...), ...
        },
        "hg cmd": {
            repo:         makeHgRepositoryCmd(t, hgCommands...), ...
        },
    }

These test sets are hardcoded in every test suite scenario. It's impossible to tell the test suite to only run it on the libgit2 implementation, for example.

Proposal

I propose refactoring the tests so that each suite scenario is only aware of a single vcs interface implementation, and it's called N times for each implementation we want to test. Additionally, we could add the ability to select which backend should be tested using go -tags.

For example, go test -tags gitcmd should only run the test suite on the gitcmd backend.

Steps

  • Abstract the setup functions (make*Repository*) behind a common interface that can be provided.
  • Replace the test backend matrix with either a registry (probably simpler) or a parameterized test runner. (Thoughts?)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions