func TestBuilderErrors(t *testing.T) { Convey("Build Errors", t, func() { opt.SrcDir = "../../xxxx" b2 := builder.New(opt) So(b2.Error, ShouldEqual, builder.ErrSrcDirMissing) opt.SrcDir = "../../source" opt.TplDir = "../../xxx" b2 = builder.New(opt) So(b2.Error, ShouldEqual, builder.ErrTplDirMissing) }) Convey("Build Fail", t, func() { opt.TplDir = "../../template" opt.SrcDir = "./testdata" b := builder.New(opt) So(b.Error, ShouldBeNil) b.Build("testdata_dest") So(b.Context().Error, ShouldNotBeNil) removeDirectory("testdata_dest") }) }
// build site function func buildSite(opt *builder.BuildOption, mustWatch bool) func(ctx *cli.Context) { return func(ctx *cli.Context) { // ctrl+C capture signalChan := make(chan os.Signal) signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM) opt.Theme = ctx.String("theme") b := builder.New(opt) if b.Error != nil { log15.Crit("Builder.Fail", "error", b.Error.Error()) } targetDir := ctx.String("dest") if targetDir == "template" || targetDir == "source" { log15.Crit("Builder.Fail", "error", "destination directory should not be 'template' or 'source'") } // detect deploy callback way, err := deploy.Detect(ctx) if err != nil { log15.Crit("Deploy.Fail", "error", err.Error()) } if way != nil { targetDir = way.Dir() opt.After(func(b *builder.Builder, ctx *builder.Context) error { t := time.Now() if err := way.Do(b, ctx); err != nil { return err } log15.Info("Deploy.Finish", "duration", time.Since(t)) return nil }) } // make directory log15.Info("Dest." + targetDir) if com.IsDir(targetDir) { log15.Warn("Dest." + targetDir + ".Existed") } // auto watching b.Build(targetDir) if err := b.Context().Error; err != nil { log15.Crit("Build.Fail", "error", err.Error()) } if ctx.Bool("watch") || mustWatch { b.Watch(targetDir) <-signalChan } log15.Info("Build.Close") } }
"github.com/Unknwon/com" "github.com/go-xiaohei/pugo-static/app/builder" . "github.com/smartystreets/goconvey/convey" ) var ( opt = &builder.BuildOption{ SrcDir: "../../source", TplDir: "../../template", MediaDir: "../../source/media", Version: "0.1.1", VerDate: "2015-12-22", Theme: "default", } target = "../../dest" b = builder.New(opt) shoudlExistDirs = []string{ "tags", "posts", "static", } shouldExistFiles = []string{ "index.html", "archive.html", "about.html", "feed.xml", "sitemap.xml", "favicon.ico", "tags/pugo.html", "posts/1.html", }