moved nodejitsu deploy to its own package with unit tests

This commit is contained in:
Brad Rydzewski 2014-10-11 19:32:31 -07:00
parent c4838dfaed
commit 89f8d17b8d
3 changed files with 93 additions and 8 deletions

View file

@ -8,6 +8,7 @@ import (
"github.com/drone/drone/plugin/deploy/git" "github.com/drone/drone/plugin/deploy/git"
"github.com/drone/drone/plugin/deploy/heroku" "github.com/drone/drone/plugin/deploy/heroku"
"github.com/drone/drone/plugin/deploy/modulus" "github.com/drone/drone/plugin/deploy/modulus"
"github.com/drone/drone/plugin/deploy/nodejitsu"
"github.com/drone/drone/plugin/deploy/tsuru" "github.com/drone/drone/plugin/deploy/tsuru"
) )
@ -19,7 +20,7 @@ type Deploy struct {
Git *git.Git `yaml:"git,omitempty"` Git *git.Git `yaml:"git,omitempty"`
Heroku *heroku.Heroku `yaml:"heroku,omitempty"` Heroku *heroku.Heroku `yaml:"heroku,omitempty"`
Modulus *modulus.Modulus `yaml:"modulus,omitempty"` Modulus *modulus.Modulus `yaml:"modulus,omitempty"`
Nodejitsu *Nodejitsu `yaml:"nodejitsu,omitempty"` Nodejitsu *nodejitsu.Nodejitsu `yaml:"nodejitsu,omitempty"`
SSH *SSH `yaml:"ssh,omitempty"` SSH *SSH `yaml:"ssh,omitempty"`
Tsuru *tsuru.Tsuru `yaml:"tsuru,omitempty"` Tsuru *tsuru.Tsuru `yaml:"tsuru,omitempty"`
Bash *Bash `yaml:"bash,omitempty"` Bash *Bash `yaml:"bash,omitempty"`

View file

@ -0,0 +1,32 @@
package nodejitsu
import (
"github.com/drone/drone/plugin/condition"
"github.com/drone/drone/shared/build/buildfile"
)
type Nodejitsu struct {
User string `yaml:"user,omitempty"`
Token string `yaml:"token,omitempty"`
Condition *condition.Condition `yaml:"when,omitempty"`
}
func (n *Nodejitsu) Write(f *buildfile.Buildfile) {
if len(n.Token) == 0 || len(n.User) == 0 {
return
}
f.WriteEnv("username", n.User)
f.WriteEnv("apiToken", n.Token)
// Install the jitsu command line interface then
// deploy the configured app.
f.WriteCmdSilent("[ -f /usr/bin/sudo ] || npm install -g jitsu")
f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo npm install -g jitsu")
f.WriteCmd("jitsu deploy")
}
func (n *Nodejitsu) GetCondition() *condition.Condition {
return n.Condition
}

View file

@ -0,0 +1,52 @@
package nodejitsu
import (
"testing"
"github.com/drone/drone/shared/build/buildfile"
"github.com/franela/goblin"
)
func Test_Modulus(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Nodejitsu Deploy", func() {
g.It("Requires a User", func() {
b := new(buildfile.Buildfile)
n := Nodejitsu{
User: "foo",
}
n.Write(b)
g.Assert(b.String()).Equal("")
})
g.It("Requires a Token", func() {
b := new(buildfile.Buildfile)
n := Nodejitsu{
Token: "bar",
}
n.Write(b)
g.Assert(b.String()).Equal("")
})
g.It("Should execute deploy commands", func() {
b := new(buildfile.Buildfile)
n := Nodejitsu{
User: "foo",
Token: "bar",
}
n.Write(b)
g.Assert(b.String()).Equal(`export username=foo
export apiToken=bar
[ -f /usr/bin/sudo ] || npm install -g jitsu
[ -f /usr/bin/sudo ] && sudo npm install -g jitsu
echo '#DRONE:6a69747375206465706c6f79'
jitsu deploy
`)
})
})
}