From 95952830ba5a66fea2981fad50ffb56576474f3e Mon Sep 17 00:00:00 2001 From: Serene Han Date: Mon, 11 Jan 2016 10:30:49 -0800 Subject: [PATCH] begin snowflake coffee tests and Cakefile --- proxy/Cakefile | 8 ++++ proxy/README.md | 11 +++++ proxy/snowflake_test.coffee | 80 +++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 proxy/Cakefile create mode 100644 proxy/README.md create mode 100644 proxy/snowflake_test.coffee diff --git a/proxy/Cakefile b/proxy/Cakefile new file mode 100644 index 0000000..de1982d --- /dev/null +++ b/proxy/Cakefile @@ -0,0 +1,8 @@ +fs = require 'fs' + +{exec} = require 'child_process' + +task 'test', 'test snowflake.coffee', () -> + exec 'coffee snowflake_test.coffee -v', (err, stdout, stderr) -> + throw err if err + console.log stdout + stderr diff --git a/proxy/README.md b/proxy/README.md new file mode 100644 index 0000000..36c2e9c --- /dev/null +++ b/proxy/README.md @@ -0,0 +1,11 @@ +This is the browser proxy component of Snowflake. + +### Testing: + +Unit tests are available with: +``` +cake test +``` + +To run locally, start a webserver and navigate to `snowflake.html`. + diff --git a/proxy/snowflake_test.coffee b/proxy/snowflake_test.coffee new file mode 100644 index 0000000..9db56b3 --- /dev/null +++ b/proxy/snowflake_test.coffee @@ -0,0 +1,80 @@ +s = require './snowflake' + +VERBOSE = false +if process.argv.indexOf("-v") >= 0 + VERBOSE = true +numTests = 0 +numFailed = 0 + +announce = (testName) -> + if VERBOSE + # if (!top) + # console.log(); + console.log testName + # top = false + +pass = (test) -> + numTests++; + if VERBOSE + console.log "PASS " + test + +fail = (test, expected, actual) -> + numTests++ + numFailed++ + console.log "FAIL " + test + " expected: " + expected + " actual: " + actual + + +testBuildUrl = -> + TESTS = [{ + args: ["http", "example.com"] + expected: "http://example.com" + },{ + args: ["http", "example.com", 80] + expected: "http://example.com" + },{ + args: ["http", "example.com", 81], + expected: "http://example.com:81" + },{ + args: ["https", "example.com", 443] + expected: "https://example.com" + },{ + args: ["https", "example.com", 444] + expected: "https://example.com:444" + },{ + args: ["http", "example.com", 80, "/"] + expected: "http://example.com/" + },{ + args: ["http", "example.com", 80, "/test?k=%#v"] + expected: "http://example.com/test%3Fk%3D%25%23v" + },{ + args: ["http", "example.com", 80, "/test", []] + expected: "http://example.com/test?" + },{ + args: ["http", "example.com", 80, "/test", [["k", "%#v"]]] + expected: "http://example.com/test?k=%25%23v" + },{ + args: ["http", "example.com", 80, "/test", [["a", "b"], ["c", "d"]]] + expected: "http://example.com/test?a=b&c=d" + },{ + args: ["http", "1.2.3.4"] + expected: "http://1.2.3.4" + },{ + args: ["http", "1:2::3:4"] + expected: "http://[1:2::3:4]" + },{ + args: ["http", "bog][us"] + expected: "http://bog%5D%5Bus" + },{ + args: ["http", "bog:u]s"] + expected: "http://bog%3Au%5Ds" + } + ] + announce "-- testBuildUrl --" + for test in TESTS + actual = s.buildUrl.apply undefined, test.args + if actual == test.expected + pass test.args + else + fail test.args, test.expected, actual + +testBuildUrl()