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

Integration test framework #1290

Merged
merged 4 commits into from
Apr 25, 2017
Merged

Conversation

ethantkoenig
Copy link
Member

@ethantkoenig ethantkoenig commented Mar 16, 2017

NOTE: Drone is currently failing due to .drone.yml.sig, which needs to be updated.

A new framework for integration tests. The main issues with our current integration tests are that it

  • Uses the production database
  • Re-installs the server for every test
  • Must manually add content (e.g. users, repos) to the system for every test

My proposal is to have a test "environment" (database and filesystem containing repos). The integration test environment would be populated with "fixtures", somewhat similar to what we do for unit tests (plus actual repos in the filesystem). Right now, this is implemented by having a separate app.ini for integration tests, as well as a collection of database fixtures and directory of repositories.

Also implements @andreynering's suggestion from #1135 (comment) of using the ServeHTTP(..) method

This system would allow us to not only add integration tests, but also unit tests for components that interact with the filesystem (e.g. anything that runs git commands).

STORING THE INTEGRATION ENVIRONMENT:
In order to not have to store a bunch of test fixtures and repos inside the main gitea repository, I have created a separate repo (https://github.com/ethantkoenig/gitea-integration) that stores the integration test fixtures and repositories. This repo must be cloned to run integration tests. If we end up choosing this approach, it might make sense to transfer this repo to the go-gitea organization.

WHAT TO DO WITH EXISTING INTEGRATION TESTS:
For now, I have removed the existing integration tests to clear up the integrations/ directory. I have ported all previous integration tests to the new framework.

HOW TO RUN INTEGRATION TESTS:

  1. make test-(sqlite|mysql|pgsql). You may need to update the corresponding integrations/*.ini to match whatever you have running locally.

cmd/web.go Outdated
@@ -71,7 +71,7 @@ and it takes care of all the other things for you`,
}

// newMacaron initializes Macaron instance.
func newMacaron() *macaron.Macaron {
func NewMacaron() *macaron.Macaron {
Copy link
Member

@bkcsoft bkcsoft Mar 16, 2017

Choose a reason for hiding this comment

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

Can we move this (and RegisterRoutes to a new modules/router instead? Since they really shouldn't be here anyway 🙂 )

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

models/models.go Outdated
@@ -24,6 +24,9 @@ import (
// Needed for the MSSSQL driver
_ "github.com/denisenkom/go-mssqldb"

// Needed for SQLite
_ "github.com/mattn/go-sqlite3"
Copy link
Member

@bkcsoft bkcsoft Mar 16, 2017

Choose a reason for hiding this comment

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

nononononono, there's a reason that this isn't here...

Copy link
Member Author

@ethantkoenig ethantkoenig Mar 16, 2017

Choose a reason for hiding this comment

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

I know, I added it as a temporary hack so the tests would work; I realize that sqlite has to be explicitly enabled. Perhaps I should have made that clearer.

Copy link
Member Author

@ethantkoenig ethantkoenig Mar 17, 2017

Choose a reason for hiding this comment

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

I figured out the non-hacky way to make things work, so this has been removed.

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
"/home/ethantkoenig/.gopath/src/code.gitea.io/gitea/gitea" hook --config='integrations/app.ini' post-receive
Copy link
Member

Choose a reason for hiding this comment

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

This will break for everyone... Don't put the test-repos in here, have the test pull it from somewhere (or untar/unzip)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I didn't realize there were hard-coded absolute paths in here. If we pull from somewhere else, we'll still have to edit all of these scripts to have the correct path (which is doable, but annoying).

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've updated the scripts to use $GITEA_ROOT instead of a hard-coded path. We'll have to export the appropriate value for GITEA_ROOT before running integration tests involving these scripts.

@bkcsoft
Copy link
Member

bkcsoft commented Mar 16, 2017

Also don't call it myintegrations, just go for intergrations or tests/integration :)

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 16, 2017
@ethantkoenig
Copy link
Member Author

Rebased, renamed myintegrations to integrations and remove the previous contents of integrations.

@lunny lunny added the pr/wip This PR is not ready for review label Mar 17, 2017
@lunny
Copy link
Member

lunny commented Mar 17, 2017

It seems #741 had imported the integration tests and #1135 added signup tests.

@strk
Copy link
Member

strk commented Mar 17, 2017 via email

@ethantkoenig
Copy link
Member Author

@lunny I am aware, but there are some problems with these integration tests (see PR description). It was my understanding that #741 and #1135 were not a permanent solution (#1135 (comment)).

@ethantkoenig ethantkoenig force-pushed the test/integration branch 2 times, most recently from e5f0858 to 6ca850a Compare March 20, 2017 01:09
@ethantkoenig
Copy link
Member Author

ethantkoenig commented Mar 20, 2017

Rebased to resolve conflicts.

@strk I've updated it to use testfixtures, so to use another RDBMS all you have to do is modify integrations/app.ini

@ethantkoenig ethantkoenig changed the title [WIP] Integration test framework Integration test framework Mar 20, 2017
@lunny lunny added this to the 1.2.0 milestone Mar 20, 2017
@strk
Copy link
Member

strk commented Mar 20, 2017

@ethantkoenig would it be possible to script the app.ini update so to have make check (or go test if possible) run the test against all supported (at build-time) database backends ?

@ethantkoenig ethantkoenig force-pushed the test/integration branch 2 times, most recently from a267737 to 1eeae42 Compare March 23, 2017 21:05
@ethantkoenig
Copy link
Member Author

ethantkoenig commented Mar 23, 2017

@strk I've created separate .ini files for SQLite, MySQL, and PostgreSQL. The integration tests can be run using make test-(sqlite|mysql|pgsql). All three pass locally, but I've been having some trouble getting MySQL and PostgreSQL to pass in CI.

@ethantkoenig ethantkoenig force-pushed the test/integration branch 2 times, most recently from 5d08ed1 to 96669d4 Compare March 23, 2017 21:15
.gitignore Outdated
@@ -44,3 +44,5 @@ coverage.out
/indexers
/log
/public/img/avatar

Copy link
Member

Choose a reason for hiding this comment

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

empty line ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed.

.drone.yml Outdated
@@ -42,7 +53,7 @@ pipeline:
TAGS: bindata
GOPATH: /srv/app
commands:
- make test-pgsql
- echo 'Not ready yet'
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you could leave the intended command in here, for reference, like echo make 'test-pgsql #not ready yet' (and same for all non-ready blocks)

.drone.yml Outdated
TAGS: bindata
GOPATH: /srv/app
commands:
- echo 'Not ready yet'
Copy link
Member

Choose a reason for hiding this comment

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

I thought you mentioned this was actually passing on drone ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Member

@strk strk left a comment

Choose a reason for hiding this comment

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

Please don't add that tar.gz to the repository (what is it for?).

Also, I don't understand the changes to cmd/web.go

@ethantkoenig
Copy link
Member Author

ethantkoenig commented Mar 23, 2017

The .tar.gz was accidentally added; I've removed it, and added it to .gitignore.

The changes to cmd/web.go are following @bkcsoft's suggestion above

@andreynering
Copy link
Contributor

Drone error seems unrelated to the change:

WARNING: unable to verify the Yaml signature.

@andreynering
Copy link
Contributor

LGTM 🎉

I'd just disable Xorm log output on console.

@tboerger tboerger removed the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 23, 2017
@strk
Copy link
Member

strk commented Apr 20, 2017

@bkcsoft why modules/router/router.go rather than routers/something ?

go test -c code.gitea.io/gitea/integrations -tags 'sqlite'

integrations/gitea-integration:
curl -L https://github.com/ethantkoenig/gitea-integration/archive/v2.tar.gz > integrations/gitea-integration.tar.gz
Copy link
Member

Choose a reason for hiding this comment

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

What's the archive?

Copy link
Member Author

Choose a reason for hiding this comment

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

It contains the git repositories for the integration tests. It is necessary, because some integration may need to run git commands, or access files in the repositories.

See also the "STORING THE INTEGRATION ENVIRONMENT" section of the PR description.

"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/routers"

"bytes"
Copy link
Member

Choose a reason for hiding this comment

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

wrong import place

"code.gitea.io/gitea/integrations/internal/utils"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
Copy link
Member

Choose a reason for hiding this comment

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

blank line.

"testing"

"code.gitea.io/gitea/models"
"github.com/stretchr/testify/assert"
Copy link
Member

Choose a reason for hiding this comment

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

blank line

@bkcsoft
Copy link
Member

bkcsoft commented Apr 21, 2017

@strk @ethantkoenig I didn't really have a reason for modules/routes/ over routers/, feel free to move it. But it didn't belong as an exported function in cmd/web.go (nothing should import /cmd except for main.go 😉 )

@ethantkoenig
Copy link
Member Author

@lunny I've addressed your review, and moved modules/router/router.go to routers

@lunny lunny removed the pr/wip This PR is not ready for review label Apr 24, 2017
@lunny
Copy link
Member

lunny commented Apr 24, 2017

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 24, 2017
test-mysql:
image: webhippie/golang:edge
pull: true
environment:
TAGS: bindata
GOPATH: /srv/app
commands:
- make test-mysql
- echo make test-mysql # Not ready yet
Copy link
Member

Choose a reason for hiding this comment

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

revert this changes? @ethantkoenig

Copy link
Member Author

Choose a reason for hiding this comment

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

test-mysql and test-pgsql still aren't ready to run in CI (although they do pass locally). Unfortunately, I've had a hard time debugging why they aren't passing in CI, and given how long it took to get a .drone.yml.sig for this PR, I think makes more sense to address them in a future PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

See also #1290 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

OK

@@ -42,7 +53,7 @@ pipeline:
TAGS: bindata
GOPATH: /srv/app
commands:
- make test-pgsql
- echo make test-pqsql # Not ready yet
Copy link
Member

Choose a reason for hiding this comment

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

revert this changes? @ethantkoenig

@ethantkoenig
Copy link
Member Author

@strk I believe I have addressed all of your requested changes.

@strk
Copy link
Member

strk commented Apr 24, 2017

Thanks, all checks pass now, just needs to be merged. Looking forward to enable the CI testing of mysql and postgresql !

@lunny
Copy link
Member

lunny commented Apr 24, 2017

conflicted. @ethantkoenig

@ethantkoenig
Copy link
Member Author

@lunny Rebased to resolve conflicts. Unfortunately, I will need a new .drone.yml.sig now that #1468 has been merged into master.

@lunny
Copy link
Member

lunny commented Apr 25, 2017

@ethantkoenig I have resigned it.

@lunny lunny merged commit c58708d into go-gitea:master Apr 25, 2017
@ethantkoenig ethantkoenig deleted the test/integration branch April 29, 2017 14:13
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants