Merge pull request #797 from mattbostock/go_fmt

Run gofmt and add test to prevent regressions
This commit is contained in:
Brad Rydzewski 2015-01-11 11:13:35 -08:00
commit ae65cf5fdb
9 changed files with 84 additions and 83 deletions

View file

@ -8,6 +8,7 @@ deps:
go get -t -v ./...
test:
@test -z "$(shell find . -name '*.go' | xargs gofmt -l)" || (echo "Need to run 'go fmt ./...'"; exit 1)
go vet ./...
go test -cover -short ./...

View file

@ -30,7 +30,7 @@ func restartCommandFunc(c *cli.Context, client *client.Client) error {
case 2:
branch = "master"
sha = args[1]
case 3,4,5:
case 3, 4, 5:
branch = args[1]
sha = args[2]
}

View file

@ -22,20 +22,20 @@ const (
// deisurl: deis.myurl.tdl:2222/
type Deis struct {
App string `yaml:"app,omitempty"`
Force bool `yaml:"force,omitempty"`
Deisurl string `yaml:"deisurl,omitempty"`
Condition *condition.Condition `yaml:"when,omitempty"`
App string `yaml:"app,omitempty"`
Force bool `yaml:"force,omitempty"`
Deisurl string `yaml:"deisurl,omitempty"`
Condition *condition.Condition `yaml:"when,omitempty"`
}
func (h *Deis) Write(f *buildfile.Buildfile) {
f.WriteCmdSilent(CmdRevParse)
f.WriteCmdSilent(CmdGlobalUser)
f.WriteCmdSilent(CmdGlobalEmail)
// git@deis.yourdomain.com:2222/drone.git
f.WriteCmd(fmt.Sprintf("git remote add deis ssh://git@%s%s.git", h.Deisurl , h.App))
f.WriteCmd(fmt.Sprintf("git remote add deis ssh://git@%s%s.git", h.Deisurl, h.App))
switch h.Force {
case true:

View file

@ -16,8 +16,8 @@ func Test_Deis(t *testing.T) {
g.It("Should set git.config", func() {
b := new(buildfile.Buildfile)
h := Deis{
App: "drone",
Deisurl: "deis.yourdomain.com:2222",
App: "drone",
Deisurl: "deis.yourdomain.com:2222",
}
h.Write(b)
@ -30,8 +30,8 @@ func Test_Deis(t *testing.T) {
g.It("Should add remote", func() {
b := new(buildfile.Buildfile)
h := Deis{
App: "drone",
Deisurl: "deis.yourdomain.com:2222/",
App: "drone",
Deisurl: "deis.yourdomain.com:2222/",
}
h.Write(b)
@ -54,7 +54,7 @@ func Test_Deis(t *testing.T) {
b := new(buildfile.Buildfile)
h := Deis{
Force: true,
App: "drone",
App: "drone",
}
h.Write(b)

View file

@ -5,9 +5,9 @@ import (
"github.com/drone/drone/shared/build/buildfile"
"github.com/drone/drone/shared/build/repo"
"github.com/drone/drone/plugin/deploy/deis"
"github.com/drone/drone/plugin/deploy/git"
"github.com/drone/drone/plugin/deploy/heroku"
"github.com/drone/drone/plugin/deploy/deis"
"github.com/drone/drone/plugin/deploy/modulus"
"github.com/drone/drone/plugin/deploy/nodejitsu"
"github.com/drone/drone/plugin/deploy/tsuru"
@ -20,7 +20,7 @@ type Deploy struct {
CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"`
Git *git.Git `yaml:"git,omitempty"`
Heroku *heroku.Heroku `yaml:"heroku,omitempty"`
Deis *deis.Deis `yaml:"deis,omitempty"`
Deis *deis.Deis `yaml:"deis,omitempty"`
Modulus *modulus.Modulus `yaml:"modulus,omitempty"`
Nodejitsu *nodejitsu.Nodejitsu `yaml:"nodejitsu,omitempty"`
SSH *SSH `yaml:"ssh,omitempty"`

View file

@ -17,7 +17,7 @@ const (
// Command to write the API token to ~/.netrc
// use "_" since heroku git authentication ignores username
CmdLogin = "echo 'machine git.heroku.com login _ password %s' >> ~/.netrc"
CmdLogin = "echo 'machine git.heroku.com login _ password %s' >> ~/.netrc"
)
type Heroku struct {

View file

@ -29,14 +29,14 @@ func Test_Heroku(t *testing.T) {
g.It("Should write token", func() {
b := new(buildfile.Buildfile)
h := Heroku{
App: "drone",
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)

View file

@ -1,19 +1,19 @@
package script
const (
DefaultDockerNetworkMode = "bridge"
DefaultDockerNetworkMode = "bridge"
)
// Docker stores the configuration details for
// configuring docker container.
type Docker struct {
// NetworkMode (also known as `--net` option)
// Could be set only if Docker is running in privileged mode
NetworkMode *string `yaml:"net,omitempty"`
// NetworkMode (also known as `--net` option)
// Could be set only if Docker is running in privileged mode
NetworkMode *string `yaml:"net,omitempty"`
// Hostname (also known as `--hostname` option)
// Could be set only if Docker is running in privileged mode
Hostname *string `yaml:"hostname,omitempty"`
// Hostname (also known as `--hostname` option)
// Could be set only if Docker is running in privileged mode
Hostname *string `yaml:"hostname,omitempty"`
}
// DockerNetworkMode returns DefaultNetworkMode
@ -21,10 +21,10 @@ type Docker struct {
// DockerNetworkMode returns Docker.NetworkMode
// when it is not empty.
func DockerNetworkMode(d *Docker) string {
if d == nil || d.NetworkMode == nil {
return DefaultDockerNetworkMode
}
return *d.NetworkMode
if d == nil || d.NetworkMode == nil {
return DefaultDockerNetworkMode
}
return *d.NetworkMode
}
// DockerNetworkMode returns empty string
@ -32,8 +32,8 @@ func DockerNetworkMode(d *Docker) string {
// DockerNetworkMode returns Docker.NetworkMode
// when it is not empty.
func DockerHostname(d *Docker) string {
if d == nil || d.Hostname == nil {
return ""
}
return *d.Hostname
if d == nil || d.Hostname == nil {
return ""
}
return *d.Hostname
}

View file

@ -1,69 +1,69 @@
package script
import (
"testing"
"testing"
)
func TestDockerNetworkMode(t *testing.T) {
var d *Docker
var expected string
var d *Docker
var expected string
expected = DefaultDockerNetworkMode
d = nil
if actual := DockerNetworkMode(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = DefaultDockerNetworkMode
d = nil
if actual := DockerNetworkMode(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = DefaultDockerNetworkMode
d = &Docker{}
if actual := DockerNetworkMode(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = DefaultDockerNetworkMode
d = &Docker{}
if actual := DockerNetworkMode(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = DefaultDockerNetworkMode
d = &Docker{NetworkMode: nil}
if actual := DockerNetworkMode(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = DefaultDockerNetworkMode
d = &Docker{NetworkMode: nil}
if actual := DockerNetworkMode(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = "bridge"
d = &Docker{NetworkMode: &expected}
if actual := DockerNetworkMode(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = "bridge"
d = &Docker{NetworkMode: &expected}
if actual := DockerNetworkMode(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = "host"
d = &Docker{NetworkMode: &expected}
if actual := DockerNetworkMode(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = "host"
d = &Docker{NetworkMode: &expected}
if actual := DockerNetworkMode(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
}
func TestDockerHostname(t *testing.T) {
var d *Docker
var expected string
var d *Docker
var expected string
expected = ""
d = nil
if actual := DockerHostname(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = ""
d = nil
if actual := DockerHostname(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = ""
d = &Docker{}
if actual := DockerHostname(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = ""
d = &Docker{}
if actual := DockerHostname(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = ""
d = &Docker{Hostname: nil}
if actual := DockerHostname(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = ""
d = &Docker{Hostname: nil}
if actual := DockerHostname(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = "host"
d = &Docker{Hostname: &expected}
if actual := DockerHostname(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
expected = "host"
d = &Docker{Hostname: &expected}
if actual := DockerHostname(d); actual != expected {
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
}
}