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.

163 lines
4.1 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. 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. ifneq ($(DRONE_TAG),)
  16. VERSION ?= $(subst v,,$(DRONE_TAG))
  17. else
  18. ifneq ($(DRONE_BRANCH),)
  19. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  20. else
  21. VERSION ?= master
  22. endif
  23. endif
  24. .PHONY: all
  25. all: build
  26. .PHONY: clean
  27. clean:
  28. go clean -i ./...
  29. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA)
  30. .PHONY: fmt
  31. fmt:
  32. find . -name "*.go" -type f -not -path "./vendor/*" | xargs gofmt -s -w
  33. .PHONY: vet
  34. vet:
  35. go vet $(PACKAGES)
  36. .PHONY: generate
  37. generate:
  38. @hash go-bindata > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  39. go get -u github.com/jteeuwen/go-bindata/...; \
  40. fi
  41. go generate $(PACKAGES)
  42. .PHONY: errcheck
  43. errcheck:
  44. @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  45. go get -u github.com/kisielk/errcheck; \
  46. fi
  47. errcheck $(PACKAGES)
  48. .PHONY: lint
  49. lint:
  50. @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  51. go get -u github.com/golang/lint/golint; \
  52. fi
  53. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  54. .PHONY: integrations
  55. integrations: TAGS=bindata sqlite
  56. integrations: build
  57. go test code.gitea.io/gitea/integrations
  58. .PHONY: test
  59. test:
  60. for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
  61. .PHONY: test-mysql
  62. test-mysql:
  63. @echo "Not integrated yet!"
  64. .PHONY: test-pgsql
  65. test-pgsql:
  66. @echo "Not integrated yet!"
  67. .PHONY: check
  68. check: test
  69. .PHONY: install
  70. install: $(wildcard *.go)
  71. go install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  72. .PHONY: build
  73. build: $(EXECUTABLE)
  74. $(EXECUTABLE): $(SOURCES)
  75. go build -i -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  76. .PHONY: docker
  77. docker:
  78. 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
  79. docker build -t gitea/gitea:latest .
  80. .PHONY: release
  81. release: release-dirs release-windows release-linux release-darwin release-copy release-check
  82. .PHONY: release-dirs
  83. release-dirs:
  84. mkdir -p $(DIST)/binaries $(DIST)/release
  85. .PHONY: release-windows
  86. release-windows:
  87. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  88. go get -u github.com/karalabe/xgo; \
  89. fi
  90. xgo -dest $(DIST)/binaries -tags '$(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  91. ifeq ($(CI),drone)
  92. mv /build/* $(DIST)/binaries
  93. endif
  94. .PHONY: release-linux
  95. release-linux:
  96. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  97. go get -u github.com/karalabe/xgo; \
  98. fi
  99. xgo -dest $(DIST)/binaries -tags '$(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out gitea-$(VERSION) .
  100. ifeq ($(CI),drone)
  101. mv /build/* $(DIST)/binaries
  102. endif
  103. .PHONY: release-darwin
  104. release-darwin:
  105. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  106. go get -u github.com/karalabe/xgo; \
  107. fi
  108. xgo -dest $(DIST)/binaries -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  109. ifeq ($(CI),drone)
  110. mv /build/* $(DIST)/binaries
  111. endif
  112. .PHONY: release-copy
  113. release-copy:
  114. $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
  115. .PHONY: release-check
  116. release-check:
  117. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  118. .PHONY: javascripts
  119. javascripts: public/js/index.js
  120. .IGNORE: public/js/index.js
  121. public/js/index.js: $(JAVASCRIPTS)
  122. cat $< >| $@
  123. .PHONY: stylesheets
  124. stylesheets: public/css/index.css
  125. .IGNORE: public/css/index.css
  126. public/css/index.css: $(STYLESHEETS)
  127. lessc $< $@
  128. .PHONY: assets
  129. assets: javascripts stylesheets