Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use table tests instead of helpers.PreparerValidator #155

Closed
BrianHicks opened this issue Aug 11, 2016 · 5 comments
Closed

Use table tests instead of helpers.PreparerValidator #155

BrianHicks opened this issue Aug 11, 2016 · 5 comments
Assignees

Comments

@BrianHicks
Copy link
Contributor

BrianHicks commented Aug 11, 2016

Once #142 is merged, PreparerValidator will be in the code. It should be removed in favor of something like http://dave.cheney.net/2013/06/09/writing-table-driven-tests-in-go

@Dacode45
Copy link
Contributor

Well I also made a CheckValidator and ApplyValidator as well as a few other questionable helpers (e.g SquashChecks). I'd rather not introduce bad practices in the codebase. I could refactor them into a /helpers/testing package

@Dacode45
Copy link
Contributor

Instead of putting it in helpers, I could put it in the resource package, and make generic table test for task and prepares?

@BrianHicks
Copy link
Contributor Author

No, it probably should be table tests in each of the test files if you really need them. I noticed a lot of the places where it's being used are just single checks. Helper functions in each module may make more sense.

@sehqlr sehqlr self-assigned this Aug 24, 2016
@sehqlr
Copy link
Contributor

sehqlr commented Aug 24, 2016

Here is a sample of a table test that can replace the two test cases and that helper func. It's based on the unmerged changes, so I won't open a PR until that is merged.

func TestPreparerTableTest(t *testing.T) {
    t.Parallel()

    fr := fakerenderer.FakeRenderer{}
    prepTests := []struct {
        prep resource.Resource
        err  error
    }{
        {
            &absent.Preparer{Destination: "/path/to/absent"},
            nil,
        },
        {
            &absent.Preparer{},
            errors.New("resource requires a `destination` parameter"),
        },
    }

    for _, prepTest := range prepTests {
        _, err := prepTest.prep.Prepare(&fr)
        assert.Equal(t, err, prepTest.err)
    }
}

@BrianHicks
Copy link
Contributor Author

This issue has gone pretty stale. I'm going to close it. We'll fix tests as we go.

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

No branches or pull requests

3 participants