chris-l / mock-couch

A node.js module designed to mock a CouchDB server, mostly for unit testing purposes.
http://chris-l.github.io/mock-couch/
67 stars 44 forks source link

Adding support for GET _uuids #28

Closed watchforstock closed 9 years ago

watchforstock commented 9 years ago

I needed support for the _uuids command so have added it here. Instead of generating full UUIDs as per couch, it's just generating integers. For my use case this allows the ID of the generated items to be predicted and therefore checked in the tests.

chris-l commented 9 years ago

Hi! I merged your pull request, however, I didn't like how it deviated from the standard behavior of Couchdb. But I do recognize how having predictable results is useful during tests.

Now, Couchdb has the sequential algorithm, which is somehow similar to what you tried to do. The big difference would be in the fact that algorithm produces unpredictable results (each value is increased by a random amount)

So what I did is the following: Each number is prefixed by a string (by default is 4e17c12963f4bee0e6ec90da54) and then the number produced in the for loop, prefixed with zeros.

The result looks like this:

{
 "uuids": [
  "4e17c12963f4bee0e6ec90da54000000",
  "4e17c12963f4bee0e6ec90da54000001",
  "4e17c12963f4bee0e6ec90da54000002",
  "4e17c12963f4bee0e6ec90da54000003",
  "4e17c12963f4bee0e6ec90da54000004",
  "4e17c12963f4bee0e6ec90da54000005",
  "4e17c12963f4bee0e6ec90da54000006",
  "4e17c12963f4bee0e6ec90da54000007",
  "4e17c12963f4bee0e6ec90da54000008",
  "4e17c12963f4bee0e6ec90da54000009"
 ]
}

As you can see, the numbers are on sequence which is completely predictable, and at the same time, they look similar to the ids generated by couchdb's sequential algorithm.

Later, I will document this feature on the readme.

Something you didn't add, and is quite important, was adding unit tests. Could you add at least one unit test checking this for feature, please?

Thanks a lot!

watchforstock commented 9 years ago

Thanks for merging. I'll try to sort out some tests as soon as I can.

On 9 May 2015 at 09:18, christopher luna notifications@github.com wrote:

Hi! I merged your pull request, however, I didn't like how it deviated from the standard behavior of Couchdb. But I do recognize how having predictable results is useful during tests.

Now, Couchdb has the sequential algorithm, which is somehow similar to what you tried to do. The big difference would be in the fact that algorithm produces unpredictable results (each value is increased by a random amount)

So what I did is the following: Each number is prefixed by a string (by default is 4e17c12963f4bee0e6ec90da54) and then the number produced in the for loop, prefixed with zeros.

The result looks like this:

{ "uuids": [ "4e17c12963f4bee0e6ec90da54000000", "4e17c12963f4bee0e6ec90da54000001", "4e17c12963f4bee0e6ec90da54000002", "4e17c12963f4bee0e6ec90da54000003", "4e17c12963f4bee0e6ec90da54000004", "4e17c12963f4bee0e6ec90da54000005", "4e17c12963f4bee0e6ec90da54000006", "4e17c12963f4bee0e6ec90da54000007", "4e17c12963f4bee0e6ec90da54000008", "4e17c12963f4bee0e6ec90da54000009" ] }

As you can see, the numbers are on sequence which is completely predictable, and at the same time, they look similar to the ids generated by couchdb's sequential algorithm.

Later, I will document this feature on the readme.

Something you didn't add, and is quite important, was adding unit tests. Could you add at least one unit test checking this for feature, please?

Thanks a lot!

— Reply to this email directly or view it on GitHub https://github.com/chris-l/mock-couch/pull/28#issuecomment-100446989.