-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
45 lines (38 loc) · 944 Bytes
/
client_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
package gopeana
import (
"fmt"
"testing"
)
func assert(t *testing.T, got, want string) {
t.Helper()
if got != want {
t.Errorf("Got '%s', want '%s'", got, want)
}
}
func TestClient(t *testing.T) {
t.Run("Creating new Client with both keys", func(t *testing.T) {
apiKey := "abc"
privateKey := "def"
client := NewClient(apiKey, privateKey)
if client == nil {
t.Errorf("Client is nil")
}
})
t.Run("Creating new Client without private key", func(t *testing.T) {
c := NewClient("abc", "")
if c == nil {
t.Errorf("Client is nil")
}
})
t.Run("Return proper baseURL", func(t *testing.T) {
c := NewClient("abc", "def")
got := c.baseURL()
if c.Config.UseHTTPS {
want := fmt.Sprintf("https://www.europeana.eu/api/v2/search.json?wskey=%s", c.APIKey)
assert(t, got, want)
} else {
want := fmt.Sprintf("http://www.europeana.eu/api/v2/search.json?wskey=%s", c.APIKey)
assert(t, got, want)
}
})
}