2015-10-21 23:14:02 +00:00
|
|
|
package datastore
|
2015-09-30 01:21:17 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2015-10-21 23:14:02 +00:00
|
|
|
func Test_nodestore(t *testing.T) {
|
|
|
|
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("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() {
|
2015-10-21 23:14:02 +00:00
|
|
|
node := model.Node{
|
2015-09-30 01:21:17 +00:00
|
|
|
Addr: "unix:///var/run/docker/docker.sock",
|
|
|
|
Arch: "linux_amd64",
|
|
|
|
}
|
2015-10-21 23:14:02 +00:00
|
|
|
err := s.Nodes().Create(&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() {
|
2015-10-21 23:14:02 +00:00
|
|
|
node := model.Node{
|
2015-09-30 01:21:17 +00:00
|
|
|
Addr: "unix:///var/run/docker/docker.sock",
|
|
|
|
Arch: "linux_amd64",
|
|
|
|
}
|
2015-10-21 23:14:02 +00:00
|
|
|
err := s.Nodes().Create(&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"
|
|
|
|
|
2015-10-21 23:14:02 +00:00
|
|
|
err1 := s.Nodes().Update(&node)
|
|
|
|
getnode, err2 := s.Nodes().Get(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() {
|
2015-10-21 23:14:02 +00:00
|
|
|
node := model.Node{
|
2015-09-30 01:21:17 +00:00
|
|
|
Addr: "unix:///var/run/docker/docker.sock",
|
|
|
|
Arch: "linux_amd64",
|
|
|
|
}
|
2015-10-21 23:14:02 +00:00
|
|
|
err := s.Nodes().Create(&node)
|
2015-09-30 01:21:17 +00:00
|
|
|
g.Assert(err == nil).IsTrue()
|
|
|
|
g.Assert(node.ID != 0).IsTrue()
|
|
|
|
|
2015-10-21 23:14:02 +00:00
|
|
|
getnode, err := s.Nodes().Get(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() {
|
2015-10-21 23:14:02 +00:00
|
|
|
node1 := model.Node{
|
2015-09-30 01:21:17 +00:00
|
|
|
Addr: "unix:///var/run/docker/docker.sock",
|
|
|
|
Arch: "linux_amd64",
|
|
|
|
}
|
2015-10-21 23:14:02 +00:00
|
|
|
node2 := model.Node{
|
2015-09-30 01:21:17 +00:00
|
|
|
Addr: "unix:///var/run/docker.sock",
|
|
|
|
Arch: "linux_386",
|
|
|
|
}
|
2015-10-21 23:14:02 +00:00
|
|
|
s.Nodes().Create(&node1)
|
|
|
|
s.Nodes().Create(&node2)
|
2015-09-30 01:21:17 +00:00
|
|
|
|
2015-10-21 23:14:02 +00:00
|
|
|
nodes, err := s.Nodes().GetList()
|
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() {
|
2015-10-21 23:14:02 +00:00
|
|
|
node := model.Node{
|
2015-09-30 01:21:17 +00:00
|
|
|
Addr: "unix:///var/run/docker/docker.sock",
|
|
|
|
Arch: "linux_amd64",
|
|
|
|
}
|
2015-10-21 23:14:02 +00:00
|
|
|
err1 := s.Nodes().Create(&node)
|
|
|
|
err2 := s.Nodes().Delete(&node)
|
2015-09-30 01:21:17 +00:00
|
|
|
g.Assert(err1 == nil).IsTrue()
|
|
|
|
g.Assert(err2 == nil).IsTrue()
|
|
|
|
|
2015-10-21 23:14:02 +00:00
|
|
|
_, err := s.Nodes().Get(node.ID)
|
2015-09-30 01:21:17 +00:00
|
|
|
g.Assert(err == nil).IsFalse()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|