Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Work on no caching expectation.

  • Loading branch information...
commit 4a45199c65dafc95d97c4cb5cd4c8639ad0d2be1 1 parent 4c340ce
@colin-jack authored
View
7 index.js
@@ -1,6 +1,3 @@
-// global within the module
-lib = require('./lib/namespace');
+global.testResourcesLib = require('./lib/namespace');
-var entryPointCreator = require('./lib/entryPointCreator');
-
-module.exports = entryPointCreator;
+module.exports = require('./lib/entryPointCreator');
View
2  lib/expectation/cacheForeverExpectation.js
@@ -9,7 +9,7 @@ var cacheForeverExpectation = function(where, response) {
var assertCachedForLongTime = function assertCachedForLongTime(cacheControlHeader) {
var tenYearsInSeconds = 10 * 365 * 24 * 60 * 60;
- var maxAgeRegex = new RegExp("max-age=(.*)(,|^)");
+ var maxAgeRegex = new RegExp("max-age=([0-9]+)");
var match = cacheControlHeader.match(maxAgeRegex);
View
15 lib/expectation/noCacheExpectation.js
@@ -1,15 +0,0 @@
-var format = require('util').format;
-
-var expectCached = function(response) {
- var noCachingRegex = /(.*no-cache.*)/
-
- // TODO - Also check Expires to keep HTTP 1.0 caches happy
- if (response.headers['cache-control'].match(noCachingRegex) === null) {
- var message = format("The cache-control value '%s' should have matched '%s'",
- response.headers['cache-control'],
- regexString);
- throw new Error(message)
- }
-};
-
-module.exports = expectCached;
View
17 lib/expectation/notCachedExpectation.js
@@ -1,18 +1,15 @@
var format = require('util').format;
-var notCachedExpectation = function(response) {
- // TODO: no-cache, no-store
- // TODO: Pragma: no-cache
- var maxAge = "max-age=" + (minutes * 60);
- var regexString = "(.*" + maxAge + ".*" + where +".*)|(.*" + where + ".*" + maxAge + ".*)";
-
- var cachingRegex = new RegExp(regexString);
+var expectCached = function(response) {
+ var noCachingRegex = /(.*no-cache.*)/
// TODO - Also check Expires to keep HTTP 1.0 caches happy
- if (response.headers['cache-control'].match(cachingRegex) === null) {
- var message = format("The cache-control value '%s' should have matched '%s'", response.headers['cache-control'], regexString);
+ if (response.headers['cache-control'].match(noCachingRegex) === null) {
+ var message = format("The cache-control value '%s' should have matched '%s'",
+ response.headers['cache-control'],
+ regexString);
throw new Error(message)
}
};
-module.exports = notCachedExpectation
+module.exports = expectCached;
View
33 lib/fluent/createGetChain.js
@@ -1,26 +1,30 @@
-var cacheExpectation = lib.require('cacheExpectation'),
+var cacheExpectation = testResourcesLib.require('cacheExpectation'),
sharedFluentInterface = require('./sharedFluentInterface'),
- noCacheExpectation = lib.require('noCacheExpectation'),
+ notCachedExpectation = testResourcesLib.require('notCachedExpectation'),
sendRequestAndAssertOnResponse = require('./sendRequestAndAssertOnResponse'),
- cacheForeverExpectation = lib.require('cacheForeverExpectation'),
- notCachedExpectation = lib.require('notCachedExpectation');
+ cacheForeverExpectation = testResourcesLib.require('cacheForeverExpectation'),
+ notCachedExpectation = testResourcesLib.require('notCachedExpectation'),
+ ensure = require('rules').ensure;
var run = function(allDone) {
sendRequestAndAssertOnResponse(this, allDone);
}
+var registerChildChain = function registerChildChain(childChain) {
+ this.childChain = childChain;
+}
+
var expectNotCached = function expectNotCached() {
this.expectations.caching = function(response) {
- noCacheExpectation(response);
+ notCachedExpectation(response);
}
return this;
};
-var registerChildChain = function registerChildChain(childChain) {
- this.childChain = childChain;
-}
-
var expectCached = function expectCached(where, minutes) {
+ //ensure(where).populated().string();
+ //ensure(minutes).populated().numeric();
+
this.expectations.caching = function(response) {
cacheExpectation(where, minutes, response);
}
@@ -29,6 +33,9 @@ var expectCached = function expectCached(where, minutes) {
};
var expectCachedForever = function expectCached(where) {
+ // TODO: Validate where against enum.
+ //ensure(where).populated().string();
+
this.expectations.caching = function(response) {
cacheForeverExpectation(where, response);
}
@@ -36,14 +43,6 @@ var expectCachedForever = function expectCached(where) {
return this;
};
-var expectNotCached = function expectNotCached() {
- this.expectations.caching = function(response) {
- notCachedExpectation(where, response);
- }
-
- return this;
-}
-
var followLink = function followLink(linkRel) {
var createFollowLinkChain = require('./createFollowLinkChain');
View
2  lib/fluent/sendRequestAndAssertOnResponse.js
@@ -37,7 +37,7 @@ var processResponse = function(response, requestChain, allDone) {
else
{
requestChain.wrapper.closeExpress();
- winston.info("Running expectations for" + response.req.path);
+ winston.info("Running expectations for " + response.req.path);
assert(requestChain.expectations, requestChain.wrapper, response)
allDone();
}
View
2  lib/namespace.js
@@ -1,5 +1,5 @@
// Brings all the files inside this directory into a namespace called 'lib', allowing you
-// to require using lib.require('{fileName}') without having to worry about the directory
+// to require using testResourcesLib.require('{fileName}') without having to worry about the directory
// structure involved.
var requireNamespace = require('require-namespace');
module.exports = requireNamespace.createSync('lib', __dirname + "/");
View
6 spec/integration/GET/get.js
@@ -1,5 +1,5 @@
-var resource = lib.require('entryPointCreator'),
- resource = lib.require('entryPointCreator'),
+var resource = testResourcesLib.require('entryPointCreator'),
+ resource = testResourcesLib.require('entryPointCreator'),
express = require('express'),
testUtil = require('./../testUtil');
@@ -42,7 +42,7 @@ describe("get - ", function() {
it.skip('should fail if you expect it to be cached forever', function(done) {
testBuilder
- .expectCacheForever()
+ .expectCachedForever()
.run(testUtil.assertError(/The body did not match/, done));
});
View
8 spec/integration/GET/get_expectCacheForever.js
@@ -1,5 +1,5 @@
-var resource = lib.require('entryPointCreator'),
- resource = lib.require('entryPointCreator'),
+var resource = testResourcesLib.require('entryPointCreator'),
+ resource = testResourcesLib.require('entryPointCreator'),
express = require('express'),
testUtil = require('./../testUtil');
@@ -10,13 +10,13 @@ describe("get cache forever - ", function() {
beforeEach(function() {
var app = express();
- app.get('/noCache', function(req, res){
+ app.get('/cacheForever', function(req, res){
var twentyYears = 20 * 365 * 24 * 60 * 60;
res.header('Cache-Control', 'public, max-age=' + twentyYears)
res.send({ name: 'fido' });
});
- testBuilder = resource(app).get('/noCache');
+ testBuilder = resource(app).get('/cacheForever');
});
it('should pass if your expectation matches', function(done) {
View
11 spec/integration/GET/get_followLink.js
@@ -1,11 +1,11 @@
-var resource = lib.require('entryPointCreator'),
- getServerAddress = lib.require('getServerAddress'),
+var resource = testResourcesLib.require('entryPointCreator'),
+ getServerAddress = testResourcesLib.require('getServerAddress'),
express = require('express'),
testUtil = require('./../testUtil'),
http = require('http');
describe("follow link - ", function() {
- describe.skip('when you test a get request containing a link', function() {
+ describe('when you test a get request containing a link', function() {
var testBuilder, address, server;
beforeEach(function() {
@@ -23,7 +23,8 @@ describe("follow link - ", function() {
});
app.get('/address', function(req, res) {
- res.header('Cache-Control', 'no-cache')
+ var twentyYears = 20 * 365 * 24 * 60 * 60;
+ res.header('Cache-Control', 'public, max-age=' + twentyYears)
res.json(address);
});
@@ -36,7 +37,7 @@ describe("follow link - ", function() {
.expectNotCached()
.followLink("address")
.expectBody(address)
- .expectCacheForever("publically")
+ .expectCachedForever("public")
.endLink()
.run(testUtil.assertNoError(done));
});
View
5 spec/integration/GET/get_noCache.js
@@ -1,5 +1,5 @@
-var resource = lib.require('entryPointCreator'),
- resource = lib.require('entryPointCreator'),
+var resource = testResourcesLib.require('entryPointCreator'),
+ resource = testResourcesLib.require('entryPointCreator'),
express = require('express'),
testUtil = require('./../testUtil');
@@ -19,6 +19,7 @@ describe("get no cache - ", function() {
});
it('should pass if your expectations are correct', function(done) {
+ debugger;
testBuilder
.expectNotCached()
.run(testUtil.assertNoError(done));
View
2  spec/integration/put_spec.js
@@ -1,4 +1,4 @@
-var resource = lib.require('entryPointCreator'),
+var resource = testResourcesLib.require('entryPointCreator'),
express = require('express'),
testUtil = require('./testUtil');
View
15 spec/testFixture.js
@@ -1,19 +1,14 @@
//require('longjohn')
-// global within the module
-function requireFromLib = (toRequire) {
- var lib = require('./../lib/namespace');
- lib.require(toRequire)
-}
+// Reduce coupling to the directory structure under lib so tests don't
+// break if I move files, and less need for ../../../ style paths in require
+global.testResourcesLib = require('./../lib/namespace');
-assert = require('chai').assert;
+global.assert = require('chai').assert;
var winston = require('winston');
winston.cli();
winston.info("Switching to only logging errors (testFixture.js).")
winston.level = 'error';
-// Reduce coupling to the directory structur under lib so tests don't break if I move files, and less need for ../../../ style
-// pahts in require
-var libNamespace = require('./../lib/namespace');
-module.lib = libNamespace;
+
View
6 spec/unit/cacheForeverExpecation.js
@@ -1,5 +1,5 @@
var assert = require('chai').assert,
- cacheForeverExpectation = lib.require('cacheForeverExpectation');
+ cacheForeverExpectation = testResourcesLib.require('cacheForeverExpectation');
describe("when passed a value with no max-age", function() {
it("should throw an error", function() {
@@ -24,14 +24,14 @@ describe("when passed a value with a small max-age", function() {
describe("when passed a value with a large enough max-age", function() {
it("should not throw an error", function() {
- var runExpectation = cacheForeverExpectationWrapper("public, max-age=50000000")
+ var runExpectation = cacheForeverExpectationWrapper("public, max-age=900000000")
assert.doesNotThrow(runExpectation)
});
});
describe("when passed a value with a large enough max-age and location is last", function() {
it("should not throw an error", function() {
- var runExpectation = cacheForeverExpectationWrapper("max-age=50000000, public")
+ var runExpectation = cacheForeverExpectationWrapper("max-age=900000000, public")
assert.doesNotThrow(runExpectation)
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.