Skip to content

Commit

Permalink
fix: modified unit testing in paper service
Browse files Browse the repository at this point in the history
  • Loading branch information
penqee committed Nov 28, 2024
1 parent 25b4513 commit 6b094d4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
21 changes: 19 additions & 2 deletions internal/paper/service/download_url_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
/*
Copyright 2024 The west2-online Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package service

import (
"context"
"testing"

"github.com/bytedance/mockey"
"github.com/stretchr/testify/assert"

"github.com/west2-online/fzuhelper-server/kitex_gen/paper"
"github.com/west2-online/fzuhelper-server/pkg/base"
"github.com/west2-online/fzuhelper-server/pkg/cache"
"github.com/west2-online/fzuhelper-server/pkg/upyun"
"github.com/west2-online/fzuhelper-server/pkg/utils"
"testing"
)

func TestGenerateDownloadUrl(t *testing.T) {
Expand Down Expand Up @@ -47,6 +65,5 @@ func TestGenerateDownloadUrl(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, tc.expectedResult, result)
})

}
}
24 changes: 19 additions & 5 deletions internal/paper/service/get_dir_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
/*
Copyright 2024 The west2-online Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package service

import (
"context"
"errors"
"testing"

"github.com/bytedance/mockey"
"github.com/stretchr/testify/assert"

"github.com/west2-online/fzuhelper-server/kitex_gen/model"
"github.com/west2-online/fzuhelper-server/kitex_gen/paper"
"github.com/west2-online/fzuhelper-server/pkg/base"
"github.com/west2-online/fzuhelper-server/pkg/cache"
paperCache "github.com/west2-online/fzuhelper-server/pkg/cache/paper"
"github.com/west2-online/fzuhelper-server/pkg/upyun"
"testing"
)

func TestGetDir(t *testing.T) {

type testCase struct {
name string // 用例名
// 控制返回值与mock函数行为
Expand Down Expand Up @@ -172,14 +189,11 @@ func TestGetDir(t *testing.T) {
}
assert.Equal(t, tc.expectedResult, result)
assert.Equal(t, tc.mockIsGetInfo, ret)

} else {
assert.Nil(t, err)
assert.Equal(t, tc.expectedResult, result)
assert.Equal(t, tc.mockIsGetInfo, ret)

}
})
}

}

0 comments on commit 6b094d4

Please sign in to comment.