-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* define finality violation error Signed-off-by: Dmytro Haidashenko <dmytro.haidashenko@smartcontract.com> * rename finality violation Signed-off-by: Dmytro Haidashenko <dmytro.haidashenko@smartcontract.com> * Test ContainsError Signed-off-by: Dmytro Haidashenko <dmytro.haidashenko@smartcontract.com> --------- Signed-off-by: Dmytro Haidashenko <dmytro.haidashenko@smartcontract.com> Co-authored-by: Domino Valdano <domino.valdano@smartcontract.com>
- Loading branch information
1 parent
9087f5e
commit 0b03fa3
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package services | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestContainsError(t *testing.T) { | ||
anError := errors.New("an error") | ||
anotherError := errors.New("another error") | ||
testCases := []struct { | ||
Name string | ||
Report map[string]error | ||
Target error | ||
ExpectedResult bool | ||
}{ | ||
{ | ||
Name: "nil map", | ||
Report: nil, | ||
Target: anError, | ||
ExpectedResult: false, | ||
}, | ||
{ | ||
Name: "report contains service, but it's healthy", | ||
Report: map[string]error{"service": nil}, | ||
Target: anError, | ||
ExpectedResult: false, | ||
}, | ||
{ | ||
Name: "service is not healthy, but it's not caused by target error", | ||
Report: map[string]error{"service": anotherError}, | ||
Target: anError, | ||
ExpectedResult: false, | ||
}, | ||
{ | ||
Name: "service is not healthy and contains wrapper target", | ||
Report: map[string]error{"service": fmt.Errorf("wrapped error: %w", anError)}, | ||
Target: anError, | ||
ExpectedResult: true, | ||
}, | ||
{ | ||
Name: "service is not healthy due to multiple errors including target", | ||
Report: map[string]error{"service": errors.Join(anError, anotherError)}, | ||
Target: anError, | ||
ExpectedResult: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
actualResult := ContainsError(tc.Report, tc.Target) | ||
assert.Equal(t, tc.ExpectedResult, actualResult) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters