Skip to content

Commit

Permalink
Add deployment list instance
Browse files Browse the repository at this point in the history
Signed-off-by: Xabier Larrakoetxea <slok69@gmail.com>
  • Loading branch information
slok committed Jul 21, 2015
1 parent 494f226 commit 38c1678
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
28 changes: 16 additions & 12 deletions data/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,22 @@ func ListDeploymentsAsJson(namespace string) ([][]byte, error) {
return d, err
}

//func ListDeployments() ([]Deployment, error) {
// d := []Deployment{}
//
// err := db.Conn.View(func(tx *bolt.Tx) error {
// bucket, err := tx.Bucket([]byte(DeployBucketDbKey))
// if err != nil {
// return err
// }
//
// })
// return d, err
//}
func ListDeployments(namespace string) ([]Deployment, error) {
dJson, err := ListDeploymentsAsJson(namespace)
if err != nil {
return nil, err
}
ds := []Deployment{}
for _, i := range dJson {
d := &Deployment{}
err := json.Unmarshal(i, d)
if err != nil {
return nil, err
}
ds = append(ds, *d)
}
return ds, err
}

// Status represents the current status of a deployment
type Status struct {
Expand Down
24 changes: 24 additions & 0 deletions data/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,27 @@ func (s *DatabaseModelDeploymentSuite) TestDeploymentListAsJson(c *C) {
c.Assert(dj1.Task, Equals, "deploy")
c.Assert(dj2.Task, Equals, "deploy")
}

func (s *DatabaseModelDeploymentSuite) TestDeploymentList(c *C) {
for _, i := range s.deployments {
i.Save()
}
ds, _ := ListDeployments(s.deployments[0].Namespace)

c.Assert(len(ds), Equals, len(s.deployments))

c.Assert(ds[0].Id, Equals, int64(1))
c.Assert(ds[1].Id, Equals, int64(2))

c.Assert(ds[0].Sha, Equals, "d583d658d6da0b2f95ab3bcd27cd7d4bd93c3fc0")
c.Assert(ds[1].Sha, Equals, "980670afcebfd86727505b3061d8667195234816")

c.Assert(ds[0].Ref, Equals, "master")
c.Assert(ds[1].Ref, Equals, "fix-#4213")

c.Assert(ds[0].Environment, Equals, "production")
c.Assert(ds[1].Environment, Equals, "preproduction")

c.Assert(ds[0].Task, Equals, "deploy")
c.Assert(ds[1].Task, Equals, "deploy")
}

0 comments on commit 38c1678

Please sign in to comment.