Dockerized build updated tests (#9943)

* testlib: introduce and leverage

This doesn't yet factor out the individual test helpers: many packages
still rely on `api4` directly to do this, but now wire up the test store
setup through this package. `app` and `store`, in particular, don't use
`testlib` because of circular dependencies at the moment.

* cmd: command_test.go: use api4 testlib

* cmd: plugin_test.go: remove dependence on test-config.json

* cmd: config_test.go use configured database settings

* ensure test-(te|ee) exit with status code

* test-server: run all tests, deprecating test-te/test-ee

* cmd/mattermost/commands: fix unit tests

Instead of relying on (and modifying) a config.json found in the current path, explicitly create a temporary one from defaults for each test. This was likely the source of various bugs over time, but specifically allows us to override the SqlSettings to point at the configured test database for all tests simultaneously.

* wrap run/check into a test helper

It was insufficient to set a config for each invocation of CheckCommand or RunCommand: some tests relied on the config having changed in a subsequent assertion. Instead, create a new test helper embedding api4.TestHelper. This has the nice advantage of cleaning up all the teardown.

* additional TestConfigGet granularity

* customized config path to avoid default location

* be explicit if the storetest initialization fails

* generate safe coverprofile names in the presence of subtests

* additional TestConfigShow granularity

* fix permission_test.go typo

* fix webhook tests

* actually flag.Parse() to skip database setup on os.Execed tests

* fix recent regression in #9962, not caught by unit tests
Этот коммит содержится в:
Jesse Hallam
2018-12-06 13:19:32 -05:00
коммит произвёл GitHub
родитель 2708ed6d1f
Коммит d39d9a5caf
36 изменённых файлов: 775 добавлений и 1110 удалений

Просмотреть файл

@@ -71,7 +71,6 @@ TESTFLAGSEE ?= -short
# Packages lists
TE_PACKAGES=$(shell go list ./...)
TE_PACKAGES_COMMA=$(shell echo $(TE_PACKAGES) | tr ' ' ',')
# Plugins Packages
PLUGIN_PACKAGES=mattermost-plugin-zoom mattermost-plugin-jira
@@ -83,15 +82,16 @@ ifeq ($(BUILD_ENTERPRISE_READY),true)
IGNORE:=$(shell cp $(BUILD_ENTERPRISE_DIR)/imports/imports.go imports/)
IGNORE:=$(shell rm -f enterprise)
IGNORE:=$(shell ln -s $(BUILD_ENTERPRISE_DIR) enterprise)
else
IGNORE:=$(shell rm -f imports/imports.go)
endif
EE_PACKAGES=$(shell go list ./enterprise/...)
EE_PACKAGES_COMMA=$(shell echo $(EE_PACKAGES) | tr ' ' ',')
ifeq ($(BUILD_ENTERPRISE_READY),true)
ALL_PACKAGES_COMMA=$(TE_PACKAGES_COMMA),$(EE_PACKAGES_COMMA)
ALL_PACKAGES=$(TE_PACKAGES) $(EE_PACKAGES)
else
ALL_PACKAGES_COMMA=$(TE_PACKAGES_COMMA)
ALL_PACKAGES=$(TE_PACKAGES)
endif
@@ -354,33 +354,6 @@ do-cover-file: ## Creates the test coverage report file.
go-junit-report:
go get -u github.com/jstemmer/go-junit-report
test-te: start-docker go-junit-report do-cover-file ## Runs tests in the team edition.
@echo Testing TE
@echo "Packages to test: "$(TE_PACKAGES)
find . -name 'cprofile*.out' -exec sh -c 'rm "{}"' \;
$(GO) test $(GOFLAGS) -run=$(TESTS) $(TESTFLAGS) -p 1 -v -timeout=2000s -covermode=count -coverpkg=$(ALL_PACKAGES_COMMA) -exec $(ROOT)/scripts/test-xprog.sh $(TE_PACKAGES) | tee output-test-te
cat output-test-te | $(GOPATH)/bin/go-junit-report > report-te.xml && rm output-test-te
find . -name 'cprofile*.out' -exec sh -c 'tail -n +2 {} >> cover.out ; rm "{}"' \;
test-ee: start-docker go-junit-report do-cover-file ## Runs tests in the enterprise edition.
@echo Testing EE
rm -f enterprise/config/*.crt
rm -f enterprise/config/*.key
ifeq ($(BUILD_ENTERPRISE_READY),true)
@echo Testing EE
@echo "Packages to test: "$(EE_PACKAGES)
find . -name 'cprofile*.out' -exec sh -c 'rm "{}"' \;
$(GO) test $(GOFLAGS) -run=$(TESTS) $(TESTFLAGSEE) -p 1 -v -timeout=2000s -covermode=count -coverpkg=$(ALL_PACKAGES_COMMA) -exec $(ROOT)/scripts/test-xprog.sh $(EE_PACKAGES) 2>&1 | tee output-test-ee
cat output-test-ee | $(GOPATH)/bin/go-junit-report > report-ee.xml && rm output-test-ee
find . -name 'cprofile*.out' -exec sh -c 'tail -n +2 {} >> cover.out ; rm "{}"' \;
rm -f enterprise/config/*.crt
rm -f enterprise/config/*.key
else
@echo Skipping EE Tests
endif
test-compile:
@echo COMPILE TESTS
@@ -388,8 +361,13 @@ test-compile:
$(GO) test $(GOFLAGS) -c $$package; \
done
test-server: test-te test-ee ## Runs tests.
find . -type d -name data -not -path './vendor/*' | xargs rm -rf
test-server: start-docker go-junit-report do-cover-file ## Runs tests.
ifeq ($(BUILD_ENTERPRISE_READY),true)
@echo Running all tests
else
@echo Running only TE tests
endif
./scripts/test.sh "$(GO)" "$(GOFLAGS)" "$(ALL_PACKAGES)" "$(TESTS)" "$(TESTFLAGS)"
internal-test-web-client: ## Runs web client tests.
$(GO) run $(GOFLAGS) $(PLATFORM_FILES) test web_client_tests