woodpecker/store/datastore/nodes_test.go

102 lines
2.3 KiB
Go
Raw Normal View History

package datastore
2015-09-30 01:21:17 +00:00
import (
"testing"
"github.com/drone/drone/model"
2015-09-30 01:21:17 +00:00
"github.com/franela/goblin"
)
func TestNodes(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("Nodes", func() {
// before each test be sure to purge the package
// table data from the database.
g.BeforeEach(func() {
db.Exec("DELETE FROM nodes")
})
g.It("Should create a node", func() {
node := model.Node{
2015-09-30 01:21:17 +00:00
Addr: "unix:///var/run/docker/docker.sock",
Arch: "linux_amd64",
}
err := s.CreateNode(&node)
2015-09-30 01:21:17 +00:00
g.Assert(err == nil).IsTrue()
g.Assert(node.ID != 0).IsTrue()
})
g.It("Should update a node", func() {
node := model.Node{
2015-09-30 01:21:17 +00:00
Addr: "unix:///var/run/docker/docker.sock",
Arch: "linux_amd64",
}
err := s.CreateNode(&node)
2015-09-30 01:21:17 +00:00
g.Assert(err == nil).IsTrue()
g.Assert(node.ID != 0).IsTrue()
node.Addr = "unix:///var/run/docker.sock"
err1 := s.UpdateNode(&node)
getnode, err2 := s.GetNode(node.ID)
2015-09-30 01:21:17 +00:00
g.Assert(err1 == nil).IsTrue()
g.Assert(err2 == nil).IsTrue()
g.Assert(node.ID).Equal(getnode.ID)
g.Assert(node.Addr).Equal(getnode.Addr)
g.Assert(node.Arch).Equal(getnode.Arch)
})
g.It("Should get a node", func() {
node := model.Node{
2015-09-30 01:21:17 +00:00
Addr: "unix:///var/run/docker/docker.sock",
Arch: "linux_amd64",
}
err := s.CreateNode(&node)
2015-09-30 01:21:17 +00:00
g.Assert(err == nil).IsTrue()
g.Assert(node.ID != 0).IsTrue()
getnode, err := s.GetNode(node.ID)
2015-09-30 01:21:17 +00:00
g.Assert(err == nil).IsTrue()
g.Assert(node.ID).Equal(getnode.ID)
g.Assert(node.Addr).Equal(getnode.Addr)
g.Assert(node.Arch).Equal(getnode.Arch)
})
g.It("Should get a node list", func() {
node1 := model.Node{
2015-09-30 01:21:17 +00:00
Addr: "unix:///var/run/docker/docker.sock",
Arch: "linux_amd64",
}
node2 := model.Node{
2015-09-30 01:21:17 +00:00
Addr: "unix:///var/run/docker.sock",
Arch: "linux_386",
}
s.CreateNode(&node1)
s.CreateNode(&node2)
2015-09-30 01:21:17 +00:00
nodes, err := s.GetNodeList()
2015-09-30 01:21:17 +00:00
g.Assert(err == nil).IsTrue()
g.Assert(len(nodes)).Equal(2)
})
g.It("Should delete a node", func() {
node := model.Node{
2015-09-30 01:21:17 +00:00
Addr: "unix:///var/run/docker/docker.sock",
Arch: "linux_amd64",
}
err1 := s.CreateNode(&node)
err2 := s.DeleteNode(&node)
2015-09-30 01:21:17 +00:00
g.Assert(err1 == nil).IsTrue()
g.Assert(err2 == nil).IsTrue()
_, err := s.GetNode(node.ID)
2015-09-30 01:21:17 +00:00
g.Assert(err == nil).IsFalse()
})
})
}