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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
package putio
import (
"context"
"fmt"
"net/http"
"testing"
)
func TestZips_Get(t *testing.T) {
setup()
defer teardown()
fixture := `
{
"missing_files": [],
"size": 27039611973,
"status": "OK",
"url": "https://some-valid-storage-url.com/12345"
}
`
mux.HandleFunc("/v2/zips/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprintln(w, fixture)
})
zip, err := client.Zips.Get(context.Background(), 1)
if err != nil {
t.Error(err)
}
if zip.URL != "https://some-valid-storage-url.com/12345" {
t.Errorf("got: %v, want: https://some-valid-storage-url.com/12345", zip.URL)
}
}
func TestZips_List(t *testing.T) {
setup()
defer teardown()
fixture := `
{
"status": "OK",
"zips": [
{
"created_at": "2016-07-15T10:42:12",
"id": 4177262
}
]
}
`
mux.HandleFunc("/v2/zips/list", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprintln(w, fixture)
})
zips, err := client.Zips.List(context.Background())
if err != nil {
t.Error(err)
}
if len(zips) != 1 {
t.Errorf("got: %v, want: 1", len(zips))
}
if zips[0].ID != 4177262 {
t.Errorf("got: %v, want: 4177262", zips[0].ID)
}
}
func TestZips_Create(t *testing.T) {
setup()
defer teardown()
fixture := `
{
"status": "OK",
"zip_id": 4177264
}
`
mux.HandleFunc("/v2/zips/create", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testHeader(t, r, "Content-Type", "application/x-www-form-urlencoded")
fmt.Fprintln(w, fixture)
})
id, err := client.Zips.Create(context.Background(), 666)
if err != nil {
t.Error(err)
}
if id != 4177264 {
t.Errorf("got: %v, want 4177264", id)
}
_, err = client.Zips.Create(context.Background())
if err == nil {
t.Errorf("empty params accepted")
}
}
|