Skip to content

Commit a71d62c

Browse files
committed
[codestyle] Codestyle refactor for tests
1 parent 23705de commit a71d62c

4 files changed

Lines changed: 92 additions & 86 deletions

File tree

test/memcached-add.test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
'use strict';
2+
13
/**
24
* Test dependencies
35
*/
4-
56
var assert = require('assert')
67
, fs = require('fs')
78
, common = require('./common')
@@ -13,33 +14,31 @@ global.testnumbers = global.testnumbers || +(Math.random(10) * 1000000).toFixed(
1314
* Expresso test suite for all `add` related
1415
* memcached commands
1516
*/
16-
describe("Memcached ADD", function() {
17+
describe('Memcached ADD', function () {
1718
/**
1819
* Make sure that adding a key which already exists returns an error.
1920
*/
20-
it("fail to add an already existing key", function(done) {
21+
it('fail to add an already existing key', function (done) {
2122
var memcached = new Memcached(common.servers.single)
2223
, message = common.alphabet(256)
2324
, testnr = ++global.testnumbers
2425
, callbacks = 0;
2526

26-
memcached.set("test:" + testnr, message, 1000, function(error, ok){
27+
memcached.set('test:' + testnr, message, 1000, function (error, ok) {
2728
++callbacks;
2829

2930
assert.ok(!error);
3031
ok.should.be.true;
3132

32-
memcached.add("test:" + testnr, message, 1000, function(error, answer){
33+
memcached.add('test:' + testnr, message, 1000, function (error, answer) {
3334
++callbacks;
3435

3536
assert.ok(error);
3637

3738
memcached.end(); // close connections
3839
assert.equal(callbacks, 2);
3940
done();
40-
4141
});
4242
});
4343
});
44-
4544
});

test/memcached-cas.test.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
'use strict';
2+
13
/**
24
* Test dependencies
35
*/
4-
56
var assert = require('assert')
67
, common = require('./common')
78
, Memcached = require('../');
@@ -12,32 +13,32 @@ global.testnumbers = global.testnumbers || +(Math.random(10) * 1000000).toFixed(
1213
* Expresso test suite for all `get` related
1314
* memcached commands
1415
*/
15-
describe("Memcached CAS", function() {
16+
describe('Memcached CAS', function () {
1617
/**
1718
* For a proper CAS update in memcached you will need to know the CAS value
1819
* of a given key, this is done by the `gets` command. So we will need to make
1920
* sure that a `cas` key is given.
2021
*/
21-
it("set and gets for cas result", function(done) {
22+
it('set and gets for cas result', function (done) {
2223
var memcached = new Memcached(common.servers.single)
2324
, message = common.alphabet(256)
2425
, testnr = ++global.testnumbers
2526
, callbacks = 0;
2627

27-
memcached.set("test:" + testnr, message, 1000, function(error, ok){
28+
memcached.set('test:' + testnr, message, 1000, function (error, ok) {
2829
++callbacks;
2930

3031
assert.ok(!error);
3132
ok.should.be.true;
3233

33-
memcached.gets("test:" + testnr, function(error, answer){
34+
memcached.gets('test:' + testnr, function (error, answer) {
3435
++callbacks;
3536

3637
assert.ok(!error);
3738

3839
assert.ok(typeof answer === 'object');
3940
assert.ok(!!answer.cas);
40-
answer["test:" + testnr].should.eql(message);
41+
answer['test:' + testnr].should.eql(message);
4142

4243
memcached.end(); // close connections
4344
assert.equal(callbacks, 2);
@@ -49,30 +50,30 @@ describe("Memcached CAS", function() {
4950
/**
5051
* Create a successful cas update, so we are sure we send a cas request correctly.
5152
*/
52-
it("successful cas update", function(done) {
53+
it('successful cas update', function(done) {
5354
var memcached = new Memcached(common.servers.single)
5455
, message = common.alphabet(256)
5556
, testnr = ++global.testnumbers
5657
, callbacks = 0;
5758

58-
memcached.set("test:" + testnr, message, 1000, function(error, ok){
59+
memcached.set('test:' + testnr, message, 1000, function (error, ok) {
5960
++callbacks;
6061
assert.ok(!error);
6162
ok.should.be.true;
6263

63-
memcached.gets("test:" + testnr, function(error, answer){
64+
memcached.gets('test:' + testnr, function (error, answer) {
6465
++callbacks;
6566
assert.ok(!error);
6667
assert.ok(!!answer.cas);
6768

6869
// generate new message for the cas update
6970
message = common.alphabet(256);
70-
memcached.cas("test:" + testnr, message, answer.cas, 1000, function(error, answer){
71+
memcached.cas('test:' + testnr, message, answer.cas, 1000, function (error, answer) {
7172
++callbacks;
7273
assert.ok(!error);
7374
assert.ok(!!answer);
7475

75-
memcached.get("test:" + testnr, function(error, answer){
76+
memcached.get('test:' + testnr, function (error, answer) {
7677
++callbacks;
7778

7879
assert.ok(!error);
@@ -81,7 +82,7 @@ describe("Memcached CAS", function() {
8182
memcached.end(); // close connections
8283
assert.equal(callbacks, 4);
8384
done();
84-
})
85+
});
8586
});
8687
});
8788
});
@@ -91,33 +92,33 @@ describe("Memcached CAS", function() {
9192
* Create a unsuccessful cas update, which would indicate that the server has changed
9293
* while we where doing nothing.
9394
*/
94-
it("unsuccessful cas update", function(done) {
95+
it('unsuccessful cas update', function (done) {
9596
var memcached = new Memcached(common.servers.single)
9697
, message = common.alphabet(256)
9798
, testnr = ++global.testnumbers
9899
, callbacks = 0;
99100

100-
memcached.set("test:" + testnr, message, 1000, function(error, ok){
101+
memcached.set('test:' + testnr, message, 1000, function (error, ok) {
101102
++callbacks;
102103
assert.ok(!error);
103104
ok.should.be.true;
104105

105-
memcached.gets("test:" + testnr, function(error, answer){
106+
memcached.gets('test:' + testnr, function (error, answer) {
106107
++callbacks;
107108
assert.ok(!error);
108109
assert.ok(!!answer.cas);
109110

110111
// generate new message
111112
message = common.alphabet(256);
112-
memcached.set("test:" + testnr, message, 1000, function(){
113+
memcached.set('test:' + testnr, message, 1000, function () {
113114
++callbacks;
114115

115-
memcached.cas("test:" + testnr, message, answer.cas, 1000, function(error, answer){
116+
memcached.cas('test:' + testnr, message, answer.cas, 1000, function (error, answer) {
116117
++callbacks;
117118
assert.ok(!error);
118119
assert.ok(!answer);
119120

120-
memcached.get("test:" + testnr, function(error, answer){
121+
memcached.get('test:' + testnr, function (error, answer) {
121122
++callbacks;
122123

123124
assert.ok(!error);

test/memcached-namespace.test.js

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
'use strict';
2+
13
/**
24
* Test dependencies
35
*/
4-
56
var assert = require('assert')
67
, fs = require('fs')
78
, common = require('./common')
@@ -13,50 +14,53 @@ global.testnumbers = global.testnumbers || +(Math.random(10) * 1000000).toFixed(
1314
* Expresso test suite for all `get` related
1415
* memcached commands
1516
*/
16-
describe("Memcached tests with Namespaces", function() {
17+
describe('Memcached tests with Namespaces', function () {
1718
/**
1819
* Make sure that the string that we send to the server is correctly
1920
* stored and retrieved. We will be storing random strings to ensure
2021
* that we are not retrieving old data.
2122
*/
22-
it("set with one namespace and verify it can't be read in another", function(done) {
23+
it("set with one namespace and verify it can't be read in another", function (done) {
2324
var memcached = new Memcached(common.servers.single)
2425
, message = common.alphabet(256)
2526
, testnr = ++global.testnumbers
2627
, callbacks = 0;
2728

2829
// Load an non-namespaced entry to memcached
29-
memcached.set("test:" + testnr, message, 1000, function(error, ok){
30+
memcached.set('test:' + testnr, message, 1000, function (error, ok) {
3031
++callbacks;
3132

3233
assert.ok(!error);
3334
ok.should.be.true;
3435

35-
var memcachedOther = new Memcached(common.servers.single, {namespace: 'mySegmentedMemcached:'});
36+
var memcachedOther = new Memcached(common.servers.single, {
37+
namespace: 'mySegmentedMemcached:'
38+
});
39+
3640
// Try to load that memcache key with the namespace prepended - this should fail
37-
memcachedOther.get("test:" + testnr, function(error, answer){
41+
memcachedOther.get('test:' + testnr, function (error, answer) {
3842
++callbacks;
39-
43+
4044
assert.ok(!error);
4145
ok.should.be.true;
4246
answer.should.be.false;
43-
47+
4448
// OK, now let's put it in with the namespace prepended
45-
memcachedOther.set("test:" + testnr, message, 1000, function(error, ok){
49+
memcachedOther.set('test:' + testnr, message, 1000, function (error, ok) {
4650
++callbacks;
47-
51+
4852
assert.ok(!error);
4953
ok.should.be.true;
50-
54+
5155
// Now when we request it back, it should be there
52-
memcachedOther.get("test:" + testnr, function(error, answer){
56+
memcachedOther.get('test:' + testnr, function (error, answer) {
5357
++callbacks;
54-
58+
5559
assert.ok(!error);
56-
60+
5761
assert.ok(typeof answer === 'string');
5862
answer.should.eql(message);
59-
63+
6064
memcachedOther.end(); // close connections
6165
assert.equal(callbacks, 4);
6266
done();
@@ -65,31 +69,33 @@ describe("Memcached tests with Namespaces", function() {
6569
});
6670
});
6771
});
68-
69-
it("set, set, and multiget with custom namespace", function(done) {
70-
var memcached = new Memcached(common.servers.single, {namespace: 'mySegmentedMemcached:'})
71-
, callbacks = 0;
72-
72+
73+
it('set, set, and multiget with custom namespace', function (done) {
74+
var memcached = new Memcached(common.servers.single, {
75+
namespace: 'mySegmentedMemcached:'
76+
})
77+
, callbacks = 0;
78+
7379
// Load two namespaced variables into memcached
74-
memcached.set("test1", "test1answer", 1000, function(error, ok){
80+
memcached.set('test1', 'test1answer', 1000, function (error, ok) {
7581
++callbacks;
76-
82+
7783
assert.ok(!error);
7884
ok.should.be.true;
79-
80-
memcached.set("test2", "test2answer", 1000, function(error, ok){
85+
86+
memcached.set('test2', 'test2answer', 1000, function (error, ok) {
8187
++callbacks;
82-
88+
8389
assert.ok(!error);
8490
ok.should.be.true;
85-
86-
memcached.get(["test1", "test2"], function(error, answer){
91+
92+
memcached.get(['test1', 'test2'], function (error, answer) {
8793
++callbacks;
88-
94+
8995
assert.ok(typeof answer === 'object');
90-
answer["test1"].should.eql("test1answer");
91-
answer["test2"].should.eql("test2answer");
92-
96+
answer.test1.should.eql('test1answer');
97+
answer.test2.should.eql('test2answer');
98+
9399
memcached.end(); // close connections
94100

95101
assert.equal(callbacks, 3);

0 commit comments

Comments
 (0)