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) 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") 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("nowatch") { b.Watch(targetDir) <-signalChan } log15.Info("Build.Close") } }
func TestBuildWatch(t *testing.T) { Convey("Build Watch", t, func() { opt.TplDir = "../template" opt.SrcDir = "./testdata" b := builder.New(opt) So(b.Error, ShouldBeNil) So(b.Context(), ShouldBeNil) b.Watch("testdata_dest") file := path.Join(opt.SrcDir, "test.md") ioutil.WriteFile(file, []byte("```ini"), os.ModePerm) time.Sleep(5 * time.Second) So(b.Context(), ShouldNotBeNil) So(b.Context().Error, ShouldNotBeNil) }) }
"path" "testing" "time" ) var ( opt = &builder.BuildOption{ SrcDir: "../source", TplDir: "../template", UploadDir: "../upload", Version: "0.0.0", VerDate: "2015-11-11", 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", }