-
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 FindCurrent methods and NotFound, MultipleCandidates errors for g…
…alleries
- Loading branch information
thisisaaronland
committed
Oct 1, 2021
1 parent
e94af64
commit 8aa0076
Showing
5 changed files
with
182 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package galleries | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type NotFound struct{ code string } | ||
|
||
func (e NotFound) Error() string { | ||
return fmt.Sprintf("Gallery '%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 gallery '%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 galleries | ||
|
||
import ( | ||
_ "fmt" | ||
"testing" | ||
) | ||
|
||
func TestGalleriesNotFound(t *testing.T) { | ||
|
||
e := NotFound{"D16"} | ||
|
||
if !IsNotFound(e) { | ||
t.Fatalf("Expected NotFound error") | ||
} | ||
|
||
if e.String() != "Gallery 'D16' not found" { | ||
t.Fatalf("Invalid stringification") | ||
} | ||
} | ||
|
||
func TestGalleriesMultipleCandidates(t *testing.T) { | ||
|
||
e := MultipleCandidates{"D16"} | ||
|
||
if !IsMultipleCandidates(e) { | ||
t.Fatalf("Expected MultipleCandidates error") | ||
} | ||
|
||
if e.String() != "Multiple candidates for gallery 'D16'" { | ||
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
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,28 @@ | ||
package galleries | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func TestFindCurrentGallery(t *testing.T) { | ||
|
||
tests := map[string]int64{ | ||
"D16": 1745882461, | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
for code, id := range tests { | ||
|
||
g, err := FindCurrentGallery(ctx, code) | ||
|
||
if err != nil { | ||
t.Fatalf("Failed to find current gallery for %s, %v", code, err) | ||
} | ||
|
||
if g.WhosOnFirstId != id { | ||
t.Fatalf("Unexpected ID for gallery %s. Got %d but expected %d", code, g.WhosOnFirstId, id) | ||
} | ||
} | ||
} |
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