fix: unittest

This commit is contained in:
xucong053
2022-05-20 15:03:37 +08:00
parent 584d7aeea0
commit 9b429e91c9
10 changed files with 23 additions and 11 deletions

View File

@@ -27,6 +27,7 @@ const (
type ProjectInfo struct {
ProjectName string `json:"project_name,omitempty" yaml:"project_name,omitempty"`
ProjectPath string `json:"project_path,omitempty" yaml:"project_path,omitempty"`
CreateTime time.Time `json:"create_time,omitempty" yaml:"create_time,omitempty"`
Version string `json:"hrp_version,omitempty" yaml:"hrp_version,omitempty"`
}
@@ -76,6 +77,12 @@ func CreateScaffold(projectName string, pluginType PluginType, force bool) error
os.RemoveAll(projectName)
}
// get project abs path
projectPath, err := filepath.Abs(projectName)
if err != nil {
projectPath = projectName
}
// create project folders
if err := builtin.CreateFolder(projectName); err != nil {
return err
@@ -98,12 +105,16 @@ func CreateScaffold(projectName string, pluginType PluginType, force bool) error
projectInfo := &ProjectInfo{
ProjectName: projectName,
ProjectPath: projectPath,
CreateTime: time.Now(),
Version: version.VERSION,
}
// dump project information to file
err := builtin.Dump2JSON(projectInfo, filepath.Join(projectName, "proj.json"))
err = builtin.Dump2JSON(projectInfo, filepath.Join(projectName, "proj.json"))
if err != nil {
return err
}
// create .gitignore
err = CopyFile("templates/gitignore", filepath.Join(projectName, ".gitignore"))

View File

@@ -207,7 +207,7 @@ func TestLoadTestCases(t *testing.T) {
if !assert.Nil(t, err) {
t.Fatal()
}
if !assert.Equal(t, len(testCases), 4) {
if !assert.Equal(t, 4, len(testCases)) {
t.Fatal()
}

View File

@@ -287,8 +287,8 @@ func LoadTestCases(iTestCases ...ITestCase) ([]*TestCase, error) {
testCasePath := TestCasePath(path)
tc, err := testCasePath.ToTestCase()
if err != nil {
log.Error().Err(err).Str("path", path).Msg("load testcase failed")
return errors.Wrap(err, "load testcase failed")
log.Warn().Err(err).Str("path", path).Msg("load testcase failed")
return nil
}
testCases = append(testCases, tc)
return nil