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

Testing Brigade #7

Open
wants to merge 22 commits into
base: add-brigade
Choose a base branch
from
Open
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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .Dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app/node-app
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.pyc
*.egg-info
.DS_Store
.node_modules
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu:16.04

RUN apt-get update -y && \
apt-get install -y python-pip python-dev

# We copy just the requirements.txt first to leverage Docker cache
COPY ./requirements.txt /app/requirements.txt

WORKDIR /app

RUN pip install -r requirements.txt

COPY . /app

EXPOSE 5000

CMD ["python", "app/__init__.py" ]
Binary file added app/.DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
@app.route("/")
def hello():
return Response(str(uuid.uuid4()), status=200, mimetype='text/plain')


if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)
61 changes: 61 additions & 0 deletions app/node-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
41 changes: 41 additions & 0 deletions app/node-app/brigade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const { events, Job } = require("brigadier");

events.on("pull_request", function(e, project) {
console.log("received push for commit " + e.commit);

// Create a new job
var node = new Job("test-runner");

// We want our job to run the stock Docker Python 3 image
node.image = "node:9-alpine";

// Now we want it to run these commands in order:
node.tasks = ["cd /src/", "npm install", "npm test"];

// We're done configuring, so we run the job
node.run().catch(err => {
const title = "Tests failed for Test app";
const msg = "Figure out how to display logs";
slack = slackNotify("danger", title, msg, e);
slack.run();
});
});

var count = 0;

function slackNotify(state, title, msg, e) {
const slack = new Job(
`slack-notify-${count}`,
"technosophos/slack-notify:latest"
);
slack.env = {
SLACK_WEBHOOK:
"https://hooks.slack.com/services/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",
SLACK_USERNAME: "Sandeep",
SLACK_TITLE: "Build Failed",
SLACK_MESSAGE: "Build failed for this pull request",
SLACK_COLOR: state
};
count++;
return slack;
}
1 change: 1 addition & 0 deletions app/node-app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib')
1 change: 1 addition & 0 deletions app/node-app/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./webpage')
15 changes: 15 additions & 0 deletions app/node-app/lib/test-setup.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const sinon = require('sinon')
const chai = require('chai')
const sinonChai = require('sinon-chai')

before(function () {
chai.use(sinonChai)
})

beforeEach(function () {
this.sandbox = sinon.sandbox.create()
})

afterEach(function () {
this.sandbox.restore()
})
38 changes: 38 additions & 0 deletions app/node-app/lib/webpage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict'

const fs = require('fs')
const request = require('request')

function getWebpage (url) {
return new Promise (function (resolve, reject) {
request.get(url, function (err, response, body) {
if (err) {
return reject(err)
}

resolve(body)
})
})
}

function writeFile (fileContent) {
let filePath = 'page'
return new Promise (function (resolve, reject) {
fs.writeFile(filePath, fileContent, function (err) {
if (err) {
return reject(err)
}

resolve(filePath)
})
})
}

function saveWebpage (url, filePath) {
return getWebpage(url, filePath)
.then(writeFile)
}

module.exports = {
saveWebpage
}
26 changes: 26 additions & 0 deletions app/node-app/lib/webpage.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require('fs')
const request = require('request')

const expect = require('chai').expect

const webpage = require('./webpage')

describe('The webpage module', function () {
it('saves the content', function * () {
const url = 'google.com'
const content = '<h1>title</h1>'
const writeFileStub = this.sandbox.stub(fs, 'writeFile', function (filePath, fileContent, cb) {
cb(null)
})

const requestStub = this.sandbox.stub(request, 'get', function (url, cb) {
cb(null, null, content)
})

const result = yield webpage.saveWebpage(url)

expect(writeFileStub).to.be.calledWith()
expect(requestStub).to.be.calledWith(url)
expect(result).to.eql('page')
})
})
Loading