Skip to content

Commit f12d2dc

Browse files
committed
fix test
1 parent 901b88a commit f12d2dc

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

integration/go/main.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package main
22

33
import (
4+
"bytes"
5+
"encoding/json"
46
"errors"
57
"github.com/apioo/sdkgen-go/v2"
68
"log"
9+
"net/url"
710
"strconv"
811
)
912

@@ -19,6 +22,11 @@ func main() {
1922
assertGetEntries(client)
2023
assertInsert(client)
2124
assertThrowException(client)
25+
assertBinary(client)
26+
assertForm(client)
27+
assertJson(client)
28+
assertText(client)
29+
assertXml(client)
2230
}
2331

2432
func assertGetHello(client *Client) {
@@ -98,3 +106,77 @@ func assertThrowException(client *Client) {
98106
log.Fatal("Test assertThrowException failed: Error message does not match, got: " + err.Error())
99107
}
100108
}
109+
110+
func assertBinary(client *Client) {
111+
var payload = []byte{0x66, 0x6F, 0x6F, 0x62, 0x61, 0x72}
112+
113+
response, err := client.Test().Binary(payload)
114+
if err != nil {
115+
log.Fatal(err)
116+
}
117+
118+
if !bytes.Equal(*response, payload) {
119+
log.Fatal("Test assertBinary failed")
120+
}
121+
}
122+
123+
func assertForm(client *Client) {
124+
var payload = url.Values{}
125+
payload.Set("foo", "bar")
126+
127+
response, err := client.Test().Form(payload)
128+
if err != nil {
129+
log.Fatal(err)
130+
}
131+
132+
if response.Get("foo") != "bar" {
133+
log.Fatal("Test assertForm failed")
134+
}
135+
}
136+
137+
func assertJson(client *Client) {
138+
var payload = make(map[string]string)
139+
payload["foo"] = "bar"
140+
141+
response, err := client.Test().Json(payload)
142+
if err != nil {
143+
log.Fatal(err)
144+
}
145+
146+
if response == nil {
147+
log.Fatal("Test assertJson failed, no response")
148+
}
149+
150+
left, _ := json.Marshal(payload)
151+
right, _ := json.Marshal(&response)
152+
153+
if !bytes.Equal(left, right) {
154+
log.Fatal("Test assertJson failed")
155+
}
156+
}
157+
158+
func assertText(client *Client) {
159+
var payload = "foobar"
160+
161+
response, err := client.Test().Text(payload)
162+
if err != nil {
163+
log.Fatal(err)
164+
}
165+
166+
if payload != response {
167+
log.Fatal("Test assertText failed")
168+
}
169+
}
170+
171+
func assertXml(client *Client) {
172+
var payload = "<foo>bar</foo>"
173+
174+
response, err := client.Test().Xml(payload)
175+
if err != nil {
176+
log.Fatal(err)
177+
}
178+
179+
if payload != response {
180+
log.Fatal("Test assertXml failed")
181+
}
182+
}

0 commit comments

Comments
 (0)