package utils import ( "crypto/rsa" "reflect" "testing" ) func TestMchConfig_Request(t *testing.T) { type fields struct { mchId string certificateSerialNo string privateKeyFilePath string wechatPayPublicKeyId string wechatPayPublicKeyFilePath string privateKey *rsa.PrivateKey wechatPayPublicKey *rsa.PublicKey } type args struct { host string method string path string reqBody []byte } tests := []struct { name string fields fields args args wantResponse []byte wantErr bool }{ { name: "test", fields: fields{ mchId: "1652322442", certificateSerialNo: "certificateSerialNo", privateKeyFilePath: "privateKeyFilePath", wechatPayPublicKeyId: "wechatPayPublicKeyId", wechatPayPublicKeyFilePath: "wechatPayPublicKeyFilePath", }, args: args{ host: "https://api.mch.weixin.qq.com", }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { srv := &MchConfig{ mchId: tt.fields.mchId, certificateSerialNo: tt.fields.certificateSerialNo, privateKeyFilePath: tt.fields.privateKeyFilePath, wechatPayPublicKeyId: tt.fields.wechatPayPublicKeyId, wechatPayPublicKeyFilePath: tt.fields.wechatPayPublicKeyFilePath, privateKey: tt.fields.privateKey, wechatPayPublicKey: tt.fields.wechatPayPublicKey, } gotResponse, err := srv.Request(tt.args.host, tt.args.method, tt.args.path, tt.args.reqBody) if (err != nil) != tt.wantErr { t.Errorf("Request() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(gotResponse, tt.wantResponse) { t.Errorf("Request() gotResponse = %v, want %v", gotResponse, tt.wantResponse) } }) } }