tests: add examples with scaffold

This commit is contained in:
debugtalk
2022-03-27 12:00:09 +08:00
parent 98d154b654
commit cdabde4dc8
20 changed files with 1132 additions and 3 deletions

View File

@@ -0,0 +1,29 @@
package scaffold
import (
"os"
"testing"
)
func TestGenDemoExamples(t *testing.T) {
dir := "../../../examples/demo-with-go-plugin"
os.RemoveAll(dir)
err := CreateScaffold(dir, Go)
if err != nil {
t.Fail()
}
dir = "../../../examples/demo-with-py-plugin"
os.RemoveAll(dir)
err = CreateScaffold(dir, Py)
if err != nil {
t.Fail()
}
dir = "../../../examples/demo-without-plugin"
os.RemoveAll(dir)
err = CreateScaffold(dir, Ignore)
if err != nil {
t.Fail()
}
}

View File

@@ -68,12 +68,18 @@ func CreateScaffold(projectName string, pluginType PluginType) error {
if err := builtin.CreateFolder(filepath.Join(projectName, "har")); err != nil {
return err
}
if err := builtin.CreateFile(filepath.Join(projectName, "har", ".keep"), ""); err != nil {
return err
}
if err := builtin.CreateFolder(filepath.Join(projectName, "testcases")); err != nil {
return err
}
if err := builtin.CreateFolder(filepath.Join(projectName, "reports")); err != nil {
return err
}
if err := builtin.CreateFile(filepath.Join(projectName, "reports", ".keep"), ""); err != nil {
return err
}
// create .gitignore
err := CopyFile("templates/gitignore", filepath.Join(projectName, ".gitignore"))
@@ -88,8 +94,8 @@ func CreateScaffold(projectName string, pluginType PluginType) error {
// create demo testcases
if pluginType == Ignore {
err := CopyFile("templates/testcases/demo_without_plugin.json",
filepath.Join(projectName, "testcases", "demo_without_plugin.json"))
err := CopyFile("templates/testcases/demo_without_funplugin.json",
filepath.Join(projectName, "testcases", "demo_without_funplugin.json"))
if err != nil {
return err
}