github.com/fastwego/offiaccount@v1.0.1/apis/invoice/invoice_test.go (about) 1 // Copyright 2020 FastWeGo 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package invoice 16 17 import ( 18 "net/http" 19 "os" 20 "reflect" 21 "testing" 22 23 "github.com/fastwego/offiaccount" 24 "github.com/fastwego/offiaccount/test" 25 ) 26 27 func TestMain(m *testing.M) { 28 test.Setup() 29 os.Exit(m.Run()) 30 } 31 32 func TestGetAuthUrl(t *testing.T) { 33 mockResp := map[string][]byte{ 34 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 35 } 36 var resp []byte 37 test.MockSvrHandler.HandleFunc(apiGetAuthUrl, func(w http.ResponseWriter, r *http.Request) { 38 w.Write([]byte(resp)) 39 }) 40 41 type args struct { 42 ctx *offiaccount.OffiAccount 43 payload []byte 44 } 45 tests := []struct { 46 name string 47 args args 48 wantResp []byte 49 wantErr bool 50 }{ 51 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 52 } 53 for _, tt := range tests { 54 t.Run(tt.name, func(t *testing.T) { 55 resp = mockResp[tt.name] 56 gotResp, err := GetAuthUrl(tt.args.ctx, tt.args.payload) 57 //fmt.Println(string(gotResp), err) 58 if (err != nil) != tt.wantErr { 59 t.Errorf("GetAuthUrl() error = %v, wantErr %v", err, tt.wantErr) 60 return 61 } 62 if !reflect.DeepEqual(gotResp, tt.wantResp) { 63 t.Errorf("GetAuthUrl() gotResp = %v, want %v", gotResp, tt.wantResp) 64 } 65 }) 66 } 67 } 68 func TestGetAuthData(t *testing.T) { 69 mockResp := map[string][]byte{ 70 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 71 } 72 var resp []byte 73 test.MockSvrHandler.HandleFunc(apiGetAuthData, func(w http.ResponseWriter, r *http.Request) { 74 w.Write([]byte(resp)) 75 }) 76 77 type args struct { 78 ctx *offiaccount.OffiAccount 79 payload []byte 80 } 81 tests := []struct { 82 name string 83 args args 84 wantResp []byte 85 wantErr bool 86 }{ 87 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 88 } 89 for _, tt := range tests { 90 t.Run(tt.name, func(t *testing.T) { 91 resp = mockResp[tt.name] 92 gotResp, err := GetAuthData(tt.args.ctx, tt.args.payload) 93 //fmt.Println(string(gotResp), err) 94 if (err != nil) != tt.wantErr { 95 t.Errorf("GetAuthData() error = %v, wantErr %v", err, tt.wantErr) 96 return 97 } 98 if !reflect.DeepEqual(gotResp, tt.wantResp) { 99 t.Errorf("GetAuthData() gotResp = %v, want %v", gotResp, tt.wantResp) 100 } 101 }) 102 } 103 } 104 func TestRejectInsert(t *testing.T) { 105 mockResp := map[string][]byte{ 106 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 107 } 108 var resp []byte 109 test.MockSvrHandler.HandleFunc(apiRejectInsert, func(w http.ResponseWriter, r *http.Request) { 110 w.Write([]byte(resp)) 111 }) 112 113 type args struct { 114 ctx *offiaccount.OffiAccount 115 payload []byte 116 } 117 tests := []struct { 118 name string 119 args args 120 wantResp []byte 121 wantErr bool 122 }{ 123 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 124 } 125 for _, tt := range tests { 126 t.Run(tt.name, func(t *testing.T) { 127 resp = mockResp[tt.name] 128 gotResp, err := RejectInsert(tt.args.ctx, tt.args.payload) 129 //fmt.Println(string(gotResp), err) 130 if (err != nil) != tt.wantErr { 131 t.Errorf("RejectInsert() error = %v, wantErr %v", err, tt.wantErr) 132 return 133 } 134 if !reflect.DeepEqual(gotResp, tt.wantResp) { 135 t.Errorf("RejectInsert() gotResp = %v, want %v", gotResp, tt.wantResp) 136 } 137 }) 138 } 139 } 140 func TestMakeOutInvoice(t *testing.T) { 141 mockResp := map[string][]byte{ 142 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 143 } 144 var resp []byte 145 test.MockSvrHandler.HandleFunc(apiMakeOutInvoice, func(w http.ResponseWriter, r *http.Request) { 146 w.Write([]byte(resp)) 147 }) 148 149 type args struct { 150 ctx *offiaccount.OffiAccount 151 payload []byte 152 } 153 tests := []struct { 154 name string 155 args args 156 wantResp []byte 157 wantErr bool 158 }{ 159 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 160 } 161 for _, tt := range tests { 162 t.Run(tt.name, func(t *testing.T) { 163 resp = mockResp[tt.name] 164 gotResp, err := MakeOutInvoice(tt.args.ctx, tt.args.payload) 165 //fmt.Println(string(gotResp), err) 166 if (err != nil) != tt.wantErr { 167 t.Errorf("MakeOutInvoice() error = %v, wantErr %v", err, tt.wantErr) 168 return 169 } 170 if !reflect.DeepEqual(gotResp, tt.wantResp) { 171 t.Errorf("MakeOutInvoice() gotResp = %v, want %v", gotResp, tt.wantResp) 172 } 173 }) 174 } 175 } 176 func TestClearOutInvoice(t *testing.T) { 177 mockResp := map[string][]byte{ 178 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 179 } 180 var resp []byte 181 test.MockSvrHandler.HandleFunc(apiClearOutInvoice, func(w http.ResponseWriter, r *http.Request) { 182 w.Write([]byte(resp)) 183 }) 184 185 type args struct { 186 ctx *offiaccount.OffiAccount 187 payload []byte 188 } 189 tests := []struct { 190 name string 191 args args 192 wantResp []byte 193 wantErr bool 194 }{ 195 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 196 } 197 for _, tt := range tests { 198 t.Run(tt.name, func(t *testing.T) { 199 resp = mockResp[tt.name] 200 gotResp, err := ClearOutInvoice(tt.args.ctx, tt.args.payload) 201 //fmt.Println(string(gotResp), err) 202 if (err != nil) != tt.wantErr { 203 t.Errorf("ClearOutInvoice() error = %v, wantErr %v", err, tt.wantErr) 204 return 205 } 206 if !reflect.DeepEqual(gotResp, tt.wantResp) { 207 t.Errorf("ClearOutInvoice() gotResp = %v, want %v", gotResp, tt.wantResp) 208 } 209 }) 210 } 211 } 212 func TestQueryInvoceInfo(t *testing.T) { 213 mockResp := map[string][]byte{ 214 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 215 } 216 var resp []byte 217 test.MockSvrHandler.HandleFunc(apiQueryInvoceInfo, func(w http.ResponseWriter, r *http.Request) { 218 w.Write([]byte(resp)) 219 }) 220 221 type args struct { 222 ctx *offiaccount.OffiAccount 223 payload []byte 224 } 225 tests := []struct { 226 name string 227 args args 228 wantResp []byte 229 wantErr bool 230 }{ 231 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 232 } 233 for _, tt := range tests { 234 t.Run(tt.name, func(t *testing.T) { 235 resp = mockResp[tt.name] 236 gotResp, err := QueryInvoceInfo(tt.args.ctx, tt.args.payload) 237 //fmt.Println(string(gotResp), err) 238 if (err != nil) != tt.wantErr { 239 t.Errorf("QueryInvoceInfo() error = %v, wantErr %v", err, tt.wantErr) 240 return 241 } 242 if !reflect.DeepEqual(gotResp, tt.wantResp) { 243 t.Errorf("QueryInvoceInfo() gotResp = %v, want %v", gotResp, tt.wantResp) 244 } 245 }) 246 } 247 } 248 func TestSetUrl(t *testing.T) { 249 mockResp := map[string][]byte{ 250 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 251 } 252 var resp []byte 253 test.MockSvrHandler.HandleFunc(apiSetUrl, func(w http.ResponseWriter, r *http.Request) { 254 w.Write([]byte(resp)) 255 }) 256 257 type args struct { 258 ctx *offiaccount.OffiAccount 259 payload []byte 260 } 261 tests := []struct { 262 name string 263 args args 264 wantResp []byte 265 wantErr bool 266 }{ 267 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 268 } 269 for _, tt := range tests { 270 t.Run(tt.name, func(t *testing.T) { 271 resp = mockResp[tt.name] 272 gotResp, err := SetUrl(tt.args.ctx, tt.args.payload) 273 //fmt.Println(string(gotResp), err) 274 if (err != nil) != tt.wantErr { 275 t.Errorf("SetUrl() error = %v, wantErr %v", err, tt.wantErr) 276 return 277 } 278 if !reflect.DeepEqual(gotResp, tt.wantResp) { 279 t.Errorf("SetUrl() gotResp = %v, want %v", gotResp, tt.wantResp) 280 } 281 }) 282 } 283 } 284 func TestPlatformCreateCard(t *testing.T) { 285 mockResp := map[string][]byte{ 286 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 287 } 288 var resp []byte 289 test.MockSvrHandler.HandleFunc(apiPlatformCreateCard, func(w http.ResponseWriter, r *http.Request) { 290 w.Write([]byte(resp)) 291 }) 292 293 type args struct { 294 ctx *offiaccount.OffiAccount 295 payload []byte 296 } 297 tests := []struct { 298 name string 299 args args 300 wantResp []byte 301 wantErr bool 302 }{ 303 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 304 } 305 for _, tt := range tests { 306 t.Run(tt.name, func(t *testing.T) { 307 resp = mockResp[tt.name] 308 gotResp, err := PlatformCreateCard(tt.args.ctx, tt.args.payload) 309 //fmt.Println(string(gotResp), err) 310 if (err != nil) != tt.wantErr { 311 t.Errorf("PlatformCreateCard() error = %v, wantErr %v", err, tt.wantErr) 312 return 313 } 314 if !reflect.DeepEqual(gotResp, tt.wantResp) { 315 t.Errorf("PlatformCreateCard() gotResp = %v, want %v", gotResp, tt.wantResp) 316 } 317 }) 318 } 319 } 320 func TestPlatformSetpdf(t *testing.T) { 321 mockResp := map[string][]byte{ 322 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 323 } 324 var resp []byte 325 test.MockSvrHandler.HandleFunc(apiPlatformSetpdf, func(w http.ResponseWriter, r *http.Request) { 326 w.Write([]byte(resp)) 327 }) 328 329 type args struct { 330 ctx *offiaccount.OffiAccount 331 payload []byte 332 } 333 tests := []struct { 334 name string 335 args args 336 wantResp []byte 337 wantErr bool 338 }{ 339 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 340 } 341 for _, tt := range tests { 342 t.Run(tt.name, func(t *testing.T) { 343 resp = mockResp[tt.name] 344 gotResp, err := PlatformSetpdf(tt.args.ctx, tt.args.payload) 345 //fmt.Println(string(gotResp), err) 346 if (err != nil) != tt.wantErr { 347 t.Errorf("PlatformSetpdf() error = %v, wantErr %v", err, tt.wantErr) 348 return 349 } 350 if !reflect.DeepEqual(gotResp, tt.wantResp) { 351 t.Errorf("PlatformSetpdf() gotResp = %v, want %v", gotResp, tt.wantResp) 352 } 353 }) 354 } 355 } 356 func TestPlatformGetpdf(t *testing.T) { 357 mockResp := map[string][]byte{ 358 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 359 } 360 var resp []byte 361 test.MockSvrHandler.HandleFunc(apiPlatformGetpdf, func(w http.ResponseWriter, r *http.Request) { 362 w.Write([]byte(resp)) 363 }) 364 365 type args struct { 366 ctx *offiaccount.OffiAccount 367 payload []byte 368 } 369 tests := []struct { 370 name string 371 args args 372 wantResp []byte 373 wantErr bool 374 }{ 375 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 376 } 377 for _, tt := range tests { 378 t.Run(tt.name, func(t *testing.T) { 379 resp = mockResp[tt.name] 380 gotResp, err := PlatformGetpdf(tt.args.ctx, tt.args.payload) 381 //fmt.Println(string(gotResp), err) 382 if (err != nil) != tt.wantErr { 383 t.Errorf("PlatformGetpdf() error = %v, wantErr %v", err, tt.wantErr) 384 return 385 } 386 if !reflect.DeepEqual(gotResp, tt.wantResp) { 387 t.Errorf("PlatformGetpdf() gotResp = %v, want %v", gotResp, tt.wantResp) 388 } 389 }) 390 } 391 } 392 func TestInsert(t *testing.T) { 393 mockResp := map[string][]byte{ 394 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 395 } 396 var resp []byte 397 test.MockSvrHandler.HandleFunc(apiInsert, func(w http.ResponseWriter, r *http.Request) { 398 w.Write([]byte(resp)) 399 }) 400 401 type args struct { 402 ctx *offiaccount.OffiAccount 403 payload []byte 404 } 405 tests := []struct { 406 name string 407 args args 408 wantResp []byte 409 wantErr bool 410 }{ 411 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 412 } 413 for _, tt := range tests { 414 t.Run(tt.name, func(t *testing.T) { 415 resp = mockResp[tt.name] 416 gotResp, err := Insert(tt.args.ctx, tt.args.payload) 417 //fmt.Println(string(gotResp), err) 418 if (err != nil) != tt.wantErr { 419 t.Errorf("Insert() error = %v, wantErr %v", err, tt.wantErr) 420 return 421 } 422 if !reflect.DeepEqual(gotResp, tt.wantResp) { 423 t.Errorf("Insert() gotResp = %v, want %v", gotResp, tt.wantResp) 424 } 425 }) 426 } 427 } 428 func TestPlatformUpdateStatus(t *testing.T) { 429 mockResp := map[string][]byte{ 430 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 431 } 432 var resp []byte 433 test.MockSvrHandler.HandleFunc(apiPlatformUpdateStatus, func(w http.ResponseWriter, r *http.Request) { 434 w.Write([]byte(resp)) 435 }) 436 437 type args struct { 438 ctx *offiaccount.OffiAccount 439 payload []byte 440 } 441 tests := []struct { 442 name string 443 args args 444 wantResp []byte 445 wantErr bool 446 }{ 447 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 448 } 449 for _, tt := range tests { 450 t.Run(tt.name, func(t *testing.T) { 451 resp = mockResp[tt.name] 452 gotResp, err := PlatformUpdateStatus(tt.args.ctx, tt.args.payload) 453 //fmt.Println(string(gotResp), err) 454 if (err != nil) != tt.wantErr { 455 t.Errorf("PlatformUpdateStatus() error = %v, wantErr %v", err, tt.wantErr) 456 return 457 } 458 if !reflect.DeepEqual(gotResp, tt.wantResp) { 459 t.Errorf("PlatformUpdateStatus() gotResp = %v, want %v", gotResp, tt.wantResp) 460 } 461 }) 462 } 463 } 464 func TestReimburseGetInvoiceInfo(t *testing.T) { 465 mockResp := map[string][]byte{ 466 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 467 } 468 var resp []byte 469 test.MockSvrHandler.HandleFunc(apiReimburseGetInvoiceInfo, func(w http.ResponseWriter, r *http.Request) { 470 w.Write([]byte(resp)) 471 }) 472 473 type args struct { 474 ctx *offiaccount.OffiAccount 475 payload []byte 476 } 477 tests := []struct { 478 name string 479 args args 480 wantResp []byte 481 wantErr bool 482 }{ 483 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 484 } 485 for _, tt := range tests { 486 t.Run(tt.name, func(t *testing.T) { 487 resp = mockResp[tt.name] 488 gotResp, err := ReimburseGetInvoiceInfo(tt.args.ctx, tt.args.payload) 489 //fmt.Println(string(gotResp), err) 490 if (err != nil) != tt.wantErr { 491 t.Errorf("ReimburseGetInvoiceInfo() error = %v, wantErr %v", err, tt.wantErr) 492 return 493 } 494 if !reflect.DeepEqual(gotResp, tt.wantResp) { 495 t.Errorf("ReimburseGetInvoiceInfo() gotResp = %v, want %v", gotResp, tt.wantResp) 496 } 497 }) 498 } 499 } 500 func TestReimburseGetInvoiceBatch(t *testing.T) { 501 mockResp := map[string][]byte{ 502 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 503 } 504 var resp []byte 505 test.MockSvrHandler.HandleFunc(apiReimburseGetInvoiceBatch, func(w http.ResponseWriter, r *http.Request) { 506 w.Write([]byte(resp)) 507 }) 508 509 type args struct { 510 ctx *offiaccount.OffiAccount 511 payload []byte 512 } 513 tests := []struct { 514 name string 515 args args 516 wantResp []byte 517 wantErr bool 518 }{ 519 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 520 } 521 for _, tt := range tests { 522 t.Run(tt.name, func(t *testing.T) { 523 resp = mockResp[tt.name] 524 gotResp, err := ReimburseGetInvoiceBatch(tt.args.ctx, tt.args.payload) 525 //fmt.Println(string(gotResp), err) 526 if (err != nil) != tt.wantErr { 527 t.Errorf("ReimburseGetInvoiceBatch() error = %v, wantErr %v", err, tt.wantErr) 528 return 529 } 530 if !reflect.DeepEqual(gotResp, tt.wantResp) { 531 t.Errorf("ReimburseGetInvoiceBatch() gotResp = %v, want %v", gotResp, tt.wantResp) 532 } 533 }) 534 } 535 } 536 func TestReimburseUpdateInvoiceStatus(t *testing.T) { 537 mockResp := map[string][]byte{ 538 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 539 } 540 var resp []byte 541 test.MockSvrHandler.HandleFunc(apiReimburseUpdateInvoiceStatus, func(w http.ResponseWriter, r *http.Request) { 542 w.Write([]byte(resp)) 543 }) 544 545 type args struct { 546 ctx *offiaccount.OffiAccount 547 payload []byte 548 } 549 tests := []struct { 550 name string 551 args args 552 wantResp []byte 553 wantErr bool 554 }{ 555 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 556 } 557 for _, tt := range tests { 558 t.Run(tt.name, func(t *testing.T) { 559 resp = mockResp[tt.name] 560 gotResp, err := ReimburseUpdateInvoiceStatus(tt.args.ctx, tt.args.payload) 561 //fmt.Println(string(gotResp), err) 562 if (err != nil) != tt.wantErr { 563 t.Errorf("ReimburseUpdateInvoiceStatus() error = %v, wantErr %v", err, tt.wantErr) 564 return 565 } 566 if !reflect.DeepEqual(gotResp, tt.wantResp) { 567 t.Errorf("ReimburseUpdateInvoiceStatus() gotResp = %v, want %v", gotResp, tt.wantResp) 568 } 569 }) 570 } 571 } 572 func TestReimburseUpdateStatusBatch(t *testing.T) { 573 mockResp := map[string][]byte{ 574 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 575 } 576 var resp []byte 577 test.MockSvrHandler.HandleFunc(apiReimburseUpdateStatusBatch, func(w http.ResponseWriter, r *http.Request) { 578 w.Write([]byte(resp)) 579 }) 580 581 type args struct { 582 ctx *offiaccount.OffiAccount 583 payload []byte 584 } 585 tests := []struct { 586 name string 587 args args 588 wantResp []byte 589 wantErr bool 590 }{ 591 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 592 } 593 for _, tt := range tests { 594 t.Run(tt.name, func(t *testing.T) { 595 resp = mockResp[tt.name] 596 gotResp, err := ReimburseUpdateStatusBatch(tt.args.ctx, tt.args.payload) 597 //fmt.Println(string(gotResp), err) 598 if (err != nil) != tt.wantErr { 599 t.Errorf("ReimburseUpdateStatusBatch() error = %v, wantErr %v", err, tt.wantErr) 600 return 601 } 602 if !reflect.DeepEqual(gotResp, tt.wantResp) { 603 t.Errorf("ReimburseUpdateStatusBatch() gotResp = %v, want %v", gotResp, tt.wantResp) 604 } 605 }) 606 } 607 } 608 func TestGetUserTitleUrl(t *testing.T) { 609 mockResp := map[string][]byte{ 610 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 611 } 612 var resp []byte 613 test.MockSvrHandler.HandleFunc(apiGetUserTitleUrl, func(w http.ResponseWriter, r *http.Request) { 614 w.Write([]byte(resp)) 615 }) 616 617 type args struct { 618 ctx *offiaccount.OffiAccount 619 payload []byte 620 } 621 tests := []struct { 622 name string 623 args args 624 wantResp []byte 625 wantErr bool 626 }{ 627 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 628 } 629 for _, tt := range tests { 630 t.Run(tt.name, func(t *testing.T) { 631 resp = mockResp[tt.name] 632 gotResp, err := GetUserTitleUrl(tt.args.ctx, tt.args.payload) 633 //fmt.Println(string(gotResp), err) 634 if (err != nil) != tt.wantErr { 635 t.Errorf("GetUserTitleUrl() error = %v, wantErr %v", err, tt.wantErr) 636 return 637 } 638 if !reflect.DeepEqual(gotResp, tt.wantResp) { 639 t.Errorf("GetUserTitleUrl() gotResp = %v, want %v", gotResp, tt.wantResp) 640 } 641 }) 642 } 643 } 644 func TestGetSelectTitleUrl(t *testing.T) { 645 mockResp := map[string][]byte{ 646 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 647 } 648 var resp []byte 649 test.MockSvrHandler.HandleFunc(apiGetSelectTitleUrl, func(w http.ResponseWriter, r *http.Request) { 650 w.Write([]byte(resp)) 651 }) 652 653 type args struct { 654 ctx *offiaccount.OffiAccount 655 payload []byte 656 } 657 tests := []struct { 658 name string 659 args args 660 wantResp []byte 661 wantErr bool 662 }{ 663 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 664 } 665 for _, tt := range tests { 666 t.Run(tt.name, func(t *testing.T) { 667 resp = mockResp[tt.name] 668 gotResp, err := GetSelectTitleUrl(tt.args.ctx, tt.args.payload) 669 //fmt.Println(string(gotResp), err) 670 if (err != nil) != tt.wantErr { 671 t.Errorf("GetSelectTitleUrl() error = %v, wantErr %v", err, tt.wantErr) 672 return 673 } 674 if !reflect.DeepEqual(gotResp, tt.wantResp) { 675 t.Errorf("GetSelectTitleUrl() gotResp = %v, want %v", gotResp, tt.wantResp) 676 } 677 }) 678 } 679 } 680 func TestScanTitle(t *testing.T) { 681 mockResp := map[string][]byte{ 682 "case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"), 683 } 684 var resp []byte 685 test.MockSvrHandler.HandleFunc(apiScanTitle, func(w http.ResponseWriter, r *http.Request) { 686 w.Write([]byte(resp)) 687 }) 688 689 type args struct { 690 ctx *offiaccount.OffiAccount 691 payload []byte 692 } 693 tests := []struct { 694 name string 695 args args 696 wantResp []byte 697 wantErr bool 698 }{ 699 {name: "case1", args: args{ctx: test.MockOffiAccount}, wantResp: mockResp["case1"], wantErr: false}, 700 } 701 for _, tt := range tests { 702 t.Run(tt.name, func(t *testing.T) { 703 resp = mockResp[tt.name] 704 gotResp, err := ScanTitle(tt.args.ctx, tt.args.payload) 705 //fmt.Println(string(gotResp), err) 706 if (err != nil) != tt.wantErr { 707 t.Errorf("ScanTitle() error = %v, wantErr %v", err, tt.wantErr) 708 return 709 } 710 if !reflect.DeepEqual(gotResp, tt.wantResp) { 711 t.Errorf("ScanTitle() gotResp = %v, want %v", gotResp, tt.wantResp) 712 } 713 }) 714 } 715 }