forked from o1egl/go-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 9
/
client_test.go
59 lines (45 loc) · 1.09 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package wordpress_test
import (
"context"
"errors"
"os"
"testing"
"github.com/robbiet480/go-wordpress"
)
var USER string = os.Getenv("WP_USER")
var PASSWORD string = os.Getenv("WP_PASSWD")
var API_BASE_URL string = os.Getenv("WP_API_URL")
func TestClientNew(t *testing.T) {
tp := wordpress.BasicAuthTransport{
Username: USER,
Password: PASSWORD,
}
client, clientErr := wordpress.NewClient(API_BASE_URL, tp.Client())
if client == nil {
t.Fatalf("Client should not be nil")
}
if clientErr != nil {
t.Fatal("Error parsing URL")
}
}
/**
Test helper functions
*/
// initTestClient creates test wordpress client
func initTestClient() (*wordpress.Client, context.Context) {
if API_BASE_URL == "" {
panic("Please set your environment before running the tests")
}
tp := wordpress.BasicAuthTransport{
Username: USER,
Password: PASSWORD,
}
client, clientErr := wordpress.NewClient(API_BASE_URL, tp.Client())
if client == nil {
panic(errors.New("client should not be nil"))
}
if clientErr != nil {
panic(errors.New("error parsing url"))
}
return client, context.Background()
}