Fixed bug with Reader exhaustion
This commit is contained in:
parent
d8a295be75
commit
425f0fd56d
6 changed files with 18 additions and 42 deletions
|
|
@ -1,7 +1,5 @@
|
|||
package cardsinfo
|
||||
|
||||
import "io"
|
||||
|
||||
type Fetcher struct {
|
||||
Dict io.Reader
|
||||
Dict map[string]string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ func (f *Fetcher) GetOriginalName(name string) string {
|
|||
path := scryfallUrl + "/cards/named?fuzzy=" + applyFilters(name)
|
||||
result := getCardByUrl(path)
|
||||
if result == "" && f.Dict != nil {
|
||||
result, _ = dicttranslate.FindFromReader(name, f.Dict, 5)
|
||||
result, _ = dicttranslate.Find(name, f.Dict, 5)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
package cardsinfo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/h2non/gock.v1"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
@ -31,19 +29,19 @@ func TestGetOriginalName_Scryfall(t *testing.T) {
|
|||
assert.Equal(t, "Result Card", name)
|
||||
}
|
||||
|
||||
func TestGetOriginalName_Dict(t *testing.T) {
|
||||
func TestGetOriginalName_DictTwice(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
gock.New(scryfallUrl + "/cards/named?fuzzy=card").Reply(http.StatusOK).JSON(card{})
|
||||
serialized, _ := json.Marshal(map[string]string{
|
||||
"card": "Card",
|
||||
})
|
||||
dict := strings.NewReader(string(serialized))
|
||||
gock.New(scryfallUrl + "/cards/named?fuzzy=card").Persist().Reply(http.StatusOK).JSON(card{})
|
||||
f := &Fetcher{
|
||||
Dict: dict,
|
||||
Dict: map[string]string{
|
||||
"card": "Card",
|
||||
},
|
||||
}
|
||||
name := f.GetOriginalName("card")
|
||||
assert.Equal(t, "Card", name)
|
||||
name = f.GetOriginalName("card")
|
||||
assert.Equal(t, "Card", name)
|
||||
}
|
||||
|
||||
func TestGetOriginalName_BadJson(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue