@@ -17,14 +17,17 @@ limitations under the License.
1717package remote
1818
1919import (
20+ "google.golang.org/protobuf/types/known/timestamppb"
2021 "testing"
22+ "time"
2123
2224 server "github.com/linuxsuren/api-testing/pkg/server"
2325 atest "github.com/linuxsuren/api-testing/pkg/testing"
2426 "github.com/stretchr/testify/assert"
2527)
2628
2729func TestConvert (t * testing.T ) {
30+ now := time .Now ().UTC ()
2831 t .Run ("convertToNormalTestSuite, empty object" , func (t * testing.T ) {
2932 assert .Equal (t , & atest.TestSuite {
3033 Param : map [string ]string {},
@@ -123,6 +126,211 @@ func TestConvert(t *testing.T) {
123126 assert .Equal (t , defaultPairs , result .Response .BodyFieldsExpect )
124127 assert .Equal (t , defaultPairs , result .Response .Header )
125128 })
129+
130+ t .Run ("convertHistoryToGRPCTestCase" , func (t * testing.T ) {
131+ result := ConvertHistoryToGRPCTestCase (& server.HistoryTestCase {
132+ CaseName : "fake" ,
133+ Request : & server.Request {
134+ Header : defaultPairs ,
135+ },
136+ Response : & server.Response {
137+ BodyFieldsExpect : defaultPairs ,
138+ },
139+ })
140+ if ! assert .NotNil (t , result ) {
141+ return
142+ }
143+ assert .Equal (t , defaultMap , result .Request .Header )
144+ assert .Equal (t , defaultInterMap , result .Expect .BodyFieldsExpect )
145+ assert .Equal (t , "fake" , result .Name )
146+ })
147+
148+ t .Run ("convertToNormalHistoryTestCase" , func (t * testing.T ) {
149+ assert .Equal (t , atest.HistoryTestCase {
150+ CreateTime : now ,
151+ SuiteParam : defaultMap ,
152+ SuiteSpec : atest.APISpec {
153+ Kind : "http" ,
154+ URL : "/v1" ,
155+ RPC : & atest.RPCDesc {
156+ Raw : "fake" ,
157+ },
158+ Secure : & atest.Secure {
159+ KeyFile : "fake" ,
160+ },
161+ },
162+ Data : atest.TestCase {
163+ Request : atest.Request {
164+ API : "/v1" ,
165+ Header : defaultMap ,
166+ Query : map [string ]interface {}{},
167+ Form : map [string ]string {},
168+ },
169+ Expect : atest.Response {
170+ BodyFieldsExpect : defaultInterMap ,
171+ Header : map [string ]string {},
172+ },
173+ },
174+ }, ConvertToNormalHistoryTestCase (& server.HistoryTestCase {
175+ CreateTime : timestamppb .New (now ),
176+ SuiteParam : defaultPairs ,
177+ SuiteSpec : & server.APISpec {
178+ Url : "/v1" ,
179+ Kind : "http" ,
180+ Rpc : & server.RPC {
181+ Raw : "fake" ,
182+ },
183+ Secure : & server.Secure {
184+ Key : "fake" ,
185+ },
186+ },
187+ Request : & server.Request {
188+ Header : defaultPairs ,
189+ Query : nil ,
190+ Api : "/v1" ,
191+ },
192+ Response : & server.Response {
193+ BodyFieldsExpect : defaultPairs ,
194+ },
195+ }))
196+ })
197+
198+ t .Run ("convertToNormalHistoryTestSuite, empty object" , func (t * testing.T ) {
199+ assert .Equal (t , & atest.HistoryTestSuite {}, ConvertToNormalHistoryTestSuite (& HistoryTestSuite {}))
200+ })
201+
202+ t .Run ("convertToNormalHistoryTestSuite, normal object" , func (t * testing.T ) {
203+ assert .Equal (t , & atest.HistoryTestSuite {
204+ HistorySuiteName : "fake" ,
205+ Items : []atest.HistoryTestCase {
206+ {
207+ CreateTime : now ,
208+ SuiteParam : defaultMap ,
209+ SuiteSpec : atest.APISpec {
210+ Kind : "http" ,
211+ URL : "/v1" ,
212+ RPC : & atest.RPCDesc {
213+ Raw : "fake" ,
214+ },
215+ Secure : & atest.Secure {
216+ KeyFile : "fake" ,
217+ },
218+ },
219+ },
220+ },
221+ }, ConvertToNormalHistoryTestSuite (& HistoryTestSuite {
222+ HistorySuiteName : "fake" ,
223+ Items : []* server.HistoryTestCase {
224+ {
225+ CreateTime : timestamppb .New (now ),
226+ SuiteParam : defaultPairs ,
227+ SuiteSpec : & server.APISpec {
228+ Url : "/v1" ,
229+ Kind : "http" ,
230+ Rpc : & server.RPC {
231+ Raw : "fake" ,
232+ },
233+ Secure : & server.Secure {
234+ Key : "fake" ,
235+ },
236+ },
237+ },
238+ },
239+ }))
240+ })
241+
242+ t .Run ("convertToGRPCHistoryTestCase" , func (t * testing.T ) {
243+ result := ConvertToGRPCHistoryTestCase (atest.HistoryTestCase {
244+ SuiteParam : defaultMap ,
245+ SuiteSpec : atest.APISpec {
246+ Secure : & atest.Secure {
247+ KeyFile : "fake" ,
248+ },
249+ },
250+ Data : atest.TestCase {
251+ Request : atest.Request {
252+ Header : defaultMap ,
253+ },
254+ Expect : atest.Response {
255+ BodyFieldsExpect : defaultInterMap ,
256+ },
257+ },
258+ })
259+ assert .Equal (t , defaultPairs , result .SuiteParam )
260+ assert .Equal (t , defaultPairs , result .Request .Header )
261+ assert .Equal (t , defaultPairs , result .Response .BodyFieldsExpect )
262+ assert .Equal (t , "fake" , result .SuiteSpec .Secure .Key )
263+ })
264+
265+ t .Run ("convertToGRPCHistoryTestCaseResult" , func (t * testing.T ) {
266+ result := ConvertToGRPCHistoryTestCaseResult (atest.TestCaseResult {
267+ Body : "fake body" ,
268+ Output : "fake output" ,
269+ }, & atest.TestSuite {
270+ Param : defaultMap ,
271+ Spec : atest.APISpec {
272+ Secure : & atest.Secure {
273+ KeyFile : "fake" ,
274+ },
275+ },
276+ Items : []atest.TestCase {
277+ {
278+ Request : atest.Request {
279+ Header : defaultMap ,
280+ },
281+ Expect : atest.Response {
282+ BodyFieldsExpect : defaultInterMap ,
283+ },
284+ },
285+ },
286+ })
287+ assert .Equal (t , defaultPairs , result .Data .SuiteParam )
288+ assert .Equal (t , defaultPairs , result .Data .Request .Header )
289+ assert .Equal (t , defaultPairs , result .Data .Response .BodyFieldsExpect )
290+ assert .Equal (t , "fake" , result .Data .SuiteSpec .Secure .Key )
291+ assert .Equal (t , "fake output" , result .TestCaseResult [0 ].Output )
292+ assert .Equal (t , "fake body" , result .TestCaseResult [0 ].Body )
293+ })
294+
295+ t .Run ("convertToNormalTestCaseResult" , func (t * testing.T ) {
296+ assert .Equal (t , atest.HistoryTestResult {
297+ CreateTime : now ,
298+ Data : atest.HistoryTestCase {
299+ SuiteParam : defaultMap ,
300+ CreateTime : now ,
301+ },
302+ TestCaseResult : []atest.TestCaseResult {
303+ {
304+ Body : "fake body" ,
305+ Output : "fake output" ,
306+ Header : defaultMap ,
307+ },
308+ {
309+ Body : "fake body 2" ,
310+ Output : "fake output 2" ,
311+ Header : defaultMap ,
312+ },
313+ },
314+ }, ConvertToNormalTestCaseResult (& server.HistoryTestResult {
315+ CreateTime : timestamppb .New (now ),
316+ Data : & server.HistoryTestCase {
317+ SuiteParam : defaultPairs ,
318+ CreateTime : timestamppb .New (now ),
319+ },
320+ TestCaseResult : []* server.TestCaseResult {
321+ {
322+ Body : "fake body" ,
323+ Output : "fake output" ,
324+ Header : defaultPairs ,
325+ },
326+ {
327+ Body : "fake body 2" ,
328+ Output : "fake output 2" ,
329+ Header : defaultPairs ,
330+ },
331+ },
332+ }))
333+ })
126334}
127335
128336var defaultInterMap = map [string ]interface {}{"foo" : "bar" }
0 commit comments