Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test the Dockerfile #3677

Merged
merged 6 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
language: node_js

node_js:
- "lts/*"
install:
- "bin/installDeps.sh"
- "export GIT_HASH=$(git rev-parse --verify --short HEAD)"
- "npm install ep_test_line_attrib"
script:
- "tests/frontend/travis/runner.sh"

services:
- docker

env:
global:
- secure: "WMGxFkOeTTlhWB+ChMucRtIqVmMbwzYdNHuHQjKCcj8HBEPdZLfCuK/kf4rG\nVLcLQiIsyllqzNhBGVHG1nyqWr0/LTm8JRqSCDDVIhpyzp9KpCJQQJG2Uwjk\n6/HIJJh/wbxsEdLNV2crYU/EiVO3A4Bq0YTHUlbhUqG3mSCr5Ec="
- secure: "gejXUAHYscbR6Bodw35XexpToqWkv2ifeECsbeEmjaLkYzXmUUNWJGknKSu7\nEUsSfQV8w+hxApr1Z+jNqk9aX3K1I4btL3cwk2trnNI8XRAvu1c1Iv60eerI\nkE82Rsd5lwUaMEh+/HoL8ztFCZamVndoNgX7HWp5J/NRZZMmh4g="
jdk:
- oraclejdk6

jobs:
include:
- name: "Test the Frontend"
install:
- "bin/installDeps.sh"
- "export GIT_HASH=$(git rev-parse --verify --short HEAD)"
- "npm install ep_test_line_attrib"
script:
- "tests/frontend/travis/runner.sh"
- name: "Test the Dockerfile"
install:
- "cd src && npm install && cd -"
script:
- "docker build -t etherpad:test ."
- "docker run -d -p 9001:9001 etherpad:test && sleep 3"
- "cd src && npm run test-container"

notifications:
irc:
channels:
Expand Down
3 changes: 2 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
"url": "https://github.com/ether/etherpad-lite.git"
},
"scripts": {
"test": "nyc mocha --timeout 5000 ../tests/backend/specs/api"
"test": "nyc mocha --timeout 5000 ../tests/backend/specs/api",
"test-container": "nyc mocha --timeout 5000 ../tests/container/specs/api"
},
"version": "1.8.0",
"license": "Apache-2.0"
Expand Down
13 changes: 11 additions & 2 deletions tests/backend/loadSettings.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
/*
* ACHTUNG: there is a copied & modified version of this file in
* <basedir>/tests/container/loadSettings.js
*
* TODO: unify those two files, and merge in a single one.
*/

var jsonminify = require(__dirname+"/../../src/node_modules/jsonminify");
const fs = require('fs');

function loadSettings(){
var settingsStr = fs.readFileSync(__dirname+"/../../settings.json").toString();
// try to parse the settings
var settings;
try {
if(settingsStr) {
settingsStr = jsonminify(settingsStr).replace(",]","]").replace(",}","}");
return JSON.parse(settingsStr);
var settings = JSON.parse(settingsStr);

return settings;
}
}catch(e){
console.error("whoops something is bad with settings");
Expand Down
31 changes: 19 additions & 12 deletions tests/backend/specs/api/pad.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
var assert = require('assert')
supertest = require(__dirname+'/../../../../src/node_modules/supertest'),
fs = require('fs'),
settings = require(__dirname+'/../../loadSettings').loadSettings(),
api = supertest('http://'+settings.ip+":"+settings.port),
path = require('path'),
async = require(__dirname+'/../../../../src/node_modules/async');
/*
* ACHTUNG: there is a copied & modified version of this file in
* <basedir>/tests/container/spacs/api/pad.js
*
* TODO: unify those two files, and merge in a single one.
*/

const assert = require('assert');
const supertest = require(__dirname+'/../../../../src/node_modules/supertest');
const fs = require('fs');
const settings = require(__dirname+'/../../loadSettings').loadSettings();
const api = supertest('http://'+settings.ip+":"+settings.port);
const path = require('path');
const async = require(__dirname+'/../../../../src/node_modules/async');

var filePath = path.join(__dirname, '../../../../APIKEY.txt');

Expand All @@ -29,15 +36,15 @@ var ulHtml = '<!doctype html><html><body><ul class="bullet"><li>one</li><li>two<
var expectedHtml = '<!doctype html><html><body><ul class="bullet"><li>one</li><li>two</li><li>0</li><li>1</li><li>2<ul class="bullet"><li>3</li><li>4</ul></li></ul><ol class="number"><li>item<ol class="number"><li>item1</li><li>item2</ol></li></ol></body></html>';

describe('Connectivity', function(){
it('errors if can not connect', function(done) {
it('can connect', function(done) {
api.get('/api/')
.expect('Content-Type', /json/)
.expect(200, done)
});
})

describe('API Versioning', function(){
it('errors if can not connect', function(done) {
it('finds the version tag', function(done) {
api.get('/api/')
.expect(function(res){
apiVersion = res.body.currentVersion;
Expand All @@ -49,7 +56,7 @@ describe('API Versioning', function(){
})

describe('Permission', function(){
it('errors if can connect without correct APIKey', function(done) {
it('errors with invalid APIKey', function(done) {
// This is broken because Etherpad doesn't handle HTTP codes properly see #2343
// If your APIKey is password you deserve to fail all tests anyway
var permErrorURL = '/api/'+apiVersion+'/createPad?apikey=password&padID=test';
Expand Down Expand Up @@ -204,7 +211,7 @@ describe('getText', function(){
api.get(endPoint('getText')+"&padID="+testPadId)
.expect(function(res){
if(res.body.data.text !== "testText\n") throw new Error("Pad Creation with text")
})
})
.expect('Content-Type', /json/)
.expect(200, done)
});
Expand Down Expand Up @@ -573,7 +580,7 @@ describe('createPad', function(){
it('errors if pad can be created', function(done) {
var badUrlChars = ["/", "%23", "%3F", "%26"];
async.map(
badUrlChars,
badUrlChars,
function (badUrlChar, cb) {
api.get(endPoint('createPad')+"&padID="+badUrlChar)
.expect(function(res){
Expand Down
30 changes: 30 additions & 0 deletions tests/container/loadSettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* ACHTUNG: this file was copied & modified from the analogous
* <basedir>/tests/backend/loadSettings.js
*
* TODO: unify those two files, and merge in a single one.
*/

var jsonminify = require(__dirname+"/../../src/node_modules/jsonminify");
const fs = require('fs');

function loadSettings(){
var settingsStr = fs.readFileSync(__dirname+"/../../settings.json.docker").toString();
// try to parse the settings
try {
if(settingsStr) {
settingsStr = jsonminify(settingsStr).replace(",]","]").replace(",}","}");
var settings = JSON.parse(settingsStr);

// custom settings for running in a container
settings.ip = 'localhost';
settings.port = '9001';

return settings;
}
}catch(e){
console.error("whoops something is bad with settings");
}
}

exports.loadSettings = loadSettings;
38 changes: 38 additions & 0 deletions tests/container/specs/api/pad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* ACHTUNG: this file was copied & modified from the analogous
* <basedir>/tests/backend/specs/api/pad.js
*
* TODO: unify those two files, and merge in a single one.
*/

const supertest = require(__dirname+'/../../../../src/node_modules/supertest');
const settings = require(__dirname+'/../../loadSettings').loadSettings();
const api = supertest('http://'+settings.ip+":"+settings.port);

var apiVersion = 1;

describe('Connectivity', function(){
it('can connect', function(done) {
api.get('/api/')
.expect('Content-Type', /json/)
.expect(200, done)
});
})

describe('API Versioning', function(){
it('finds the version tag', function(done) {
api.get('/api/')
.expect(function(res){
if (!res.body.currentVersion) throw new Error("No version set in API");
return;
})
.expect(200, done)
});
})

describe('Permission', function(){
it('errors with invalid APIKey', function(done) {
api.get('/api/'+apiVersion+'/createPad?apikey=wrong_password&padID=test')
.expect(401, done)
});
})
6 changes: 6 additions & 0 deletions tests/frontend/travis/sauce_tunnel.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash
# download and unzip the sauce connector
#
# ACHTUNG: as of 2019-12-21, downloading sc-latest-linux.tar.gz does not work.
# It is necessary to explicitly download a specific version, for
# example https://saucelabs.com/downloads/sc-4.5.4-linux.tar.gz
# Supported versions are currently listed at:
# https://wiki.saucelabs.com/display/DOCS/Downloading+Sauce+Connect+Proxy
curl https://saucelabs.com/downloads/sc-latest-linux.tar.gz > /tmp/sauce.tar.gz
tar zxf /tmp/sauce.tar.gz --directory /tmp
mv /tmp/sc-*-linux /tmp/sauce_connect
Expand Down