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

vtest: Automated testing for vektor servers #54

Merged
merged 8 commits into from Aug 16, 2021
Merged

Conversation

danielledeleo
Copy link
Contributor

Closes #53

Instead of using a separate `TestStart` function, setting TestMode to true prevents the server from fully starting and listening on a socket.
vtest allows users to run automated tests against their routes without spinning up a full server.
@danielledeleo danielledeleo added the enhancement New feature or request label Aug 4, 2021
Assertions are now chainable on a single request. e.g.:

`vt.Run(req, t).AssertStatus(200).AssertHeader("Content-Type", "application/json")`
Rename VKTest to VTest
Rename helpers.go to vtest.go
Rename several internal functions and constants to be unexported

[*]: I don't think there is an elegant way to create a proper go doc Example section showing how to *define* a testing function, so I just put it in the overview. Single-file Examples can't contain functions with a func(t *testing.T) signature, for whatever reason. (see https://pkg.go.dev/testing#hdr-Examples)
@danielledeleo danielledeleo marked this pull request as ready for review August 5, 2021 23:08
This way, when you call multiple Assert* methods on a single response, it prints test output data for each assertion.

Example:
=== RUN   TestNotFound
=== RUN   TestNotFound/body
=== RUN   TestNotFound/status
--- PASS: TestNotFound (0.00s)
    --- PASS: TestNotFound/body (0.00s)
    --- PASS: TestNotFound/status (0.00s)
vtest/simple_test.go Outdated Show resolved Hide resolved
vtest/vtest.go Outdated Show resolved Hide resolved
vtest/response.go Show resolved Hide resolved
vtest/simple_test.go Outdated Show resolved Hide resolved
- Add check to prevent server from starting twice
- Replace t.Error() + t.FailNow() calls with t.Fatal()
@@ -48,6 +49,12 @@ func New(opts ...OptionsModifier) *Server {

// Start starts the server listening
func (s *Server) Start() error {
if s.started.Load().(bool) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Were we not checking this anywhere before? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤷

@danielledeleo danielledeleo merged commit ecf4619 into main Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automated route testing
2 participants