-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
尝试将测试用例使用到的测试数据独立到独立的项目(ChineseSubFinder-TestData)中,然后通过统一的调用方式去拿到对应的…
…测试数据的路径 Signed-off-by: allan716 <525223688@qq.com>
- Loading branch information
1 parent
6cf46ea
commit 21cfa0e
Showing
3 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |