-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
143 lines (126 loc) · 3.93 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package swan
import (
"testing"
"time"
)
const (
ApiKey = "<API_KEY>"
WalletAddress = "<WALLET_ADDRESS>"
PrivateKey = "<WALLET_ADDRESS_PRIVATE_KEY>"
repoUri = "https://github.com/swanchain/awesome-swanchain/tree/main/hello_world"
)
func TestAPIClient_CreateTaskWithAutoPay(t *testing.T) {
instanceType := "C1ae.medium"
var req = CreateTaskReq{
Duration: time.Hour,
PrivateKey: PrivateKey,
RepoUri: repoUri,
InstanceType: instanceType,
}
apiClient, _ := NewAPIClient(ApiKey, true)
resp, err := apiClient.CreateTask(&req)
if err != nil {
t.Errorf("CreateTaskWithAutoPay() error = %v", err)
}
t.Logf("create task with auto-pay response: %+v", resp)
}
func TestAPIClient_CreateTask(t *testing.T) {
var req = CreateTaskReq{
//JobSourceUri: JobSourceUri,
WalletAddress: WalletAddress,
}
apiClient, _ := NewAPIClient(ApiKey, true)
resp, err := apiClient.CreateTask(&req)
if err != nil {
t.Errorf("CreateTask() error = %v", err)
}
t.Logf("create task response: %v", resp)
}
func TestAPIClient_PayAndDeployTask(t *testing.T) {
apiClient, _ := NewAPIClient(ApiKey, true)
// taskUuid: returned by create task
taskUuid := "a9d2f2ca-8819-43f7-9347-7ccf0ea11822"
payAndDeployTaskResp, err := apiClient.PayAndDeployTask(taskUuid, PrivateKey, time.Hour, "C1ae.small")
if err != nil {
t.Errorf("PayAndDeployTask() error = %v", err)
}
t.Logf("pay and deploy task response: %v", payAndDeployTaskResp)
}
func TestAPIClient_TaskInfo(t *testing.T) {
apiClient, _ := NewAPIClient(ApiKey, true)
resp, err := apiClient.TaskInfo("a9d2f2ca-8819-43f7-9347-7ccf0ea11822")
if err != nil {
t.Errorf("TaskInfo() error = %v", err)
}
t.Logf("get task info response: %v", resp)
}
func TestAPIClient_Tasks(t *testing.T) {
var req = &TaskQueryReq{
Wallet: WalletAddress,
Page: 0,
Size: 10,
}
apiClient, _ := NewAPIClient(ApiKey, true)
total, resp, err := apiClient.Tasks(req)
if err != nil {
t.Errorf("Tasks() error = %v", err)
}
t.Logf("get task list response, total: %d, data: %v", total, resp)
}
func TestAPIClient_Hardwares(t *testing.T) {
apiClient, _ := NewAPIClient(ApiKey, true)
resp, err := apiClient.InstanceResources(true)
if err != nil {
t.Errorf("Hardwares() error = %v", err)
}
t.Logf("get haredware response, resp: %v", resp)
}
func TestAPIClient_GetRealUrl(t *testing.T) {
apiClient, _ := NewAPIClient(ApiKey, true)
resp, err := apiClient.GetRealUrl("01c0f29a-2304-45fa-bb03-976348e714e4")
if err != nil {
t.Errorf("CreateTask() error = %v", err)
}
t.Logf("create task response: %v", resp)
}
func TestAPIClient_TerminateTask(t *testing.T) {
apiClient, _ := NewAPIClient(ApiKey, true)
resp, err := apiClient.TerminateTask("01c0f29a-2304-45fa-bb03-976348e714e4")
if err != nil {
t.Errorf("TerminateTask() error = %v", err)
}
t.Logf("terminate task response: %v", resp)
}
func Test_getContractInfo(t *testing.T) {
apiClient, _ := NewAPIClient(ApiKey, true)
resp, err := apiClient.getContractInfo(false)
if err != nil {
t.Errorf("getContractInfo() error = %v", err)
}
t.Logf("get contract response: %+v", resp)
}
func TestAPIClient_EstimatePayment(t *testing.T) {
apiClient, _ := NewAPIClient(ApiKey, true)
resp, err := apiClient.EstimatePayment("P1ae.medium", 3600)
if err != nil {
t.Errorf("EstimatePayment() error = %v", err)
}
// 32
t.Logf("estimate Payment response: %v", resp)
}
func TestAPIClient_ReNewTask(t *testing.T) {
apiClient, _ := NewAPIClient(ApiKey, true)
resp, err := apiClient.RenewTask("a9d2f2ca-8819-43f7-9347-7ccf0ea11822", time.Hour, PrivateKey)
if err != nil {
t.Errorf("ReNewTask() error = %v", err)
}
t.Logf("renew task with auto-pay response: %v", resp)
}
func TestAPIClient_RenewPayment(t *testing.T) {
apiClient, _ := NewAPIClient(ApiKey, true)
txHash, err := apiClient.RenewPayment("a9d2f2ca-8819-43f7-9347-7ccf0ea11822", time.Hour, PrivateKey)
if err != nil {
t.Errorf("RenewPayment() error = %v", err)
}
t.Logf("renew payment response: %v", txHash)
}