TEST
This commit is contained in:
parent
6af125badd
commit
7d6af61b78
@ -8,17 +8,17 @@ import (
|
|||||||
func TestArtistService_Artist(t *testing.T) {
|
func TestArtistService_Artist(t *testing.T) {
|
||||||
expectedId := 1000
|
expectedId := 1000
|
||||||
|
|
||||||
d := NewClient(testUserAgent, testToken)
|
d, _ := NewClient(&Options{})
|
||||||
artist, _, err := d.Artist.Artist(&ArtistParams{Artist_id: "1000"})
|
artist, _, err := d.Artist.Artist(&ArtistParams{Artist_id: "1000"})
|
||||||
|
|
||||||
check(t, err)
|
check(t, err)
|
||||||
assert(t, artist.Id == expectedId, fmt.Sprintf("Release.Title looked for %s, and received %s ", expectedId, artist.Id))
|
assert(t, artist.Id == expectedId, fmt.Sprintf("Release.Title looked for %d, and received %d ", expectedId, artist.Id))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArtistService_Releases(t *testing.T) {
|
func TestArtistService_Releases(t *testing.T) {
|
||||||
expectedArtist := "Dave Clarke"
|
expectedArtist := "Dave Clarke"
|
||||||
|
|
||||||
d := NewClient(testUserAgent, testToken)
|
d, _ := NewClient(&Options{})
|
||||||
releases, _, err := d.Artist.Releases(&ArtistParams{Artist_id: "1000", Sort: "year", Sort_order: "desc"})
|
releases, _, err := d.Artist.Releases(&ArtistParams{Artist_id: "1000", Sort: "year", Sort_order: "desc"})
|
||||||
|
|
||||||
check(t, err)
|
check(t, err)
|
||||||
|
@ -12,6 +12,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
|
URL string
|
||||||
Currency string
|
Currency string
|
||||||
UserAgent string
|
UserAgent string
|
||||||
Token string
|
Token string
|
||||||
@ -47,7 +48,7 @@ func NewClient(o *Options) (*Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
Release: newReleaseService(header, cur),
|
Release: newReleaseService(o.URL+"/releases/", header, cur),
|
||||||
Artist: newArtistService(base.New()),
|
Artist: newArtistService(base.New()),
|
||||||
Label: newLabelService(base.New()),
|
Label: newLabelService(base.New()),
|
||||||
Master: newMasterService(base.New()),
|
Master: newMasterService(base.New()),
|
||||||
@ -62,8 +63,9 @@ func currency(c string) (string, error) {
|
|||||||
switch c {
|
switch c {
|
||||||
case "USD", "GBP", "EUR", "CAD", "AUD", "JPY", "CHF", "MXN", "BRL", "NZD", "SEK", "ZAR":
|
case "USD", "GBP", "EUR", "CAD", "AUD", "JPY", "CHF", "MXN", "BRL", "NZD", "SEK", "ZAR":
|
||||||
return c, nil
|
return c, nil
|
||||||
|
case "":
|
||||||
|
return "USD", nil
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("%v\n", "Invalid currency abbreviation.")
|
return "", fmt.Errorf("%v\n", "Invalid currency abbreviation.")
|
||||||
}
|
}
|
||||||
return "USD", nil
|
|
||||||
}
|
}
|
||||||
|
@ -8,17 +8,17 @@ import (
|
|||||||
func TestLabelService_Label(t *testing.T) {
|
func TestLabelService_Label(t *testing.T) {
|
||||||
expectedId := 1000
|
expectedId := 1000
|
||||||
|
|
||||||
d := NewClient(testUserAgent, testToken)
|
d, _ := NewClient(&Options{})
|
||||||
label, _, err := d.Label.Label(&LabelParams{Label_id: "1000"})
|
label, _, err := d.Label.Label(&LabelParams{Label_id: "1000"})
|
||||||
|
|
||||||
check(t, err)
|
check(t, err)
|
||||||
assert(t, label.Id == expectedId, fmt.Sprintf("Release.Title looked for %s, and received %s ", expectedId, label.Id))
|
assert(t, label.Id == expectedId, fmt.Sprintf("Release.Title looked for %d, and received %d ", expectedId, label.Id))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLabelService_Releases(t *testing.T) {
|
func TestLabelService_Releases(t *testing.T) {
|
||||||
expectedId := "Ghetto Sol"
|
expectedId := "Ghetto Sol"
|
||||||
|
|
||||||
d := NewClient(testUserAgent, testToken)
|
d, _ := NewClient(&Options{})
|
||||||
label, _, err := d.Label.Releases(&LabelParams{Label_id: "1000"})
|
label, _, err := d.Label.Releases(&LabelParams{Label_id: "1000"})
|
||||||
|
|
||||||
check(t, err)
|
check(t, err)
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
func TestMasterService_Master(t *testing.T) {
|
func TestMasterService_Master(t *testing.T) {
|
||||||
expectedTitle := "Elephant Riddim"
|
expectedTitle := "Elephant Riddim"
|
||||||
|
|
||||||
d := NewClient(testUserAgent, testToken)
|
d, _ := NewClient(nil)
|
||||||
master, _, err := d.Master.Master(&MasterParams{Master_id: "960657"})
|
master, _, err := d.Master.Master(&MasterParams{Master_id: "960657"})
|
||||||
|
|
||||||
check(t, err)
|
check(t, err)
|
||||||
@ -18,7 +18,7 @@ func TestMasterService_Master(t *testing.T) {
|
|||||||
func TestMasterService_Versions(t *testing.T) {
|
func TestMasterService_Versions(t *testing.T) {
|
||||||
expectedTitle := "Stardiver"
|
expectedTitle := "Stardiver"
|
||||||
|
|
||||||
d := NewClient(testUserAgent, testToken)
|
d, _ := NewClient(nil)
|
||||||
versions, _, err := d.Master.Versions(&MasterVersionParams{Master_id: "1000", Page: 1, Per_page: 1})
|
versions, _, err := d.Master.Versions(&MasterVersionParams{Master_id: "1000", Page: 1, Per_page: 1})
|
||||||
|
|
||||||
check(t, err)
|
check(t, err)
|
||||||
|
@ -51,12 +51,14 @@ type ReqRelease struct {
|
|||||||
|
|
||||||
// ReleaseService ...
|
// ReleaseService ...
|
||||||
type ReleaseService struct {
|
type ReleaseService struct {
|
||||||
|
url string
|
||||||
header *http.Header
|
header *http.Header
|
||||||
currency string
|
currency string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newReleaseService(header *http.Header, currency string) *ReleaseService {
|
func newReleaseService(url string, header *http.Header, currency string) *ReleaseService {
|
||||||
return &ReleaseService{
|
return &ReleaseService{
|
||||||
|
url: url,
|
||||||
header: header,
|
header: header,
|
||||||
currency: currency,
|
currency: currency,
|
||||||
}
|
}
|
||||||
@ -76,7 +78,7 @@ func (s *ReleaseService) Release(releaseID int) (*Release, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *ReleaseService) request(path string, params url.Values, resp interface{}) error {
|
func (s *ReleaseService) request(path string, params url.Values, resp interface{}) error {
|
||||||
r, err := http.NewRequest("GET", discogsAPI+"releases/"+path+"?"+params.Encode(), nil)
|
r, err := http.NewRequest("GET", s.url+path+"?"+params.Encode(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,27 @@ package discogs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReleaseService_Release(t *testing.T) {
|
func ReleaseServer(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
io.WriteString(w, `{"title":"Elephant Riddim"}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReleaseServiceRelease(t *testing.T) {
|
||||||
expectedTitle := "Elephant Riddim"
|
expectedTitle := "Elephant Riddim"
|
||||||
|
|
||||||
d := NewClient(testUserAgent, testToken)
|
ts := httptest.NewServer(http.HandlerFunc(ReleaseServer))
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
d, err := NewClient(&Options{URL: ts.URL})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create client: %s", err)
|
||||||
|
}
|
||||||
release, err := d.Release.Release(8138518)
|
release, err := d.Release.Release(8138518)
|
||||||
|
|
||||||
check(t, err)
|
check(t, err)
|
||||||
|
Reference in New Issue
Block a user