Skip to content

Commit

Permalink
edit: edit server_test.go
Browse files Browse the repository at this point in the history
增加单元测试
Test_server_key
Test_server_uploadObject
  • Loading branch information
Zherphy committed Dec 12, 2024
1 parent 41e3611 commit f25311d
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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)
})
}
Expand Down

0 comments on commit f25311d

Please sign in to comment.