func TestBlobstore(t *testing.T) { db := datasql.MustConnect("sqlite3", ":memory:") bs := New(db) g := goblin.Goblin(t) g.Describe("Blobstore", func() { // before each test be sure to purge the blob // table data from the database. g.Before(func() { db.Exec("DELETE FROM blobs") }) g.It("Should Put a Blob", func() { err := bs.Put("foo", []byte("bar")) g.Assert(err == nil).IsTrue() }) g.It("Should Put a Blob reader", func() { var buf bytes.Buffer buf.Write([]byte("bar")) err := bs.PutReader("foo", &buf) g.Assert(err == nil).IsTrue() }) g.It("Should Overwrite a Blob", func() { bs.Put("foo", []byte("bar")) bs.Put("foo", []byte("baz")) blob, err := bs.Get("foo") g.Assert(err == nil).IsTrue() g.Assert(string(blob)).Equal("baz") }) g.It("Should Get a Blob", func() { bs.Put("foo", []byte("bar")) blob, err := bs.Get("foo") g.Assert(err == nil).IsTrue() g.Assert(string(blob)).Equal("bar") }) g.It("Should Get a Blob reader", func() { bs.Put("foo", []byte("bar")) r, _ := bs.GetReader("foo") blob, _ := ioutil.ReadAll(r) g.Assert(string(blob)).Equal("bar") }) g.It("Should Del a Blob", func() { bs.Put("foo", []byte("bar")) err := bs.Del("foo") g.Assert(err == nil).IsTrue() }) g.It("Should create a Context", func() { c := NewContext(context.Background(), db) b := blobstore.FromContext(c).(*Blobstore) g.Assert(b.DB).Equal(db) }) }) }
func main() { // parse flag variables flag.StringVar(&dockerhost, "docker-host", "", "") flag.StringVar(&dockercert, "docker-cert", "", "") flag.StringVar(&dockerkey, "docker-key", "", "") flag.StringVar(&password, "password", "admin:admin", "") flag.StringVar(&driver, "driver", "sqlite3", "") flag.StringVar(&datasource, "datasource", "pub.sqlite", "") flag.Parse() // Create the worker pool and director. workers = pool.New() worker = director.New() // Create the Docker worker is provided via // the commandline. Else it is expected that // workers are added via the REST endpoint. if len(dockerhost) != 0 { var d, err = docker.New(dockerhost, dockercert, dockerkey) if err != nil { fmt.Println("ERROR creating Docker client.", err) os.Exit(1) } workers.Allocate(d) } // Create the database connection db = datasql.MustConnect(driver, datasource) datasql.New(db).KillBuilds() // Parse the Template files templates := rice.MustFindBox("website") handler.BuildTempl = template.Must(template.New("_").Parse(templates.MustString("build.tmpl"))) handler.IndexTempl = template.Must(template.New("_").Parse(templates.MustString("index.tmpl"))) // Include static resources assets := http.FileServer(rice.MustFindBox("website").HTTPBox()) http.Handle("/static/", http.StripPrefix("/static", assets)) // Create the router and add middleware mux := router.New() mux.Use(handler.SetHeaders) mux.Use(secureMiddleware) mux.Use(contextMiddleware) http.Handle("/", mux) if err := http.ListenAndServe(":8000", nil); err != nil { fmt.Println("ERROR starting web server.", err) } }