-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add gates.NotFound and gates.MultipleCandidates errors
- Loading branch information
thisisaaronland
committed
Sep 30, 2021
1 parent
0373b45
commit 58ed3e1
Showing
6 changed files
with
83 additions
and
4 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,45 @@ | ||
package gates | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type NotFound struct{ code string } | ||
|
||
func (e NotFound) Error() string { | ||
return fmt.Sprintf("Gate '%s' not found", e.code) | ||
} | ||
|
||
func (e NotFound) String() string { | ||
return e.Error() | ||
} | ||
|
||
type MultipleCandidates struct{ code string } | ||
|
||
func (e MultipleCandidates) Error() string { | ||
return fmt.Sprintf("Multiple candidates for gate '%s'", e.code) | ||
} | ||
|
||
func (e MultipleCandidates) String() string { | ||
return e.Error() | ||
} | ||
|
||
func IsNotFound(e error) bool { | ||
|
||
switch e.(type) { | ||
case NotFound, *NotFound: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
func IsMultipleCandidates(e error) bool { | ||
|
||
switch e.(type) { | ||
case MultipleCandidates, *MultipleCandidates: | ||
return true | ||
default: | ||
return false | ||
} | ||
} |
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,32 @@ | ||
package gates | ||
|
||
import ( | ||
_ "fmt" | ||
"testing" | ||
) | ||
|
||
func TestNotFound(t *testing.T) { | ||
|
||
e := NotFound{"A6"} | ||
|
||
if !IsNotFound(e) { | ||
t.Fatalf("Expected NotFound error") | ||
} | ||
|
||
if e.String() != "Gate 'A6' not found" { | ||
t.Fatalf("Invalid stringification") | ||
} | ||
} | ||
|
||
func TestMultipleCandidates(t *testing.T) { | ||
|
||
e := MultipleCandidates{"A6"} | ||
|
||
if !IsMultipleCandidates(e) { | ||
t.Fatalf("Expected MultipleCandidates error") | ||
} | ||
|
||
if e.String() != "Multiple candidates for gate 'A6'" { | ||
t.Fatalf("Invalid stringification") | ||
} | ||
} |
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