-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmarketplace_test.go
76 lines (60 loc) · 1.73 KB
/
marketplace_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package discogs
import (
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"strconv"
"testing"
)
const testReleaseID = 9893847
func MarketplaceServer(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
switch r.URL.Path {
case "/marketplace" + priceSuggestionsURI + strconv.Itoa(testReleaseID):
w.WriteHeader(http.StatusOK)
if _, err := io.WriteString(w, priceSuggestionJson); err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
case "/marketplace" + releaseStatsURI + strconv.Itoa(testReleaseID):
w.WriteHeader(http.StatusOK)
if _, err := io.WriteString(w, releaseStatsJson); err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
default:
w.WriteHeader(http.StatusMethodNotAllowed)
}
}
func TestMarketplacePriceSuggestions(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(MarketplaceServer))
defer ts.Close()
d := initDiscogsClient(t, &Options{URL: ts.URL})
suggestion, err := d.PriceSuggestions(testReleaseID)
if err != nil {
t.Fatalf("failed to get price suggestion: %s", err)
}
json, err := json.Marshal(suggestion)
if err != nil {
t.Fatalf("failed to marshal folder: %s", err)
}
compareJson(t, string(json), priceSuggestionJson)
}
func TestMarketplaceReleaseStatistics(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(MarketplaceServer))
defer ts.Close()
d := initDiscogsClient(t, &Options{URL: ts.URL})
stats, err := d.ReleaseStatistics(testReleaseID)
if err != nil {
t.Fatalf("failed to get price suggestion: %s", err)
}
json, err := json.Marshal(stats)
if err != nil {
t.Fatalf("failed to marshal folder: %s", err)
}
compareJson(t, string(json), releaseStatsJson)
}