From f25311d0c9b59d463208f678b5a6115aae564f42 Mon Sep 17 00:00:00 2001 From: Zherphy <1123678689@qq.com> Date: Thu, 12 Dec 2024 14:15:32 +0800 Subject: [PATCH] edit: edit server_test.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加单元测试 Test_server_key Test_server_uploadObject --- server/server_test.go | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/server/server_test.go b/server/server_test.go index 8f466da..9e21934 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -9,6 +9,7 @@ import ( "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs" "github.com/metalogical/BigFiles/auth" "github.com/metalogical/BigFiles/batch" + "math" "net/http" "net/http/httptest" "reflect" @@ -572,7 +573,14 @@ func Test_server_key(t *testing.T) { args args want string }{ - // TODO: Add test cases. + { + name: "server key test success", + fields: serverInfo, + args: args{ + oid: "123456789", + }, + want: "Prefix123456789", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -596,12 +604,36 @@ func Test_server_uploadObject(t *testing.T) { in *batch.RequestObject out *batch.Object } + outWithLarge := batch.Object{ + OID: "123456789", + Size: 5 * int(math.Pow10(9)), + } + outObject := batch.Object{ + OID: "123456789", + Size: 1000, + } tests := []struct { - name string - fields ServerInfo - args args + name string + fields ServerInfo + args args + wantErr bool }{ - // TODO: Add test cases. + { + name: "server uploadObject size large than limit", + fields: serverInfo, + args: args{ + out: &outWithLarge, + }, + wantErr: false, + }, + { + name: "server upload size smaller than limit", + fields: serverInfo, + args: args{ + out: &outObject, + }, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -613,6 +645,7 @@ func Test_server_uploadObject(t *testing.T) { cdnDomain: tt.fields.cdnDomain, isAuthorized: tt.fields.isAuthorized, } + defer panicCheck(t, tt.wantErr) s.uploadObject(tt.args.in, tt.args.out) }) }