Skip to content

Commit

Permalink
尝试将测试用例使用到的测试数据独立到独立的项目(ChineseSubFinder-TestData)中,然后通过统一的调用方式去拿到对应的…
Browse files Browse the repository at this point in the history
…测试数据的路径

Signed-off-by: allan716 <525223688@qq.com>
  • Loading branch information
allanpk716 committed Jan 5, 2022
1 parent 6cf46ea commit 21cfa0e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/pkg/sub_helper/dialogue_merger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package sub_helper
import (
"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"

// "github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_parser_hub"
"path/filepath"
Expand Down Expand Up @@ -57,7 +59,7 @@ func Test_isFirstLetterIsEngLower(t *testing.T) {

func TestNewDialogueMerger(t *testing.T) {

testRootDir := filepath.FromSlash("../../../TestData/FixTimeline")
testRootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"FixTimeline", "test"}, 4)

subParserHub := sub_parser_hub.NewSubParserHub(ass.NewParser(), srt.NewParser())
//bFind, infoBase, err := subParserHub.DetermineFileTypeFromFile(filepath.Join(testRootDir, "2line-The Card Counter (2021) WEBDL-1080p.chinese(inside).ass"))
Expand Down
26 changes: 26 additions & 0 deletions internal/pkg/unit_test_helper/unit_test_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package unit_test_helper

import (
"path/filepath"
)

// GetTestDataResourceRootPath 向上返回几层就能够到 ChineseSubFinder-TestData 同级目录,然后进入其中的 resourceFolderName 资源文件夹中
func GetTestDataResourceRootPath(resourceFolderNames []string, goBackTimes int) string {

times := ""
for i := 0; i < goBackTimes; i++ {
times += oneBackTime
}
outPath := times + testResourceProjectName

for _, name := range resourceFolderNames {
outPath += "/" + name
}

outPath = filepath.FromSlash(outPath)

return outPath
}

const oneBackTime = "../"
const testResourceProjectName = "ChineseSubFinder-TestData"
40 changes: 40 additions & 0 deletions internal/pkg/unit_test_helper/unit_test_helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package unit_test_helper

import (
"path/filepath"
"testing"
)

func TestGetTestDataResourceRootPath(t *testing.T) {
type args struct {
resourceFolderNames []string
goBackTimes int
}
tests := []struct {
name string
args args
want string
}{
{
name: "loghelper", args: args{
resourceFolderNames: []string{"log_helper"},
goBackTimes: 1,
},
want: filepath.FromSlash("../ChineseSubFinder-TestData/log_helper"),
},
{
name: "language", args: args{
resourceFolderNames: []string{"language", "test"},
goBackTimes: 1,
},
want: filepath.FromSlash("../ChineseSubFinder-TestData/language/test"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetTestDataResourceRootPath(tt.args.resourceFolderNames, tt.args.goBackTimes); got != tt.want {
t.Errorf("GetTestDataResourceRootPath() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 21cfa0e

Please sign in to comment.