mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-01 22:31:15 +00:00
Merge pull request #797 from mattbostock/go_fmt
Run gofmt and add test to prevent regressions
This commit is contained in:
commit
ae65cf5fdb
9 changed files with 84 additions and 83 deletions
1
Makefile
1
Makefile
|
@ -8,6 +8,7 @@ deps:
|
||||||
go get -t -v ./...
|
go get -t -v ./...
|
||||||
|
|
||||||
test:
|
test:
|
||||||
|
@test -z "$(shell find . -name '*.go' | xargs gofmt -l)" || (echo "Need to run 'go fmt ./...'"; exit 1)
|
||||||
go vet ./...
|
go vet ./...
|
||||||
go test -cover -short ./...
|
go test -cover -short ./...
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ func restartCommandFunc(c *cli.Context, client *client.Client) error {
|
||||||
case 2:
|
case 2:
|
||||||
branch = "master"
|
branch = "master"
|
||||||
sha = args[1]
|
sha = args[1]
|
||||||
case 3,4,5:
|
case 3, 4, 5:
|
||||||
branch = args[1]
|
branch = args[1]
|
||||||
sha = args[2]
|
sha = args[2]
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,10 @@ const (
|
||||||
// deisurl: deis.myurl.tdl:2222/
|
// deisurl: deis.myurl.tdl:2222/
|
||||||
|
|
||||||
type Deis struct {
|
type Deis struct {
|
||||||
App string `yaml:"app,omitempty"`
|
App string `yaml:"app,omitempty"`
|
||||||
Force bool `yaml:"force,omitempty"`
|
Force bool `yaml:"force,omitempty"`
|
||||||
Deisurl string `yaml:"deisurl,omitempty"`
|
Deisurl string `yaml:"deisurl,omitempty"`
|
||||||
Condition *condition.Condition `yaml:"when,omitempty"`
|
Condition *condition.Condition `yaml:"when,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Deis) Write(f *buildfile.Buildfile) {
|
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
|
// 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 {
|
switch h.Force {
|
||||||
case true:
|
case true:
|
||||||
|
|
|
@ -16,8 +16,8 @@ func Test_Deis(t *testing.T) {
|
||||||
g.It("Should set git.config", func() {
|
g.It("Should set git.config", func() {
|
||||||
b := new(buildfile.Buildfile)
|
b := new(buildfile.Buildfile)
|
||||||
h := Deis{
|
h := Deis{
|
||||||
App: "drone",
|
App: "drone",
|
||||||
Deisurl: "deis.yourdomain.com:2222",
|
Deisurl: "deis.yourdomain.com:2222",
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Write(b)
|
h.Write(b)
|
||||||
|
@ -30,8 +30,8 @@ func Test_Deis(t *testing.T) {
|
||||||
g.It("Should add remote", func() {
|
g.It("Should add remote", func() {
|
||||||
b := new(buildfile.Buildfile)
|
b := new(buildfile.Buildfile)
|
||||||
h := Deis{
|
h := Deis{
|
||||||
App: "drone",
|
App: "drone",
|
||||||
Deisurl: "deis.yourdomain.com:2222/",
|
Deisurl: "deis.yourdomain.com:2222/",
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Write(b)
|
h.Write(b)
|
||||||
|
@ -54,7 +54,7 @@ func Test_Deis(t *testing.T) {
|
||||||
b := new(buildfile.Buildfile)
|
b := new(buildfile.Buildfile)
|
||||||
h := Deis{
|
h := Deis{
|
||||||
Force: true,
|
Force: true,
|
||||||
App: "drone",
|
App: "drone",
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Write(b)
|
h.Write(b)
|
||||||
|
|
|
@ -5,9 +5,9 @@ import (
|
||||||
"github.com/drone/drone/shared/build/buildfile"
|
"github.com/drone/drone/shared/build/buildfile"
|
||||||
"github.com/drone/drone/shared/build/repo"
|
"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/git"
|
||||||
"github.com/drone/drone/plugin/deploy/heroku"
|
"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/modulus"
|
||||||
"github.com/drone/drone/plugin/deploy/nodejitsu"
|
"github.com/drone/drone/plugin/deploy/nodejitsu"
|
||||||
"github.com/drone/drone/plugin/deploy/tsuru"
|
"github.com/drone/drone/plugin/deploy/tsuru"
|
||||||
|
@ -20,7 +20,7 @@ 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"`
|
||||||
Deis *deis.Deis `yaml:"deis,omitempty"`
|
Deis *deis.Deis `yaml:"deis,omitempty"`
|
||||||
Modulus *modulus.Modulus `yaml:"modulus,omitempty"`
|
Modulus *modulus.Modulus `yaml:"modulus,omitempty"`
|
||||||
Nodejitsu *nodejitsu.Nodejitsu `yaml:"nodejitsu,omitempty"`
|
Nodejitsu *nodejitsu.Nodejitsu `yaml:"nodejitsu,omitempty"`
|
||||||
SSH *SSH `yaml:"ssh,omitempty"`
|
SSH *SSH `yaml:"ssh,omitempty"`
|
||||||
|
|
|
@ -17,7 +17,7 @@ const (
|
||||||
|
|
||||||
// Command to write the API token to ~/.netrc
|
// Command to write the API token to ~/.netrc
|
||||||
// use "_" since heroku git authentication ignores username
|
// 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 {
|
type Heroku struct {
|
||||||
|
|
|
@ -29,14 +29,14 @@ func Test_Heroku(t *testing.T) {
|
||||||
g.It("Should write token", func() {
|
g.It("Should write token", func() {
|
||||||
b := new(buildfile.Buildfile)
|
b := new(buildfile.Buildfile)
|
||||||
h := Heroku{
|
h := Heroku{
|
||||||
App: "drone",
|
App: "drone",
|
||||||
Token: "mock-token",
|
Token: "mock-token",
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Write(b)
|
h.Write(b)
|
||||||
out := b.String()
|
out := b.String()
|
||||||
g.Assert(strings.Contains(out, "\necho 'machine git.heroku.com login _ password mock-token' >> ~/.netrc\n")).Equal(true)
|
g.Assert(strings.Contains(out, "\necho 'machine git.heroku.com login _ password mock-token' >> ~/.netrc\n")).Equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("Should add remote", func() {
|
g.It("Should add remote", func() {
|
||||||
b := new(buildfile.Buildfile)
|
b := new(buildfile.Buildfile)
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
package script
|
package script
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultDockerNetworkMode = "bridge"
|
DefaultDockerNetworkMode = "bridge"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Docker stores the configuration details for
|
// Docker stores the configuration details for
|
||||||
// configuring docker container.
|
// configuring docker container.
|
||||||
type Docker struct {
|
type Docker struct {
|
||||||
// NetworkMode (also known as `--net` option)
|
// NetworkMode (also known as `--net` option)
|
||||||
// Could be set only if Docker is running in privileged mode
|
// Could be set only if Docker is running in privileged mode
|
||||||
NetworkMode *string `yaml:"net,omitempty"`
|
NetworkMode *string `yaml:"net,omitempty"`
|
||||||
|
|
||||||
// Hostname (also known as `--hostname` option)
|
// Hostname (also known as `--hostname` option)
|
||||||
// Could be set only if Docker is running in privileged mode
|
// Could be set only if Docker is running in privileged mode
|
||||||
Hostname *string `yaml:"hostname,omitempty"`
|
Hostname *string `yaml:"hostname,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DockerNetworkMode returns DefaultNetworkMode
|
// DockerNetworkMode returns DefaultNetworkMode
|
||||||
|
@ -21,10 +21,10 @@ type Docker struct {
|
||||||
// DockerNetworkMode returns Docker.NetworkMode
|
// DockerNetworkMode returns Docker.NetworkMode
|
||||||
// when it is not empty.
|
// when it is not empty.
|
||||||
func DockerNetworkMode(d *Docker) string {
|
func DockerNetworkMode(d *Docker) string {
|
||||||
if d == nil || d.NetworkMode == nil {
|
if d == nil || d.NetworkMode == nil {
|
||||||
return DefaultDockerNetworkMode
|
return DefaultDockerNetworkMode
|
||||||
}
|
}
|
||||||
return *d.NetworkMode
|
return *d.NetworkMode
|
||||||
}
|
}
|
||||||
|
|
||||||
// DockerNetworkMode returns empty string
|
// DockerNetworkMode returns empty string
|
||||||
|
@ -32,8 +32,8 @@ func DockerNetworkMode(d *Docker) string {
|
||||||
// DockerNetworkMode returns Docker.NetworkMode
|
// DockerNetworkMode returns Docker.NetworkMode
|
||||||
// when it is not empty.
|
// when it is not empty.
|
||||||
func DockerHostname(d *Docker) string {
|
func DockerHostname(d *Docker) string {
|
||||||
if d == nil || d.Hostname == nil {
|
if d == nil || d.Hostname == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return *d.Hostname
|
return *d.Hostname
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,69 +1,69 @@
|
||||||
package script
|
package script
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDockerNetworkMode(t *testing.T) {
|
func TestDockerNetworkMode(t *testing.T) {
|
||||||
var d *Docker
|
var d *Docker
|
||||||
var expected string
|
var expected string
|
||||||
|
|
||||||
expected = DefaultDockerNetworkMode
|
expected = DefaultDockerNetworkMode
|
||||||
d = nil
|
d = nil
|
||||||
if actual := DockerNetworkMode(d); actual != expected {
|
if actual := DockerNetworkMode(d); actual != expected {
|
||||||
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = DefaultDockerNetworkMode
|
expected = DefaultDockerNetworkMode
|
||||||
d = &Docker{}
|
d = &Docker{}
|
||||||
if actual := DockerNetworkMode(d); actual != expected {
|
if actual := DockerNetworkMode(d); actual != expected {
|
||||||
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = DefaultDockerNetworkMode
|
expected = DefaultDockerNetworkMode
|
||||||
d = &Docker{NetworkMode: nil}
|
d = &Docker{NetworkMode: nil}
|
||||||
if actual := DockerNetworkMode(d); actual != expected {
|
if actual := DockerNetworkMode(d); actual != expected {
|
||||||
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = "bridge"
|
expected = "bridge"
|
||||||
d = &Docker{NetworkMode: &expected}
|
d = &Docker{NetworkMode: &expected}
|
||||||
if actual := DockerNetworkMode(d); actual != expected {
|
if actual := DockerNetworkMode(d); actual != expected {
|
||||||
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = "host"
|
expected = "host"
|
||||||
d = &Docker{NetworkMode: &expected}
|
d = &Docker{NetworkMode: &expected}
|
||||||
if actual := DockerNetworkMode(d); actual != expected {
|
if actual := DockerNetworkMode(d); actual != expected {
|
||||||
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDockerHostname(t *testing.T) {
|
func TestDockerHostname(t *testing.T) {
|
||||||
var d *Docker
|
var d *Docker
|
||||||
var expected string
|
var expected string
|
||||||
|
|
||||||
expected = ""
|
expected = ""
|
||||||
d = nil
|
d = nil
|
||||||
if actual := DockerHostname(d); actual != expected {
|
if actual := DockerHostname(d); actual != expected {
|
||||||
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = ""
|
expected = ""
|
||||||
d = &Docker{}
|
d = &Docker{}
|
||||||
if actual := DockerHostname(d); actual != expected {
|
if actual := DockerHostname(d); actual != expected {
|
||||||
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = ""
|
expected = ""
|
||||||
d = &Docker{Hostname: nil}
|
d = &Docker{Hostname: nil}
|
||||||
if actual := DockerHostname(d); actual != expected {
|
if actual := DockerHostname(d); actual != expected {
|
||||||
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = "host"
|
expected = "host"
|
||||||
d = &Docker{Hostname: &expected}
|
d = &Docker{Hostname: &expected}
|
||||||
if actual := DockerHostname(d); actual != expected {
|
if actual := DockerHostname(d); actual != expected {
|
||||||
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue