krz/devianter

A DeviantArt guest API library for Go.

clone: git clone https://gitbay.org/krz/devianter.git

v0.3.3: misc_test.go · raw

 1package devianter
 2
 3import "testing"
 4
 5// Regression: AEmedia used to call log.Fatalln on an unknown type, terminating
 6// the calling process. If this test ever regresses it will not fail — the test
 7// binary will exit(1) mid-run.
 8func TestAEmediaInvalidTypeReturnsError(t *testing.T) {
 9	_, err := AEmedia("someuser", 'z')
10	if err == nil {
11		t.Fatal("want an error for an unknown type, got nil")
12	}
13}
14
15// The argument checks must run in an order that never leaves a valid-looking
16// call unreported: a short name is an error regardless of type.
17func TestAEmediaShortNameReturnsError(t *testing.T) {
18	if _, err := AEmedia("", 'a'); err == nil {
19		t.Fatal("want an error for an empty name, got nil")
20	}
21}
22
23// Regression: PerformSearch used to call log.Fatalln on an unknown scope. As
24// above, a regression exits the test binary rather than failing this test.
25func TestPerformSearchInvalidScopeReturnsError(t *testing.T) {
26	_, _, err := PerformSearch("cats", 0, 'z')
27	if err == nil {
28		t.Fatal("want an error for an unknown scope, got nil")
29	}
30}
31
32// The account-scoped searches need a username, and must say so rather than
33// requesting a URL with an empty one.
34func TestPerformSearchAccountScopesRequireUser(t *testing.T) {
35	for _, scope := range []rune{'g', 'f'} {
36		if _, _, err := PerformSearch("cats", 0, scope); err == nil {
37			t.Errorf("want an error for scope %q with no username, got nil", scope)
38		}
39	}
40}