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.

200 lines
5.5 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
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. ifeq ($(OS), Windows_NT)
  4. EXECUTABLE := gitea.exe
  5. else
  6. EXECUTABLE := gitea
  7. endif
  8. BINDATA := modules/{options,public,templates}/bindata.go
  9. STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
  10. JAVASCRIPTS :=
  11. GOFLAGS := -i -v
  12. EXTRA_GOFLAGS ?=
  13. LDFLAGS := -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')" -X "main.Tags=$(TAGS)"
  14. PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations,$(shell go list ./... | grep -v /vendor/))
  15. SOURCES ?= $(shell find . -name "*.go" -type f)
  16. TAGS ?=
  17. TMPDIR := $(shell mktemp -d)
  18. ifneq ($(DRONE_TAG),)
  19. VERSION ?= $(subst v,,$(DRONE_TAG))
  20. else
  21. ifneq ($(DRONE_BRANCH),)
  22. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  23. else
  24. VERSION ?= master
  25. endif
  26. endif
  27. .PHONY: all
  28. all: build
  29. .PHONY: clean
  30. clean:
  31. go clean -i ./...
  32. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA)
  33. .PHONY: fmt
  34. fmt:
  35. find . -name "*.go" -type f -not -path "./vendor/*" | xargs gofmt -s -w
  36. .PHONY: vet
  37. vet:
  38. go vet $(PACKAGES)
  39. .PHONY: generate
  40. generate:
  41. @hash go-bindata > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  42. go get -u github.com/jteeuwen/go-bindata/...; \
  43. fi
  44. @hash swagger > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  45. go get -u github.com/go-swagger/go-swagger/cmd/swagger; \
  46. fi
  47. go generate $(PACKAGES)
  48. .PHONY: errcheck
  49. errcheck:
  50. @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  51. go get -u github.com/kisielk/errcheck; \
  52. fi
  53. errcheck $(PACKAGES)
  54. .PHONY: lint
  55. lint:
  56. @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  57. go get -u github.com/golang/lint/golint; \
  58. fi
  59. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  60. .PHONY: integrations
  61. integrations: TAGS=bindata sqlite
  62. integrations: build
  63. go test code.gitea.io/gitea/integrations
  64. .PHONY: test
  65. test:
  66. for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
  67. .PHONY: test-vendor
  68. test-vendor:
  69. @hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  70. go get -u github.com/kardianos/govendor; \
  71. fi
  72. govendor list +unused | tee "$(TMPDIR)/wc-gitea-unused"
  73. [ $$(cat "$(TMPDIR)/wc-gitea-unused" | wc -l) -eq 0 ] || echo "Warning: /!\\ Some vendor are not used /!\\"
  74. govendor list +outside | tee "$(TMPDIR)/wc-gitea-outside"
  75. [ $$(cat "$(TMPDIR)/wc-gitea-outside" | wc -l) -eq 0 ] || exit 1
  76. govendor status || exit 1
  77. .PHONY: test-sqlite
  78. test-sqlite:
  79. go test -c code.gitea.io/gitea/integrations -tags 'sqlite'
  80. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.test
  81. .PHONY: test-mysql
  82. test-mysql: integrations.test
  83. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.test
  84. .PHONY: test-pgsql
  85. test-pgsql: integrations.test
  86. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test
  87. integrations.test: $(SOURCES)
  88. go test -c code.gitea.io/gitea/integrations
  89. .PHONY: check
  90. check: test
  91. .PHONY: install
  92. install: $(wildcard *.go)
  93. go install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  94. .PHONY: build
  95. build: $(EXECUTABLE)
  96. $(EXECUTABLE): $(SOURCES)
  97. go build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  98. .PHONY: docker
  99. docker:
  100. 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
  101. docker build -t gitea/gitea:latest .
  102. .PHONY: release
  103. release: release-dirs release-windows release-linux release-darwin release-copy release-check
  104. .PHONY: release-dirs
  105. release-dirs:
  106. mkdir -p $(DIST)/binaries $(DIST)/release
  107. .PHONY: release-windows
  108. release-windows:
  109. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  110. go get -u github.com/karalabe/xgo; \
  111. fi
  112. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  113. ifeq ($(CI),drone)
  114. mv /build/* $(DIST)/binaries
  115. endif
  116. .PHONY: release-linux
  117. release-linux:
  118. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  119. go get -u github.com/karalabe/xgo; \
  120. fi
  121. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out gitea-$(VERSION) .
  122. ifeq ($(CI),drone)
  123. mv /build/* $(DIST)/binaries
  124. endif
  125. .PHONY: release-darwin
  126. release-darwin:
  127. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  128. go get -u github.com/karalabe/xgo; \
  129. fi
  130. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  131. ifeq ($(CI),drone)
  132. mv /build/* $(DIST)/binaries
  133. endif
  134. .PHONY: release-copy
  135. release-copy:
  136. $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
  137. .PHONY: release-check
  138. release-check:
  139. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  140. .PHONY: javascripts
  141. javascripts: public/js/index.js
  142. .IGNORE: public/js/index.js
  143. public/js/index.js: $(JAVASCRIPTS)
  144. cat $< >| $@
  145. .PHONY: stylesheets
  146. stylesheets: public/css/index.css
  147. .IGNORE: public/css/index.css
  148. public/css/index.css: $(STYLESHEETS)
  149. lessc $< $@
  150. .PHONY: swagger-ui
  151. swagger-ui:
  152. rm -Rf public/assets/swagger-ui
  153. git clone --depth=10 -b v3.0.7 --single-branch https://github.com/swagger-api/swagger-ui.git /tmp/swagger-ui
  154. mv /tmp/swagger-ui/dist public/assets/swagger-ui
  155. rm -Rf /tmp/swagger-ui
  156. sed -i "s;http://petstore.swagger.io/v2/swagger.json;../../swagger.v1.json;g" public/assets/swagger-ui/index.html
  157. .PHONY: assets
  158. assets: javascripts stylesheets