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

feat: HTTP integration tests #51

Merged
merged 10 commits into from
Apr 5, 2018
Merged

Conversation

paolobueno
Copy link
Contributor

Description

Add integration tests that utilize the whole HTTP setup.

JIRA: https://issues.jboss.org/browse/AEROGEAR-2251

Additional Notes

Moved most of the initialization code to internal/setup, following guidelines in https://github.com/golang-standards/project-layout#internal

Moved some of the fixtures to the new test.fixtures package for sharing. Would love to iterate on the way this is done.

@paolobueno paolobueno requested a review from aliok April 2, 2018 14:14
@coveralls
Copy link

coveralls commented Apr 2, 2018

Pull Request Test Coverage Report for Build #83

  • 71 of 80 (88.75%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 87.977%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/dao/dao.go 0 3 0.0%
pkg/test/fixtures.go 66 72 91.67%
Totals Coverage Status
Change from base Build #81: 0.1%
Covered Lines: 300
Relevant Lines: 341

💛 - Coveralls


import "github.com/aerogear/aerogear-app-metrics/pkg/mobile"

func GetEmptyDataMetric() mobile.Metric {
Copy link

Choose a reason for hiding this comment

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

Any reason not to return a pointer to mobile.Metric here (and in the following functions)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Considering it's only used for tests I'd argue perf/memory usage is not a big issue here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also wanted to make explicit that these would return a new instance instead of a pointer to something existing, due to the possibility of tests eventually modifying them


res, err := http.Post(s.URL+"/metrics", "application/json", buffer)
assert.NoError(t, err, "did not expect an error posting to /metrics")
defer res.Body.Close()
Copy link

Choose a reason for hiding this comment

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

Body is not read here, do you really need to close it?

}
assert.Nil(t, err, "did not expect an error posting metrics")
_, err = ioutil.ReadAll(res.Body)
Copy link

Choose a reason for hiding this comment

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

should you add a defer res.Body.Close() here?

Copy link

Choose a reason for hiding this comment

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

Ok, i see you're closing it after using the function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it should be okay to defer close from this function as long as the rest of the tests don't want to use the contents of the body, I'll do this 👍

config := config.GetConfig()
metricsDao := setup.InitDao(config)
Copy link
Contributor

Choose a reason for hiding this comment

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

Some minor points:

  1. This has created an unnecessary dependency between the setup package and the config package.
  2. Non db related options are being passed into a function called InitDao

I think the config struct should stay internal and the config package should only be depended upon at a top level. I would change this to setup.InitDao(config.DBConnectionString, config.DBMaxConnections) to avoid such a dependency. Would you agree?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@paolobueno paolobueno force-pushed the AEROGEAR-2251-integration-tests branch from e27465b to 9833c6c Compare April 5, 2018 12:22
@paolobueno paolobueno merged commit 5da54dc into master Apr 5, 2018
@paolobueno paolobueno deleted the AEROGEAR-2251-integration-tests branch April 5, 2018 13:07
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.

None yet

5 participants