2015-10-21 23:14:02 +00:00
|
|
|
package datastore
|
2015-09-30 01:21:17 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
2015-10-21 23:14:02 +00:00
|
|
|
"github.com/drone/drone/model"
|
2015-09-30 01:21:17 +00:00
|
|
|
"github.com/franela/goblin"
|
|
|
|
)
|
|
|
|
|
2016-03-25 19:54:16 +00:00
|
|
|
func TestLogs(t *testing.T) {
|
2015-10-21 23:14:02 +00:00
|
|
|
db := openTest()
|
2015-09-30 01:21:17 +00:00
|
|
|
defer db.Close()
|
|
|
|
|
2015-10-21 23:14:02 +00:00
|
|
|
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() {
|
2015-10-21 23:14:02 +00:00
|
|
|
job := model.Job{
|
2015-09-30 01:21:17 +00:00
|
|
|
ID: 1,
|
|
|
|
}
|
|
|
|
buf := bytes.NewBufferString("echo hi")
|
2016-03-25 19:54:16 +00:00
|
|
|
err := s.WriteLog(&job, buf)
|
2015-09-30 01:21:17 +00:00
|
|
|
g.Assert(err == nil).IsTrue()
|
|
|
|
|
2016-03-25 19:54:16 +00:00
|
|
|
rc, err := s.ReadLog(&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() {
|
2015-10-21 23:14:02 +00:00
|
|
|
job := model.Job{
|
2015-09-30 01:21:17 +00:00
|
|
|
ID: 1,
|
|
|
|
}
|
|
|
|
buf1 := bytes.NewBufferString("echo hi")
|
|
|
|
buf2 := bytes.NewBufferString("echo allo?")
|
2016-03-25 19:54:16 +00:00
|
|
|
err1 := s.WriteLog(&job, buf1)
|
|
|
|
err2 := s.WriteLog(&job, buf2)
|
2015-09-30 01:21:17 +00:00
|
|
|
g.Assert(err1 == nil).IsTrue()
|
|
|
|
g.Assert(err2 == nil).IsTrue()
|
|
|
|
|
2016-03-25 19:54:16 +00:00
|
|
|
rc, err := s.ReadLog(&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?")
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|