krz/devianter
A DeviantArt guest API library for Go.
clone: git clone https://gitbay.org/krz/devianter.git
v0.3.2: user-group_test.go · raw
1package devianter
2
3import (
4 "testing"
5 "time"
6)
7
8// Regression: Favourites and Gallery took folderid as a variadic, which invites
9// omitting it, but then indexed folderid[0] with no length check — so the call
10// the signature invites most panicked with index out of range.
11//
12// Both reach a request before returning, and neither takes a base URL, so these
13// squeeze Timeout down to make that request fail immediately. The failure is
14// expected and ignored: only the absence of a panic is under test.
15func TestFolderidIsOptional(t *testing.T) {
16 defer func(d time.Duration) { Timeout = d }(Timeout)
17 Timeout = time.Millisecond
18
19 s := Group{Name: "someuser"}
20
21 t.Run("Gallery", func(t *testing.T) {
22 if _, _, err := s.Gallery(0); err != nil {
23 t.Errorf("omitting folderid is not an argument error, got %v", err)
24 }
25 })
26
27 t.Run("Favourites all", func(t *testing.T) {
28 _, _ = s.Favourites(0, true)
29 })
30
31 t.Run("Favourites default listing", func(t *testing.T) {
32 _, _ = s.Favourites(0, false)
33 })
34}
35
36// Name is what every request is scoped to, so Gallery reports its absence
37// rather than requesting a URL with an empty username.
38func TestGalleryRequiresName(t *testing.T) {
39 var s Group
40 if _, _, err := s.Gallery(0, 0); err == nil {
41 t.Fatal("want an error for a Group with no Name, got nil")
42 }
43}