moved modulus deploy to separate package with unit tests

This commit is contained in:
Brad Rydzewski 2014-10-11 19:20:47 -07:00
parent 5c13d6ba35
commit aac863b896
5 changed files with 105 additions and 13 deletions

View file

@ -2,25 +2,27 @@ package deploy
import (
"github.com/drone/drone/plugin/condition"
"github.com/drone/drone/plugin/deploy/git"
"github.com/drone/drone/plugin/deploy/heroku"
"github.com/drone/drone/plugin/deploy/tsuru"
"github.com/drone/drone/shared/build/buildfile"
"github.com/drone/drone/shared/build/repo"
"github.com/drone/drone/plugin/deploy/git"
"github.com/drone/drone/plugin/deploy/heroku"
"github.com/drone/drone/plugin/deploy/modulus"
"github.com/drone/drone/plugin/deploy/tsuru"
)
// Deploy stores the configuration details
// for deploying build artifacts when
// a Build has succeeded
type Deploy struct {
CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"`
Git *git.Git `yaml:"git,omitempty"`
Heroku *heroku.Heroku `yaml:"heroku,omitempty"`
Modulus *Modulus `yaml:"modulus,omitempty"`
Nodejitsu *Nodejitsu `yaml:"nodejitsu,omitempty"`
SSH *SSH `yaml:"ssh,omitempty"`
Tsuru *tsuru.Tsuru `yaml:"tsuru,omitempty"`
Bash *Bash `yaml:"bash,omitempty"`
CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"`
Git *git.Git `yaml:"git,omitempty"`
Heroku *heroku.Heroku `yaml:"heroku,omitempty"`
Modulus *modulus.Modulus `yaml:"modulus,omitempty"`
Nodejitsu *Nodejitsu `yaml:"nodejitsu,omitempty"`
SSH *SSH `yaml:"ssh,omitempty"`
Tsuru *tsuru.Tsuru `yaml:"tsuru,omitempty"`
Bash *Bash `yaml:"bash,omitempty"`
}
func (d *Deploy) Write(f *buildfile.Buildfile, r *repo.Repo) {

View file

@ -8,7 +8,7 @@ import (
"github.com/franela/goblin"
)
func Test_Git(t *testing.T) {
func Test_Heroku(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Heroku Deploy", func() {

View file

@ -0,0 +1,36 @@
package modulus
import (
"fmt"
"github.com/drone/drone/plugin/condition"
"github.com/drone/drone/shared/build/buildfile"
)
type Modulus struct {
Project string `yaml:"project,omitempty"`
Token string `yaml:"token,omitempty"`
Condition *condition.Condition `yaml:"when,omitempty"`
}
func (m *Modulus) Write(f *buildfile.Buildfile) {
if len(m.Token) == 0 || len(m.Project) == 0 {
return
}
f.WriteEnv("MODULUS_TOKEN", m.Token)
// Verify npm exists, otherwise we cannot install the
// modulus command line utility.
f.WriteCmdSilent("[ -f /usr/bin/npm ] || echo ERROR: npm is required for moduls deployments")
f.WriteCmdSilent("[ -f /usr/bin/npm ] || exit 1")
// Install the Modulus command line interface then deploy the configured
// project.
f.WriteCmdSilent("[ -f /usr/bin/sudo ] || npm install -g modulus")
f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo npm install -g modulus")
f.WriteCmd(fmt.Sprintf("modulus deploy -p %q", m.Project))
}
func (m *Modulus) GetCondition() *condition.Condition {
return m.Condition
}

View file

@ -0,0 +1,54 @@
package modulus
import (
//"strings"
"testing"
"github.com/drone/drone/shared/build/buildfile"
"github.com/franela/goblin"
)
func Test_Modulus(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Modulus Deploy", func() {
g.It("Requires a Project name", func() {
b := new(buildfile.Buildfile)
m := Modulus{
Project: "foo",
}
m.Write(b)
g.Assert(b.String()).Equal("")
})
g.It("Requires a Token", func() {
b := new(buildfile.Buildfile)
m := Modulus{
Token: "bar",
}
m.Write(b)
g.Assert(b.String()).Equal("")
})
g.It("Should execute deploy commands", func() {
b := new(buildfile.Buildfile)
m := Modulus{
Project: "foo",
Token: "bar",
}
m.Write(b)
g.Assert(b.String()).Equal(`export MODULUS_TOKEN=bar
[ -f /usr/bin/npm ] || echo ERROR: npm is required for moduls deployments
[ -f /usr/bin/npm ] || exit 1
[ -f /usr/bin/sudo ] || npm install -g modulus
[ -f /usr/bin/sudo ] && sudo npm install -g modulus
echo '#DRONE:6d6f64756c7573206465706c6f79202d702022666f6f22'
modulus deploy -p "foo"
`)
})
})
}

View file

@ -8,7 +8,7 @@ import (
"github.com/franela/goblin"
)
func Test_Git(t *testing.T) {
func Test_Tsuru(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Tsuru Deploy", func() {