2015-10-22 01:14:02 +02:00
|
|
|
package datastore
|
2015-09-30 03:21:17 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
2015-10-22 01:14:02 +02:00
|
|
|
"github.com/drone/drone/model"
|
2015-09-30 03:21:17 +02:00
|
|
|
"github.com/franela/goblin"
|
|
|
|
)
|
|
|
|
|
2015-10-22 01:14:02 +02:00
|
|
|
func Test_logstore(t *testing.T) {
|
|
|
|
db := openTest()
|
2015-09-30 03:21:17 +02:00
|
|
|
defer db.Close()
|
|
|
|
|
2015-10-22 01:14:02 +02:00
|
|
|
s := From(db)
|
2015-09-30 03:21:17 +02: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-22 01:14:02 +02:00
|
|
|
job := model.Job{
|
2015-09-30 03:21:17 +02:00
|
|
|
ID: 1,
|
|
|
|
}
|
|
|
|
buf := bytes.NewBufferString("echo hi")
|
2015-10-22 01:14:02 +02:00
|
|
|
err := s.Logs().Write(&job, buf)
|
2015-09-30 03:21:17 +02:00
|
|
|
g.Assert(err == nil).IsTrue()
|
|
|
|
|
2015-10-22 01:14:02 +02:00
|
|
|
rc, err := s.Logs().Read(&job)
|
2015-09-30 03:21:17 +02: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-22 01:14:02 +02:00
|
|
|
job := model.Job{
|
2015-09-30 03:21:17 +02:00
|
|
|
ID: 1,
|
|
|
|
}
|
|
|
|
buf1 := bytes.NewBufferString("echo hi")
|
|
|
|
buf2 := bytes.NewBufferString("echo allo?")
|
2015-10-22 01:14:02 +02:00
|
|
|
err1 := s.Logs().Write(&job, buf1)
|
|
|
|
err2 := s.Logs().Write(&job, buf2)
|
2015-09-30 03:21:17 +02:00
|
|
|
g.Assert(err1 == nil).IsTrue()
|
|
|
|
g.Assert(err2 == nil).IsTrue()
|
|
|
|
|
2015-10-22 01:14:02 +02:00
|
|
|
rc, err := s.Logs().Read(&job)
|
2015-09-30 03:21:17 +02:00
|
|
|
g.Assert(err == nil).IsTrue()
|
|
|
|
defer rc.Close()
|
|
|
|
out, _ := ioutil.ReadAll(rc)
|
|
|
|
g.Assert(string(out)).Equal("echo allo?")
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|