woodpecker/datastore/builtin/task_test.go

48 lines
1.1 KiB
Go
Raw Normal View History

package builtin
import (
"bytes"
"github.com/drone/drone/common"
. "github.com/franela/goblin"
"io/ioutil"
"os"
"testing"
)
func TestTask(t *testing.T) {
g := Goblin(t)
g.Describe("Tasks", func() {
2015-05-01 03:40:59 +00:00
testRepo := "octopod/hq"
testBuild := 1
testTask := 0
2015-05-01 03:40:59 +00:00
testLogInfo := []byte("Log Info for SetLogs()")
var db *DB // Temp database
// create a new database before each unit
// test and destroy afterwards.
g.BeforeEach(func() {
db = Must("/tmp/drone.test.db")
})
g.AfterEach(func() {
os.Remove(db.Path())
})
g.It("Should set Logs", func() {
db.SetRepo(&common.Repo{FullName: testRepo})
err := db.SetLogs(testRepo, testBuild, testTask, (bytes.NewBuffer(testLogInfo)))
g.Assert(err).Equal(nil)
})
2015-05-01 03:40:59 +00:00
g.It("Should get logs", func() {
db.SetRepo(&common.Repo{FullName: testRepo})
db.SetLogs(testRepo, testBuild, testTask, (bytes.NewBuffer(testLogInfo)))
2015-05-01 03:40:59 +00:00
buf, err := db.LogReader(testRepo, testBuild, testTask)
g.Assert(err).Equal(nil)
logInfo, err := ioutil.ReadAll(buf)
g.Assert(logInfo).Equal(testLogInfo)
})
})
}