diff options
| author | copilot-swe-agent[bot] <[email protected]> | 2026-01-14 19:04:10 +0000 |
|---|---|---|
| committer | copilot-swe-agent[bot] <[email protected]> | 2026-01-14 19:04:10 +0000 |
| commit | af5c224dd7b66474a54aa20b4c1e7306667badf7 (patch) | |
| tree | 5f9b27680490b7638574398838a3bcbadf162779 /lib/error_test.go | |
| parent | d76526fc786931b34f6c4a3b27df71973927b63e (diff) | |
Add comprehensive unit tests for lib package with 91.9% coveragecopilot/add-unit-tests-lib-package
Co-authored-by: Loyalsoldier <[email protected]>
Diffstat (limited to 'lib/error_test.go')
| -rw-r--r-- | lib/error_test.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/error_test.go b/lib/error_test.go new file mode 100644 index 00000000..fb2f280f --- /dev/null +++ b/lib/error_test.go @@ -0,0 +1,55 @@ +package lib + +import ( + "testing" +) + +func TestErrorVariables(t *testing.T) { + tests := []struct { + name string + err error + want string + }{ + {"ErrDuplicatedConverter", ErrDuplicatedConverter, "duplicated converter"}, + {"ErrUnknownAction", ErrUnknownAction, "unknown action"}, + {"ErrNotSupportedFormat", ErrNotSupportedFormat, "not supported format"}, + {"ErrInvalidIPType", ErrInvalidIPType, "invalid IP type"}, + {"ErrInvalidIP", ErrInvalidIP, "invalid IP address"}, + {"ErrInvalidIPLength", ErrInvalidIPLength, "invalid IP address length"}, + {"ErrInvalidIPNet", ErrInvalidIPNet, "invalid IPNet address"}, + {"ErrInvalidCIDR", ErrInvalidCIDR, "invalid CIDR"}, + {"ErrInvalidPrefix", ErrInvalidPrefix, "invalid prefix"}, + {"ErrInvalidPrefixType", ErrInvalidPrefixType, "invalid prefix type"}, + {"ErrCommentLine", ErrCommentLine, "comment line"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if tt.err.Error() != tt.want { + t.Errorf("%s.Error() = %s, want %s", tt.name, tt.err.Error(), tt.want) + } + }) + } +} + +func TestErrorsAreNotNil(t *testing.T) { + errors := []error{ + ErrDuplicatedConverter, + ErrUnknownAction, + ErrNotSupportedFormat, + ErrInvalidIPType, + ErrInvalidIP, + ErrInvalidIPLength, + ErrInvalidIPNet, + ErrInvalidCIDR, + ErrInvalidPrefix, + ErrInvalidPrefixType, + ErrCommentLine, + } + + for _, err := range errors { + if err == nil { + t.Error("Expected error to be non-nil") + } + } +} |
