Skip to content
This repository
Browse code

Add test for error value returned from add when value already exists

  • Loading branch information...
commit 9e597f8aaca0f1e745f51b39579c05b43658c8ae 1 parent fb4d8cb
privman authored October 16, 2012

Showing 1 changed file with 45 additions and 0 deletions. Show diff stats Hide diff stats

  1. 45  tests/memcached-add.test.js
45  tests/memcached-add.test.js
... ...
@@ -0,0 +1,45 @@
  1
+/**
  2
+ * Test dependencies
  3
+ */
  4
+
  5
+var assert = require('assert')
  6
+  , fs = require('fs')
  7
+  , common = require('./common')
  8
+  , Memcached = require('../');
  9
+
  10
+global.testnumbers = global.testnumbers || +(Math.random(10) * 1000000).toFixed();
  11
+
  12
+/**
  13
+ * Expresso test suite for all `add` related
  14
+ * memcached commands
  15
+ */
  16
+describe("Memcached ADD", function() {
  17
+  /**
  18
+   * Make sure that adding a key which already exists returns an error.
  19
+   */
  20
+  it("fail to add an already existing key", function(done) {
  21
+    var memcached = new Memcached(common.servers.single)
  22
+        , message = common.alphabet(256)
  23
+        , testnr = ++global.testnumbers
  24
+        , callbacks = 0;
  25
+
  26
+      memcached.set("test:" + testnr, message, 1000, function(error, ok){
  27
+        ++callbacks;
  28
+
  29
+        assert.ok(!error);
  30
+        ok.should.be.true;
  31
+
  32
+        memcached.add("test:" + testnr, message, 1000, function(error, answer){
  33
+          ++callbacks;
  34
+
  35
+          assert.ok(error);
  36
+
  37
+          memcached.end(); // close connections
  38
+          assert.equal(callbacks, 2);
  39
+          done();
  40
+
  41
+        });
  42
+      });
  43
+  });
  44
+
  45
+});

0 notes on commit 9e597f8

Please sign in to comment.
Something went wrong with that request. Please try again.