Skip to content

Commit

Permalink
[MM-12449] Use separate database and default config.json when running…
Browse files Browse the repository at this point in the history
… end-to-end testing (mattermost#1924)

* use different mysql database and default config.json in running end-to-end testing

* update e2e make command to have exact order of targets and remove changes to default config

* revert DataSource changes when no config-backup.json found

* use variable for server and webapp directories and add new commands to phony targets to guarantee order

* remove other commands
  • Loading branch information
saturninoabril authored and crspeller committed Oct 24, 2018
1 parent 16a8624 commit 4f6606c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 17 deletions.
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.PHONY: build test run clean stop check-style run-unit emojis help

BUILD_SERVER_DIR = ../mattermost-server
BUILD_WEBAPP_DIR = ../mattermost-webapp
EMOJI_TOOLS_DIR = ./build/emoji

check-style: node_modules ## Checks JS file for ESLint confirmity
Expand Down Expand Up @@ -64,6 +65,41 @@ clean: ## Clears cached; deletes node_modules and dist directories
rm -rf dist
rm -rf node_modules

e2e: node_modules
@echo E2E: Running mattermost-mysql-e2e
@if [ $(shell docker ps -a | grep -ci mattermost-mysql-e2e) -eq 0 ]; then \
echo starting mattermost-mysql-e2e; \
docker run --name mattermost-mysql-e2e -p 35476:3306 -e MYSQL_ROOT_PASSWORD=mostest \
-e MYSQL_USER=mmuser -e MYSQL_PASSWORD=mostest -e MYSQL_DATABASE=mattermost_test -d mysql:5.7 > /dev/null; \
elif [ $(shell docker ps | grep -ci mattermost-mysql-e2e) -eq 0 ]; then \
echo restarting mattermost-mysql-e2e; \
docker start mattermost-mysql-e2e > /dev/null; \
fi

cd $(BUILD_SERVER_DIR) && [[ -f config/config.json ]] && \
cp config/config.json config/config-backup.json && cp config/default.json config/config.json || \
echo "config.json not found" && cp config/default.json config/config.json

@echo E2E: Running end-to-end testing
npm run test:e2e

@echo stopping mattermost-mysql-e2e
docker stop mattermost-mysql-e2e > /dev/null

cd $(BUILD_SERVER_DIR) && [[ -f config/config-backup.json ]] && \
cp config/config-backup.json config/config.json && echo "revert local config.json" || \
echo "config-backup.json not found" && sed -i'' -e 's|"DataSource": ".*"|"DataSource": "mmuser:mostest@tcp(dockerhost:3306)/mattermost_test?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s"|g' config/config.json

clean-e2e:
@if [ $(shell docker ps -a | grep -ci mattermost-mysql-e2e) -eq 1 ]; then \
echo stopping mattermost-mysql-e2e; \
docker stop mattermost-mysql-e2e > /dev/null; \
fi

cd $(BUILD_SERVER_DIR) && [[ -f config/config-backup.json ]] && \
cp config/config-backup.json config/config.json && echo "revert local config.json" || \
echo "config-backup.json not found" && sed -i'' -e 's|"DataSource": ".*"|"DataSource": "mmuser:mostest@tcp(dockerhost:3306)/mattermost_test?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s"|g' config/config.json

emojis: ## Creates emoji JSX file and extracts emoji images from the system font
gem install bundler
bundle install --gemfile=$(EMOJI_TOOLS_DIR)/Gemfile
Expand Down
45 changes: 28 additions & 17 deletions tests/e2e/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
set -e

PLATFORM_FILES="./cmd/mattermost/main.go"
BUILD_SERVER_DIR="../mattermost-server"
BUILD_WEBAPP_DIR="../mattermost-webapp"

function message {
echo ""
Expand Down Expand Up @@ -32,33 +34,39 @@ function selenium_start {
function modify_config {
message "Modifying config..."

cd ../mattermost-server
cd $BUILD_SERVER_DIR

echo "config: enable email invitation"
sed -i'' -e 's|"EnableEmailInvitations": false|"EnableEmailInvitations": true|g' config/config.json

echo "config: enable email notification"
sed -i'' -e 's|"SendEmailNotifications": false|"SendEmailNotifications": true|g' config/config.json

echo "config: enable mobile push notification"
sed -i'' -e 's|"SendPushNotifications": false|"SendPushNotifications": true|g' config/config.json
sed -i'' -e 's|"PushNotificationServer": ".*"|"PushNotificationServer": "https://push.mattermost.com"|g' config/config.json
sed -i'' -e 's|"PushNotificationContents": ".*"|"PushNotificationContents": "generic"|g' config/config.json

cd ../mattermost-webapp
echo "config: set e2e database"
sed -i'' -e 's|"DataSource": ".*"|"DataSource": "mmuser:mostest@tcp(dockerhost:35476)/mattermost_test?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s"|g' config/config.json

cd $BUILD_WEBAPP_DIR
sleep 5
}

function restart_server {
cd ../mattermost-server
function start_server {
cd $BUILD_SERVER_DIR

echo "stop the server"
make stop
sleep 5
echo "start the server"
make run

cd ../mattermost-webapp
cd $BUILD_WEBAPP_DIR
sleep 5
}

function stop_server {
cd $BUILD_SERVER_DIR

echo "stop the server"
make stop

cd $BUILD_WEBAPP_DIR
sleep 5
}

Expand All @@ -79,18 +87,18 @@ function local_setup {
}

function reset_db {
cd ../mattermost-server
cd $BUILD_SERVER_DIR

echo "reset the database"
go run $PLATFORM_FILES reset --confirm true

cd ../mattermost-webapp
cd $BUILD_WEBAPP_DIR
sleep 5
}

function add_test_users {
message "Adding test users..."
cd ../mattermost-server
cd $BUILD_SERVER_DIR

echo "reset the database"
go run $PLATFORM_FILES reset --confirm true
Expand All @@ -110,7 +118,7 @@ function add_test_users {
echo "adding users to 'ui-automation' team"
go run $PLATFORM_FILES team add ui-automation [email protected]

cd ../mattermost-webapp
cd $BUILD_WEBAPP_DIR
sleep 5
}

Expand All @@ -123,7 +131,8 @@ function local_tests {
local_setup

modify_config
restart_server
stop_server
start_server

if [ -n "$1" ]; then
message "Tag: ${1} local E2E starts..."
Expand All @@ -138,6 +147,8 @@ function local_tests {
message "E2E full local firefox starts..."
nightwatch -e firefox --skiptags tutorial --suiteRetries 1
fi

stop_server
}

local_tests $@

0 comments on commit 4f6606c

Please sign in to comment.