-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.go
59 lines (51 loc) · 1.52 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package action
import (
"context"
"github.com/pkg/errors"
"projectforge.dev/projectforge/app/lib/filesystem"
"projectforge.dev/projectforge/app/util"
)
func onTest(ctx context.Context, params *Params) *Result {
methodName := params.Cfg.GetStringOpt("method")
params.Logger.Infof("running test method [%s]...", methodName)
switch methodName {
case "":
return errorResult(errors.New("must provide test method"), TypeTest, params.Cfg, params.Logger)
case "bootstrap":
return bootstrap(ctx, params)
default:
return errorResult(errors.Errorf("invalid test method [%s]", methodName), TypeTest, params.Cfg, params.Logger)
}
}
func bootstrap(ctx context.Context, params *Params) *Result {
params.Cfg.Add(
"path", "./testproject",
"name", "Test Project",
"summary", "A Test Project!",
"package", "projectforge.dev/projectforge/testproject",
"homepage", "https://projectforge.dev",
)
err := wipeIfNeeded(params.Cfg, params.Logger)
if err != nil {
return errorResult(err, TypeTest, params.Cfg, params.Logger)
}
return onCreate(ctx, params)
}
func wipeIfNeeded(cfg util.ValueMap, logger util.Logger) error {
shouldWipe, _ := cfg.ParseBool("wipe", true, true)
if shouldWipe {
fs, err := filesystem.NewFileSystem(".", false, "")
if err != nil {
return err
}
path := cfg.GetStringOpt("path")
if path == "" {
return errors.New("must provide [path] as an argument")
}
if fs.Exists(path) {
logger.Infof("removing existing directory [%s]", path)
_ = fs.RemoveRecursive(path, logger)
}
}
return nil
}