PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/test/convenience-error.js

https://github.com/zippo445/nodegit
JavaScript | 85 lines | 64 code | 6 blank | 15 comment | 0 complexity | f0b4b816d555fc5b80ea5fca9f15b611 MD5 | raw file
Possible License(s): AGPL-3.0
  1. var git = require('../'),
  2. rimraf = require('rimraf'),
  3. fs = require( 'fs' );
  4. // Helper functions
  5. var helper = {
  6. // Test if obj is a true function
  7. testFunction: function(test, obj, label) {
  8. // The object reports itself as a function
  9. test(typeof obj, 'function', label + ' reports as a function.');
  10. // This ensures the repo is actually a derivative of the Function [[Class]]
  11. test(toString.call(obj), '[object Function]', label + ' [[Class]] is of type function.');
  12. },
  13. // Test code and handle exception thrown
  14. testException: function(test, fun, label) {
  15. try {
  16. fun();
  17. test(false, label);
  18. }
  19. catch (ex) {
  20. test(true, label);
  21. }
  22. }
  23. };
  24. /**
  25. * Test that the error object is present.
  26. *
  27. * @param {Object} test
  28. */
  29. exports.method = function(test){
  30. test.expect(2);
  31. helper.testFunction(test.equals, git.error, 'Error');
  32. test.done();
  33. };
  34. exports.codes = function(test) {
  35. test.expect(14);
  36. var error = new git.error();
  37. test.equal(error.codes.GITERR_NOMEMORY, git.raw.Error.codes.GITERR_NOMEMORY, 'GITERR_NOMEMORY code should match expected value');
  38. test.equal(error.codes.GITERR_OS, git.raw.Error.codes.GITERR_OS, 'GITERR_OS code should match expected value');
  39. test.equal(error.codes.GITERR_INVALID, git.raw.Error.codes.GITERR_INVALID, 'GITERR_INVALID code should match expected value');
  40. test.equal(error.codes.GITERR_REFERENCE, git.raw.Error.codes.GITERR_REFERENCE, 'GITERR_REFERENCE code should match expected value');
  41. test.equal(error.codes.GITERR_ZLIB, git.raw.Error.codes.GITERR_ZLIB, 'GITERR_ZLIB code should match expected value');
  42. test.equal(error.codes.GITERR_REPOSITORY, git.raw.Error.codes.GITERR_REPOSITORY, 'GITERR_REPOSITORY code should match expected value');
  43. test.equal(error.codes.GITERR_CONFIG, git.raw.Error.codes.GITERR_CONFIG, 'GITERR_CONFIG code should match expected value');
  44. test.equal(error.codes.GITERR_REGEX, git.raw.Error.codes.GITERR_REGEX, 'GITERR_REGEX code should match expected value');
  45. test.equal(error.codes.GITERR_ODB, git.raw.Error.codes.GITERR_ODB, 'GITERR_ODB code should match expected value');
  46. test.equal(error.codes.GITERR_INDEX, git.raw.Error.codes.GITERR_INDEX, 'GITERR_INDEX code should match expected value');
  47. test.equal(error.codes.GITERR_OBJECT, git.raw.Error.codes.GITERR_OBJECT, 'GITERR_OBJECT code should match expected value');
  48. test.equal(error.codes.GITERR_NET, git.raw.Error.codes.GITERR_NET, 'GITERR_NET code should match expected value');
  49. test.equal(error.codes.GITERR_TAG, git.raw.Error.codes.GITERR_TAG, 'GITERR_TAG code should match expected value');
  50. test.equal(error.codes.GITERR_TREE, git.raw.Error.codes.GITERR_TREE, 'GITERR_TREE code should match expected value');
  51. test.done();
  52. };
  53. exports.returnCodes = function(test) {
  54. test.expect(8);
  55. var error = new git.error();
  56. test.equal(error.returnCodes.GIT_OK, git.raw.Error.returnCodes.GIT_OK, 'GIT_OK return code should match expected value');
  57. test.equal(error.returnCodes.GIT_ERROR, git.raw.Error.returnCodes.GIT_ERROR, 'GIT_ERROR return code should match expected value');
  58. test.equal(error.returnCodes.GIT_ENOTFOUND, git.raw.Error.returnCodes.GIT_ENOTFOUND, 'GIT_ENOTFOUND return code should match expected value');
  59. test.equal(error.returnCodes.GIT_EEXISTS, git.raw.Error.returnCodes.GIT_EEXISTS, 'GIT_EEXISTS return code should match expected value');
  60. test.equal(error.returnCodes.GIT_EAMBIGUOUS, git.raw.Error.returnCodes.GIT_EAMBIGUOUS, 'GIT_EAMBIGUOUS return code should match expected value');
  61. test.equal(error.returnCodes.GIT_EBUFS, git.raw.Error.returnCodes.GIT_EBUFS, 'GIT_EBUFS return code should match expected value');
  62. test.equal(error.returnCodes.GIT_PASSTHROUGH, git.raw.Error.returnCodes.GIT_PASSTHROUGH, 'GIT_PASSTHROUGH return code should match expected value');
  63. test.equal(error.returnCodes.GIT_ITEROVER, git.raw.Error.returnCodes.GIT_ITEROVER, 'GIT_ITEROVER return code should match expected value');
  64. test.done();
  65. };
  66. /**
  67. * Test that
  68. *
  69. * @param {Object} test
  70. */
  71. exports.improperCommitId = function(test) {
  72. test.expect(1);
  73. git.repo('../.git', function(error, repository) {
  74. repository.commit('not a proper commit sha', function(error, commit) {
  75. test.notEqual(error.code, git.error.GIT_SUCCESS, 'Attempting to get commit by invalid SHA should error');
  76. test.done();
  77. });
  78. });
  79. };