Skip to content

Commit

Permalink
Merge pull request #4 from codefresh-io/CF-2504
Browse files Browse the repository at this point in the history
add ability to mark an error as a recognized error
  • Loading branch information
itai-codefresh committed Jul 26, 2016
2 parents 903a536 + c7bce1d commit 03b9874
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
25 changes: 25 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,31 @@ class CFError extends WError {
return CFError.errorCodes[this.name];
}

recognize() {
this.recognized = "true";
}

deRecognize() {
this.recognized = "false";
}

isRecognized() {
if (this.recognized === "false"){
return false;
}
else if (this.recognized === "true"){
return true;
}
else if (this.we_cause && this.we_cause.message){
return this.we_cause.isRecognized();
}
else {
return false;
}
}



}

CFError.errorTypes = {
Expand Down
70 changes: 70 additions & 0 deletions test.unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,74 @@ describe('CFErrors tests', function () {
expect(error).to.exists; // jshint ignore:line
});

describe('recognize tests', function(){

describe('positive - should return true', function(){

it('should recognize in case there is only 1 CFError in the chain', function(){
var error = new CFError(ErrorTypes.Error, "my error");
error.recognize();
expect(error.isRecognized()).to.equal(true);
});

it('should recognize in case recognize was called and then deRecognized and then recognized again on the same error', function(){
var error = new CFError(ErrorTypes.Error, "my error");
error.recognize();
error.deRecognize();
error.recognize();
expect(error.isRecognized()).to.equal(true);
});

it('should recognize in case a previous error deRecognized and the recent one recognized', function(){
var error = new CFError(ErrorTypes.Error, "my error");
error.deRecognize();
var error2 = new CFError(ErrorTypes.Inherit, error, "extend error");
error2.recognize();
expect(error2.isRecognized()).to.equal(true);
});

it('should recognize in case previous error recognized and the recent one did not do anything', function(){
var error = new CFError(ErrorTypes.Error, "my error");
error.recognize();
var error2 = new CFError(ErrorTypes.Inherit, error, "extend error");
expect(error2.isRecognized()).to.equal(true);
});

});

describe('negative', function(){

it('should not recognize in case there is only 1 CFError in the chain and recognize function was not called', function(){
var error = new CFError(ErrorTypes.Error, "my error");
expect(error.isRecognized()).to.equal(false);
});

it('should not recognize in case a higher error have deRecognized after a previous error recognized', function(){
var error = new CFError(ErrorTypes.Error, "my error");
error.recognize();
var error2 = new CFError(ErrorTypes.Error, error, "extended error");
error2.deRecognize();
expect(error2.isRecognized()).to.equal(false);
});

it('should not recognize in case recognized was called and then deRecognized was called on the same error', function(){
var error = new CFError(ErrorTypes.Error, "my error");
error.recognize();
error.deRecognize();
expect(error.isRecognized()).to.equal(false);
});

it('should not recognize in case recognized was called and then deRecognized was called on the same error', function(){
var error = new CFError(ErrorTypes.Error, "my error");
error.recognize();
error.deRecognize();
error.recognize();
error.deRecognize();
expect(error.isRecognized()).to.equal(false);
});

});

});

});

0 comments on commit 03b9874

Please sign in to comment.