mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 11:51:02 +00:00
Run gofmt and add test to prevent regressions
Run `go fmt ./...` [1] and add a test to the `test` make target that checks if `go fmt` has been run. [1]: http://blog.golang.org/go-fmt-your-code
This commit is contained in:
parent
6ed8542f7d
commit
b027bd8392
9 changed files with 84 additions and 83 deletions
1
Makefile
1
Makefile
|
@ -9,6 +9,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 ./...
|
||||
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@ 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) {
|
||||
|
@ -35,7 +35,7 @@ func (h *Deis) Write(f *buildfile.Buildfile) {
|
|||
|
||||
// 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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue