-
Notifications
You must be signed in to change notification settings - Fork 12
/
woo_test.go
89 lines (79 loc) · 1.77 KB
/
woo_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
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
package woocommerce
import (
"fmt"
"github.com/hiscaler/woocommerce-go/config"
jsoniter "github.com/json-iterator/go"
"os"
"testing"
)
var wooClient *WooCommerce
var orderId, noteId int
var mainId, childId int
// Operate data use WooCommerce for golang
func Example() {
b, err := os.ReadFile("./config/config_test.json")
if err != nil {
panic(fmt.Sprintf("Read config error: %s", err.Error()))
}
var c config.Config
err = jsoniter.Unmarshal(b, &c)
if err != nil {
panic(fmt.Sprintf("Parse config file error: %s", err.Error()))
}
wooClient = NewClient(c)
// Query an order
order, err := wooClient.Services.Order.One(1)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(fmt.Sprintf("%#v", order))
}
// Query orders
params := OrdersQueryParams{
After: "2022-06-10",
}
params.PerPage = 100
for {
orders, total, totalPages, isLastPage, err := wooClient.Services.Order.All(params)
if err != nil {
break
}
fmt.Println(fmt.Sprintf("Page %d/%d", total, totalPages))
// read orders
for _, order := range orders {
_ = order
}
if err != nil || isLastPage {
break
}
params.Page++
}
}
func ExampleErrorWrap() {
err := ErrorWrap(200, "Ok")
if err != nil {
return
}
}
func getOrderId(t *testing.T) {
t.Log("Execute getOrderId test")
items, _, _, _, err := wooClient.Services.Order.All(OrdersQueryParams{})
if err != nil || len(items) == 0 {
t.FailNow()
}
orderId = items[0].ID
mainId = items[0].ID
}
func TestMain(m *testing.M) {
b, err := os.ReadFile("./config/config_test.json")
if err != nil {
panic(fmt.Sprintf("Read config error: %s", err.Error()))
}
var c config.Config
err = jsoniter.Unmarshal(b, &c)
if err != nil {
panic(fmt.Sprintf("Parse config file error: %s", err.Error()))
}
wooClient = NewClient(c)
m.Run()
}