woodpecker/store/datastore/logs_test.go

61 lines
1.2 KiB
Go
Raw Normal View History

package datastore
2015-09-30 01:21:17 +00:00
import (
"bytes"
"io/ioutil"
"testing"
"github.com/drone/drone/model"
2015-09-30 01:21:17 +00:00
"github.com/franela/goblin"
)
func Test_logstore(t *testing.T) {
db := openTest()
2015-09-30 01:21:17 +00:00
defer db.Close()
s := From(db)
2015-09-30 01:21:17 +00:00
g := goblin.Goblin(t)
g.Describe("Logs", func() {
// before each test be sure to purge the package
// table data from the database.
g.BeforeEach(func() {
db.Exec("DELETE FROM logs")
})
g.It("Should create a log", func() {
job := model.Job{
2015-09-30 01:21:17 +00:00
ID: 1,
}
buf := bytes.NewBufferString("echo hi")
err := s.Logs().Write(&job, buf)
2015-09-30 01:21:17 +00:00
g.Assert(err == nil).IsTrue()
rc, err := s.Logs().Read(&job)
2015-09-30 01:21:17 +00:00
g.Assert(err == nil).IsTrue()
defer rc.Close()
out, _ := ioutil.ReadAll(rc)
g.Assert(string(out)).Equal("echo hi")
})
g.It("Should update a log", func() {
job := model.Job{
2015-09-30 01:21:17 +00:00
ID: 1,
}
buf1 := bytes.NewBufferString("echo hi")
buf2 := bytes.NewBufferString("echo allo?")
err1 := s.Logs().Write(&job, buf1)
err2 := s.Logs().Write(&job, buf2)
2015-09-30 01:21:17 +00:00
g.Assert(err1 == nil).IsTrue()
g.Assert(err2 == nil).IsTrue()
rc, err := s.Logs().Read(&job)
2015-09-30 01:21:17 +00:00
g.Assert(err == nil).IsTrue()
defer rc.Close()
out, _ := ioutil.ReadAll(rc)
g.Assert(string(out)).Equal("echo allo?")
})
})
}