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

[Testing Framework] Add test structure to views package for rendering test output #33324

Merged
merged 2 commits into from
Jun 13, 2023

Conversation

liamcervante
Copy link
Member

@liamcervante liamcervante commented Jun 7, 2023

This PR introduces a views/test.go file which adds a human-readable view for test outputs. A JSON view will be added in a later PR.

In addition, representations of test suites, test files, and test runs are added. These will be provided by the testing framework into the view to render.

Target Release

1.6.0

Terraform Testing Framework

This PR is part of a chain of PRs implementing the new Terraform test command.

Description Branch PR
Cleanup previous implementation liamcervante/tests/cleanup #33323
Add initial human view implementation liamcervante/tests/view #33324
Add Terraform test file config support liamcervante/tests/config #33325
Update terraform context functionality liamcervante/tests/context #33326
Add test command to Terraform CLI liamcervante/tests/command #33327

The above PRs implement the core functionality of the new test command. More PRs will follow implementing specific features, but the test command will work end-to-end once the above PRs are merged.

These changes are implemented in a chain, with each change building on the previous one to ensure ease of review. To see the combined changes as one, navigate to the last PR in the chain and change it to merge directly into main.

Copy link
Contributor

@alisdair alisdair left a comment

Choose a reason for hiding this comment

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

This seems good to me! Some very minor thoughts inline.

}
}

if suite.Status <= moduletest.Skip {
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels a little odd to use inequalities against state constants. I normally don't think of iota-derived constants as having an order. Did you consider using suite.Status == moduletest.Pending || suite.Status == moduletest.Skip and reject it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can definitely update it to that here, but there's another function that also relies on the ordering. I added a comment there to highlight it.

Do you think it's worth me dropping any ordering assumptions to the status and updating the other function as well? I do think the iota implementation does enforce this, but I don't feel strongly about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, I hadn't spotted that and I think it's fine to rely on the ordering here. I'd maybe suggest adding commentary next to the type definition to clarify that order is significant and point to Merge as an example of that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!


// ColorizedText returns textual representations of the status, but colored for
// visual appeal.
func (status Status) ColorizedText(color *colorstring.Colorize) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like view logic which I'd expect to be in the corresponding view package. Would it cause problems to move it over? If you're concerned about forgetting to add future status values we could add the views package to the scripts/exhaustive.sh list.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

//
// The implementation basically always returns the highest of the two, which
// means the order the statuses are defined within the iota matters.
func (status Status) Merge(next Status) Status {
Copy link
Member Author

Choose a reason for hiding this comment

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

@alisdair, this function does make an assumption on the ordering, basically to simplify the logic of combining multiple status. For example a test that has one error case, one fail case and two pass cases would report overall as error. So the ordering is deliberate in order to make this function simple.

}
}

if suite.Status <= moduletest.Skip {
Copy link
Member Author

Choose a reason for hiding this comment

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

I can definitely update it to that here, but there's another function that also relies on the ordering. I added a comment there to highlight it.

Do you think it's worth me dropping any ordering assumptions to the status and updating the other function as well? I do think the iota implementation does enforce this, but I don't feel strongly about it.

@liamcervante liamcervante merged commit ce8fd29 into main Jun 13, 2023
@liamcervante liamcervante deleted the liamcervante/tests/view branch June 13, 2023 08:09
@github-actions
Copy link
Contributor

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

@github-actions
Copy link
Contributor

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants