func Test_Deis(t *testing.T) { g := goblin.Goblin(t) g.Describe("Deis Deploy", func() { g.It("Should set git.config", func() { b := new(buildfile.Buildfile) h := Deis{ App: "drone", Deisurl: "deis.yourdomain.com:2222", } h.Write(b) out := b.String() g.Assert(strings.Contains(out, CmdRevParse)).Equal(true) g.Assert(strings.Contains(out, CmdGlobalUser)).Equal(true) g.Assert(strings.Contains(out, CmdGlobalEmail)).Equal(true) }) g.It("Should add remote", func() { b := new(buildfile.Buildfile) h := Deis{ App: "drone", Deisurl: "deis.yourdomain.com:2222/", } h.Write(b) out := b.String() g.Assert(strings.Contains(out, "\ngit remote add deis ssh://[email protected]:2222/drone.git\n")).Equal(true) }) g.It("Should push to remote", func() { b := new(buildfile.Buildfile) d := Deis{ App: "drone", } d.Write(b) out := b.String() g.Assert(strings.Contains(out, "\ngit push deis $COMMIT:master\n")).Equal(true) }) g.It("Should force push to remote", func() { b := new(buildfile.Buildfile) h := Deis{ Force: true, App: "drone", } h.Write(b) out := b.String() g.Assert(strings.Contains(out, "\ngit add -A\n")).Equal(true) g.Assert(strings.Contains(out, "\ngit commit -m 'adding build artifacts'\n")).Equal(true) g.Assert(strings.Contains(out, "\ngit push deis HEAD:master --force\n")).Equal(true) }) }) }
func Test_Tsuru(t *testing.T) { g := goblin.Goblin(t) g.Describe("Tsuru Deploy", func() { g.It("Should set git.config", func() { b := new(buildfile.Buildfile) d := Tsuru{ Remote: "git://foo.com/bar/baz.git", } d.Write(b) out := b.String() g.Assert(strings.Contains(out, CmdRevParse)).Equal(true) g.Assert(strings.Contains(out, CmdGlobalUser)).Equal(true) g.Assert(strings.Contains(out, CmdGlobalEmail)).Equal(true) }) g.It("Should add remote", func() { b := new(buildfile.Buildfile) d := Tsuru{ Remote: "git://foo.com/bar/baz.git", } d.Write(b) out := b.String() g.Assert(strings.Contains(out, "\ngit remote add tsuru git://foo.com/bar/baz.git\n")).Equal(true) }) g.It("Should push to remote", func() { b := new(buildfile.Buildfile) d := Tsuru{ Remote: "git://foo.com/bar/baz.git", } d.Write(b) out := b.String() g.Assert(strings.Contains(out, "\ngit push tsuru $COMMIT:master\n")).Equal(true) }) g.It("Should force push to remote", func() { b := new(buildfile.Buildfile) d := Tsuru{ Force: true, Remote: "git://foo.com/bar/baz.git", } d.Write(b) out := b.String() g.Assert(strings.Contains(out, "\ngit add -A\n")).Equal(true) g.Assert(strings.Contains(out, "\ngit commit -m 'adding build artifacts'\n")).Equal(true) g.Assert(strings.Contains(out, "\ngit push tsuru HEAD:master --force\n")).Equal(true) }) }) }
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 modulus.io 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" `) }) }) }
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: "******", } 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: "******", Token: "bar", } n.Write(b) g.Assert(b.String()).Equal(`export username="******" 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 `) }) }) }
func Test_Git(t *testing.T) { g := goblin.Goblin(t) g.Describe("Git Deploy", func() { g.It("Should set git.config", func() { b := new(buildfile.Buildfile) d := Git{ Target: "git://foo.com/bar/baz.git", } d.Write(b) out := b.String() g.Assert(strings.Contains(out, CmdRevParse)).Equal(true) g.Assert(strings.Contains(out, CmdGlobalUser)).Equal(true) g.Assert(strings.Contains(out, CmdGlobalEmail)).Equal(true) }) g.It("Should add remote", func() { b := new(buildfile.Buildfile) d := Git{ Target: "git://foo.com/bar/baz.git", } d.Write(b) out := b.String() g.Assert(strings.Contains(out, "\ngit remote add deploy git://foo.com/bar/baz.git\n")).Equal(true) }) g.It("Should push to remote", func() { b := new(buildfile.Buildfile) d := Git{ Target: "git://foo.com/bar/baz.git", } d.Write(b) out := b.String() g.Assert(strings.Contains(out, "\ngit push deploy $COMMIT:master\n")).Equal(true) }) g.It("Should push to alternate branch", func() { b := new(buildfile.Buildfile) d := Git{ Branch: "foo", Target: "git://foo.com/bar/baz.git", } d.Write(b) out := b.String() g.Assert(strings.Contains(out, "\ngit push deploy $COMMIT:foo\n")).Equal(true) }) g.It("Should force push to remote", func() { b := new(buildfile.Buildfile) d := Git{ Force: true, Target: "git://foo.com/bar/baz.git", } d.Write(b) out := b.String() g.Assert(strings.Contains(out, "\ngit add -A\n")).Equal(true) g.Assert(strings.Contains(out, "\ngit commit -m 'add build artifacts'\n")).Equal(true) g.Assert(strings.Contains(out, "\ngit push deploy HEAD:master --force\n")).Equal(true) }) }) }
func Test_NPM(t *testing.T) { g := goblin.Goblin(t) g.Describe("NPM Publish", func() { g.BeforeEach(func() { var user, pass, email = "", "", "" DefaultEmail = &user DefaultUser = &pass DefaultPass = &email }) g.It("Should run publish", func() { b := new(buildfile.Buildfile) n := NPM{ Email: "*****@*****.**", Username: "******", Password: "******", Folder: "/path/to/repo", } n.Write(b) out := b.String() g.Assert(strings.Contains(out, "npm publish /path/to/repo\n")).Equal(true) g.Assert(strings.Contains(out, "\nnpm set")).Equal(false) g.Assert(strings.Contains(out, "\nnpm config set")).Equal(false) }) g.It("Should use current directory if folder is empty", func() { b := new(buildfile.Buildfile) n := NPM{ Email: "*****@*****.**", Username: "******", Password: "******", } n.Write(b) g.Assert(strings.Contains(b.String(), "npm publish .\n")).Equal(true) }) g.It("Should set tag", func() { b := new(buildfile.Buildfile) n := NPM{ Email: "*****@*****.**", Username: "******", Password: "******", Folder: "/path/to/repo", Tag: "1.0.0", } n.Write(b) g.Assert(strings.Contains(b.String(), "\n_NPM_PACKAGE_TAG=\"1.0.0\"\n")).Equal(true) g.Assert(strings.Contains(b.String(), "npm tag ${_NPM_PACKAGE_NAME} ${_NPM_PACKAGE_TAG}\n")).Equal(true) }) g.It("Should set registry", func() { b := new(buildfile.Buildfile) n := NPM{ Email: "*****@*****.**", Username: "******", Password: "******", Folder: "/path/to/repo", Registry: "https://npmjs.com", } n.Write(b) g.Assert(strings.Contains(b.String(), "\nnpm config set registry https://npmjs.com\n")).Equal(true) }) g.It("Should set always-auth", func() { b := new(buildfile.Buildfile) n := NPM{ Email: "*****@*****.**", Username: "******", Password: "******", Folder: "/path/to/repo", AlwaysAuth: true, } n.Write(b) g.Assert(strings.Contains(b.String(), CmdAlwaysAuth)).Equal(true) }) g.It("Should skip when no username or password", func() { b := new(buildfile.Buildfile) n := new(NPM) n.Write(b) g.Assert(b.String()).Equal("") }) g.It("Should use default username or password", func() { b := new(buildfile.Buildfile) n := new(NPM) expected := `cat <<EOF > ~/.npmrc _auth = $(echo "foo:bar" | tr -d "\r\n" | base64) email = [email protected] EOF` var user, pass, email string = "foo", "bar", "*****@*****.**" DefaultUser = &user DefaultPass = &pass DefaultEmail = &email n.Write(b) g.Assert(strings.Contains(b.String(), expected)).Equal(true) }) g.It("Should create npmrc", func() { b := new(buildfile.Buildfile) n := NPM{ Email: "*****@*****.**", Username: "******", Password: "******", Folder: "/path/to/repo", AlwaysAuth: true, } expected := `cat <<EOF > ~/.npmrc _auth = $(echo "foo:bar" | tr -d "\r\n" | base64) email = [email protected] EOF` n.Write(b) g.Assert(strings.Contains(b.String(), expected)).Equal(true) }) }) }
func Test_Heroku(t *testing.T) { g := goblin.Goblin(t) g.Describe("Heroku Deploy", func() { g.It("Should set git.config", func() { b := new(buildfile.Buildfile) h := Heroku{ App: "drone", } h.Write(b) out := b.String() g.Assert(strings.Contains(out, CmdRevParse)).Equal(true) g.Assert(strings.Contains(out, CmdGlobalUser)).Equal(true) g.Assert(strings.Contains(out, CmdGlobalEmail)).Equal(true) }) g.It("Should write token", func() { b := new(buildfile.Buildfile) h := Heroku{ App: "drone", Token: "mock-token", } h.Write(b) out := b.String() g.Assert(strings.Contains(out, "\necho 'machine git.heroku.com login _ password mock-token' >> ~/.netrc\n")).Equal(true) }) g.It("Should add remote", func() { b := new(buildfile.Buildfile) h := Heroku{ App: "drone", } h.Write(b) out := b.String() g.Assert(strings.Contains(out, "\ngit remote add heroku https://git.heroku.com/drone.git\n")).Equal(true) }) g.It("Should push to remote", func() { b := new(buildfile.Buildfile) d := Heroku{ App: "drone", } d.Write(b) out := b.String() g.Assert(strings.Contains(out, "\ngit push heroku $COMMIT:refs/heads/master\n")).Equal(true) }) g.It("Should force push to remote", func() { b := new(buildfile.Buildfile) h := Heroku{ Force: true, App: "drone", } h.Write(b) out := b.String() g.Assert(strings.Contains(out, "\ngit add -A\n")).Equal(true) g.Assert(strings.Contains(out, "\ngit commit -m 'adding build artifacts'\n")).Equal(true) g.Assert(strings.Contains(out, "\ngit push heroku HEAD:refs/heads/master --force\n")).Equal(true) }) }) }