moved nodejitsu deploy to its own package with unit tests
This commit is contained in:
parent
c4838dfaed
commit
89f8d17b8d
3 changed files with 93 additions and 8 deletions
|
@ -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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,14 +16,14 @@ import (
|
||||||
// for deploying build artifacts when
|
// for deploying build artifacts when
|
||||||
// a Build has succeeded
|
// a Build has succeeded
|
||||||
type Deploy struct {
|
type Deploy struct {
|
||||||
CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"`
|
CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"`
|
||||||
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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Deploy) Write(f *buildfile.Buildfile, r *repo.Repo) {
|
func (d *Deploy) Write(f *buildfile.Buildfile, r *repo.Repo) {
|
||||||
|
|
32
plugin/deploy/nodejitsu/nodejitsu.go
Normal file
32
plugin/deploy/nodejitsu/nodejitsu.go
Normal 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
|
||||||
|
}
|
52
plugin/deploy/nodejitsu/nodejitsu_test.go
Normal file
52
plugin/deploy/nodejitsu/nodejitsu_test.go
Normal 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
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in a new issue