Covered prices.go with tests

This commit is contained in:
Artyom Belousov 2021-02-07 10:10:38 +03:00
parent 90d8cc9c48
commit b823cffe69
5 changed files with 3429 additions and 6 deletions

View file

@ -1,7 +1,6 @@
package cardsinfo
import (
"fmt"
"net/url"
"github.com/antchfx/htmlquery"
@ -9,7 +8,7 @@ import (
)
const scgDomain = "https://starcitygames.com"
const scgSearchUrlTemplate = "https://starcitygames.hawksearch.com/sites/starcitygames/?search_query=%v"
const scgSearchUrlTemplate = "https://starcitygames.hawksearch.com/sites/starcitygames/?search_query="
func GetPrices(name string) ([]CardPrice, error) {
prices, err := GetPricesScg(name)
@ -24,7 +23,7 @@ func GetPrices(name string) ([]CardPrice, error) {
func GetPricesScg(name string) ([]CardPrice, error) {
escapedName := url.QueryEscape(name)
searchUrl := fmt.Sprintf(scgSearchUrlTemplate, escapedName)
searchUrl := scgSearchUrlTemplate + escapedName
node, err := htmlquery.LoadURL(searchUrl)
if err != nil {
return nil, errors.Wrap(err, "cannot load url")