You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
6.3 KiB

9 years ago
9 years ago
Add basic integration test infrastructure (and new endpoint `/api/v1/version` for testing it) (#741) * Implement '/api/v1/version' * Cleanup and various fixes * Enhance run.sh * Add install_test.go * Add parameter utils.Config for testing handlers * Re-organize TestVersion.go * Rename functions * handling process cleanup properly * Fix missing function renaming * Cleanup the 'retry' logic * Cleanup * Remove unneeded logging code * Logging messages tweaking * Logging message tweaking * Fix logging messages * Use 'const' instead of hardwired numbers * We don't really need retries anymore * Move constant ServerHttpPort to install_test.go * Restore mistakenly removed constant * Add required comments to make the linter happy. * Fix comments and naming to address linter's complaints * Detect Gitea executale version automatically * Remove tests/run.sh, `go test` suffices. * Make `make build` a prerequisite of `make test` * Do not sleep before trying * Speedup the server pinging loop * Use defined const instead of hardwired numbers * Remove redundant error handling * Use a dedicated target for running code.gitea.io/tests * Do not make 'test' depend on 'build' target * Rectify the excluded package list * Remove redundant 'exit 1' * Change the API to allow passing test.T to test handlers * Make testing.T an embedded field * Use assert.Equal to comparing results * Add copyright info * Parametrized logging output * Use tmpdir instead * Eliminate redundant casting * Remove unneeded variable * Fix last commit * Add missing copyright info * Replace fmt.Fprintf with fmt.Fprint * rename the xtest to integration-test * Use Symlink instead of hard-link for cross-device linking * Turn debugging logs on * Follow the existing framework for APIs * Output logs only if test.v is true * Re-order import statements * Enhance the error message * Fix comment which breaks the linter's rule * Rename 'integration-test' to 'e2e-test' for saving keystrokes * Add comment to avoid possible confusion * Rename tests -> integration-tests Also change back the Makefile to use `make integration-test`. * Use tests/integration for now * tests/integration -> integrations Slightly flattened directory hierarchy is better. * Update Makefile accordingly * Fix a missing change in Makefile * govendor update code.gitea.io/sdk/gitea * Fix comment of struct fields * Fix conditional nonsense * Fix missing updates regarding version string changes * Make variable naming more consistent * Check http status code * Rectify error messages
7 years ago
9 years ago
9 years ago
  1. DIST := dist
  2. IMPORT := code.gitea.io/gitea
  3. BINDATA := modules/{options,public,templates}/bindata.go
  4. STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
  5. JAVASCRIPTS :=
  6. DOCKER_TAG := gitea/gitea:latest
  7. GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*" -not -path "*/bindata.go")
  8. GOFMT ?= gofmt -s
  9. GOFLAGS := -i -v
  10. EXTRA_GOFLAGS ?=
  11. LDFLAGS := -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')" -X "main.Tags=$(TAGS)"
  12. PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations,$(shell go list ./... | grep -v /vendor/))
  13. SOURCES ?= $(shell find . -name "*.go" -type f)
  14. TAGS ?=
  15. TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gitea-temp')
  16. ifeq ($(OS), Windows_NT)
  17. EXECUTABLE := gitea.exe
  18. else
  19. EXECUTABLE := gitea
  20. endif
  21. ifneq ($(DRONE_TAG),)
  22. VERSION ?= $(subst v,,$(DRONE_TAG))
  23. else
  24. ifneq ($(DRONE_BRANCH),)
  25. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  26. else
  27. VERSION ?= master
  28. endif
  29. endif
  30. .PHONY: all
  31. all: build
  32. .PHONY: clean
  33. clean:
  34. go clean -i ./...
  35. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA)
  36. required-gofmt-version:
  37. @go version | grep -q '\(1.7\|1.8\)' || { echo "We require go version 1.7 or 1.8 to format code" >&2 && exit 1; }
  38. .PHONY: fmt
  39. fmt: required-gofmt-version
  40. $(GOFMT) -w $(GOFILES)
  41. .PHONY: vet
  42. vet:
  43. go vet $(PACKAGES)
  44. .PHONY: generate
  45. generate:
  46. @hash go-bindata > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  47. go get -u github.com/jteeuwen/go-bindata/...; \
  48. fi
  49. @hash swagger > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  50. go get -u github.com/go-swagger/go-swagger/cmd/swagger; \
  51. fi
  52. go generate $(PACKAGES)
  53. .PHONY: errcheck
  54. errcheck:
  55. @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  56. go get -u github.com/kisielk/errcheck; \
  57. fi
  58. errcheck $(PACKAGES)
  59. .PHONY: lint
  60. lint:
  61. @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  62. go get -u github.com/golang/lint/golint; \
  63. fi
  64. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  65. .PHONY: misspell-check
  66. misspell-check:
  67. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  68. go get -u github.com/client9/misspell/cmd/misspell; \
  69. fi
  70. misspell -error -i unknwon $(GOFILES)
  71. .PHONY: misspell
  72. misspell:
  73. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  74. go get -u github.com/client9/misspell/cmd/misspell; \
  75. fi
  76. misspell -w -i unknwon $(GOFILES)
  77. .PHONY: fmt-check
  78. fmt-check: required-gofmt-version
  79. # get all go files and run go fmt on them
  80. @diff=$$($(GOFMT) -d $(GOFILES)); \
  81. if [ -n "$$diff" ]; then \
  82. echo "Please run 'make fmt' and commit the result:"; \
  83. echo "$${diff}"; \
  84. exit 1; \
  85. fi;
  86. .PHONY: test
  87. test: fmt-check
  88. go test $(PACKAGES)
  89. .PHONY: test-coverage
  90. test-coverage:
  91. for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
  92. .PHONY: test-vendor
  93. test-vendor:
  94. @hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  95. go get -u github.com/kardianos/govendor; \
  96. fi
  97. govendor list +unused | tee "$(TMPDIR)/wc-gitea-unused"
  98. [ $$(cat "$(TMPDIR)/wc-gitea-unused" | wc -l) -eq 0 ] || echo "Warning: /!\\ Some vendor are not used /!\\"
  99. govendor list +outside | tee "$(TMPDIR)/wc-gitea-outside"
  100. [ $$(cat "$(TMPDIR)/wc-gitea-outside" | wc -l) -eq 0 ] || exit 1
  101. govendor status || exit 1
  102. .PHONY: test-sqlite
  103. test-sqlite:
  104. go test -c code.gitea.io/gitea/integrations -tags 'sqlite'
  105. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.test
  106. .PHONY: test-mysql
  107. test-mysql: integrations.test
  108. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.test
  109. .PHONY: test-pgsql
  110. test-pgsql: integrations.test
  111. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test
  112. integrations.test: $(SOURCES)
  113. go test -c code.gitea.io/gitea/integrations
  114. .PHONY: check
  115. check: test
  116. .PHONY: install
  117. install: $(wildcard *.go)
  118. go install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  119. .PHONY: build
  120. build: $(EXECUTABLE)
  121. $(EXECUTABLE): $(SOURCES)
  122. go build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  123. .PHONY: docker
  124. docker:
  125. docker run -ti --rm -v $(CURDIR):/srv/app/src/code.gitea.io/gitea -w /srv/app/src/code.gitea.io/gitea -e TAGS="bindata $(TAGS)" webhippie/golang:edge make clean generate build
  126. docker build -t $(DOCKER_TAG) .
  127. .PHONY: release
  128. release: release-dirs release-windows release-linux release-darwin release-copy release-check
  129. .PHONY: release-dirs
  130. release-dirs:
  131. mkdir -p $(DIST)/binaries $(DIST)/release
  132. .PHONY: release-windows
  133. release-windows:
  134. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  135. go get -u github.com/karalabe/xgo; \
  136. fi
  137. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  138. ifeq ($(CI),drone)
  139. mv /build/* $(DIST)/binaries
  140. endif
  141. .PHONY: release-linux
  142. release-linux:
  143. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  144. go get -u github.com/karalabe/xgo; \
  145. fi
  146. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out gitea-$(VERSION) .
  147. ifeq ($(CI),drone)
  148. mv /build/* $(DIST)/binaries
  149. endif
  150. .PHONY: release-darwin
  151. release-darwin:
  152. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  153. go get -u github.com/karalabe/xgo; \
  154. fi
  155. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  156. ifeq ($(CI),drone)
  157. mv /build/* $(DIST)/binaries
  158. endif
  159. .PHONY: release-copy
  160. release-copy:
  161. $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
  162. .PHONY: release-check
  163. release-check:
  164. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  165. .PHONY: javascripts
  166. javascripts: public/js/index.js
  167. .IGNORE: public/js/index.js
  168. public/js/index.js: $(JAVASCRIPTS)
  169. cat $< >| $@
  170. .PHONY: stylesheets
  171. stylesheets: public/css/index.css
  172. .IGNORE: public/css/index.css
  173. public/css/index.css: $(STYLESHEETS)
  174. lessc $< $@
  175. .PHONY: swagger-ui
  176. swagger-ui:
  177. rm -Rf public/assets/swagger-ui
  178. git clone --depth=10 -b v3.0.7 --single-branch https://github.com/swagger-api/swagger-ui.git /tmp/swagger-ui
  179. mv /tmp/swagger-ui/dist public/assets/swagger-ui
  180. rm -Rf /tmp/swagger-ui
  181. sed -i "s;http://petstore.swagger.io/v2/swagger.json;../../swagger.v1.json;g" public/assets/swagger-ui/index.html
  182. .PHONY: assets
  183. assets: javascripts stylesheets