Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added basic structure with integration and unit testing frameworks in…

… place
  • Loading branch information...
commit 19dfdca3db4f2b1897dc32616484aea405f2b929 1 parent b74789a
Ed Bosher authored
5 .gitignore
View
@@ -0,0 +1,5 @@
+.idea/
+app.json
+config.yml
+*.pem
+certrequest.csr
22 examples/connect/server.js
View
@@ -0,0 +1,22 @@
+var crypto = require('crypto'),
+ fs = require('fs'),
+ connect = require('connect');
+
+var echo = require('echo'),
+ backplane = echo.backplane;
+
+var port = 8001;
+
+var privateKey = fs.readFileSync('privatekey.pem').toString(),
+ certificate = fs.readFileSync('certificate.pem').toString();
+
+var credentials = crypto.createCredentials({key: privateKey, cert: certificate});
+
+var server = module.exports = connect.createServer(
+ connect.logger(),
+ backplane.connect()
+);
+
+server.setSecure(credentials);
+server.listen(port);
+console.log("Listening on port: " + port);
14 features/channel.feature
View
@@ -0,0 +1,14 @@
+Feature: Backplane channel implementation (http://backplanespec.googlegroups.com/web/backplane-20101101.pdf?hl=en)
+ In order to allow communication between javascript clients and server applications
+ As a javascript widget server
+ I want to securely post messages and anonymously consume messages on a randomly generated channel
+
+ Scenario: Post a message
+ Given the api key "valid_key"
+ When I post a valid message to a random channel
+ Then I should receive an HTTP Response code of "200"
+
+ Scenario: Use an invalid key
+ Given the api key "invalid_key"
+ When I post a valid message to a random channel
+ Then I should receive response code "401" with message "Wrong username and/or password"
4 features/config.yml.sample
View
@@ -0,0 +1,4 @@
+base_url: 'http://testserver:port'
+valid_info:
+ bus: 'some valid bus name'
+ key: 'some valid key'
0  features/step_definitions/channel_steps.rb
View
No changes.
16 features/step_definitions/my_steps.rb
View
@@ -0,0 +1,16 @@
+And /^the api key "(.*)"$/ do |api_key|
+
+end
+
+When /^I post a valid message to a random channel$/ do
+ @response = RestClient.post @defaults.get_valid_bus(@uuid.generate), { 'x' => 1 }.to_json, :Authentication => @defaults.get_valid_auth_header(), :content_type => :json
+end
+
+Then /^I should receive an HTTP Response code of "(\d+)"$/ do |expected_response|
+ @response.code.to_s().should == expected_response
+end
+
+Then /^I should receive response code "(\d+)" with message "([^"]*)"$/ do |expected_response,expected_message|
+ Then "I should receive an HTTP Response code of \"" + expected_response + "\""
+ @response.message.to_s().should == expected_message
+end
18 features/support/defaults.rb
View
@@ -0,0 +1,18 @@
+class Defaults
+ def initialize(config)
+ @config = config
+ @valid_info = @config['valid_info']
+ end
+
+ def get_valid_bus(channel)
+ @config['base_url'] + '/' + @config['backplane']['version'] + '/' + @valid_info['bus'] + '/channel/' + channel
+ end
+
+ def get_valid_token()
+ @config['valid_info']['key']
+ end
+
+ def get_valid_auth_header()
+ 'Basic ' + Base64.encode64(@valid_info['bus'] + ':' + @valid_info['key'])
+ end
+end
20 features/support/env.rb
View
@@ -0,0 +1,20 @@
+require 'rspec/expectations'
+require 'rest_client'
+require 'uuid'
+require 'json'
+require 'base64'
+
+
+# "before all"
+# How do we make this path anchored at some sort of root, so that 'cucumber' doesn't have to be instantiated
+# relative to this path?
+config = YAML.load_file "features/config.yml"
+Before do
+ @config = config
+ @defaults = Defaults.new(config)
+ @uuid = UUID.new
+end
+
+# "after all"
+at_exit do
+end
6 lib/backplane.js
View
@@ -0,0 +1,6 @@
+exports.connect = function(){
+ return function(req,res,next) {
+ res.writeHead(200, {"Content-Type": "text/plain"});
+ res.end("Hello Connect");
+ }
+};
1  lib/index.js
View
@@ -0,0 +1 @@
+exports.backplane = require('./backplane.js');
15 package.json
View
@@ -0,0 +1,15 @@
+{
+ "name": "echo",
+ "description": "Echo library for node",
+ "version": "0.0.0",
+ "author": "TikiBooth Limited",
+ "contributors": [
+ { "name": "Ed Bosher", "email": "ed@butter.com.hk" }
+ ],
+ "directories": {
+ "lib": "./lib/"
+ },
+ "engines": {
+ "node": "0.2.6"
+ }
+}
17 spec/test.js
View
@@ -0,0 +1,17 @@
+describe('jasmine-node-flat', function(){
+ it('should pass', function(){
+ expect(1+2).toEqual(3);
+ });
+
+ it('should fail', function(){
+ expect(3*3).toEqual(6);
+ });
+
+});
+
+describe('jasmine-node-more', function(){
+ it('should pass', function(){
+ expect(1+2).toEqual(3);
+ });
+
+});
22 specs.js
View
@@ -0,0 +1,22 @@
+require.paths.push("./lib");
+var jasmine = require('jasmine-node');
+var sys = require('sys');
+
+for(var key in jasmine) {
+ global[key] = jasmine[key];
+}
+
+var isVerbose = false;
+var showColors = true;
+process.argv.forEach(function(arg){
+ switch(arg) {
+ case '--color': showColors = true; break;
+ case '--noColor': showColors = false; break;
+ case '--verbose': isVerbose = true; break;
+ }
+});
+
+
+jasmine.executeSpecsInFolder(__dirname + '/spec', function(runner, log){
+ process.exit(runner.results().failedCount);
+}, isVerbose, showColors);
Please sign in to comment.
Something went wrong with that request. Please try again.