Skip to content

Commit

Permalink
ref(*): clean up most code linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed Feb 20, 2015
1 parent b2ce935 commit 1b5055e
Show file tree
Hide file tree
Showing 23 changed files with 50 additions and 65 deletions.
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@ test-style:
# display output, then check
$(GOFMT) $(GO_PACKAGES)
@$(GOFMT) $(GO_PACKAGES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
# FIXME: make this mandatory
-$(GOVET) $(GO_PACKAGES_REPO_PATH)
# FIXME: make this mandatory
$(GOVET) $(GO_PACKAGES_REPO_PATH)
@for i in $(addsuffix /...,$(GO_PACKAGES)); do \
$(GOLINT) $$i; \
done
@$(foreach C, $(COMPONENTS), $(MAKE) -C $(C) test-style &&) echo done
@$(foreach C, $(CLIENTS), $(MAKE) -C $(C) test-style &&) echo done
@$(foreach C, tests $(CLIENTS) $(COMPONENTS), $(MAKE) -C $(C) test-style &&) echo done
8 changes: 3 additions & 5 deletions builder/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include ../includes.mk
repo_path = github.com/deis/deis/builder

GO_FILES = types.go utils.go utils_test.go
GO_PACKAGES = bin
GO_PACKAGES = bin tests
GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))

COMPONENT = $(notdir $(repo_path))
Expand Down Expand Up @@ -71,10 +71,8 @@ test-style:
# display output, then check
$(GOFMT) $(GO_PACKAGES) $(GO_FILES)
@$(GOFMT) $(GO_PACKAGES) $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
# FIXME: make this mandatory
-$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
# FIXME: make this mandatory
-$(GOLINT) ./...
$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
$(GOLINT) ./...

cedarish/build:
mkdir -p build
Expand Down
2 changes: 1 addition & 1 deletion builder/bin/generate-buildhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
var procfile builder.ProcessType
assert(json.Unmarshal([]byte(os.Args[5]), &procfile))

var dockerfile string = os.Args[6]
var dockerfile = os.Args[6]
if dockerfile == "false" {
dockerfile = ""
}
Expand Down
2 changes: 1 addition & 1 deletion builder/bin/yaml2json-procfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func main() {
os.Exit(1)
}

procfile, err := builder.YamlToJson(bytes)
procfile, err := builder.YamlToJSON(bytes)

if err != nil {
fmt.Println("the procfile does not contains a valid yaml structure")
Expand Down
10 changes: 7 additions & 3 deletions builder/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"gopkg.in/yaml.v2"
)

// YamlToJson takes an input yaml string, parses it and returns a string formatted as json.
func YamlToJson(bytes []byte) (string, error) {
// YamlToJSON takes an input yaml string, parses it and returns a string formatted as json.
func YamlToJSON(bytes []byte) (string, error) {
var anomaly map[string]string

if err := yaml.Unmarshal(bytes, &anomaly); err != nil {
Expand Down Expand Up @@ -39,6 +39,7 @@ func ParseConfig(res *http.Response) (*Config, error) {
return &config, err
}

// ParseDomain returns the domain field from the bytes of a build hook response.
func ParseDomain(bytes []byte) (string, error) {
var hook BuildHookResponse
if err := json.Unmarshal(bytes, &hook); err != nil {
Expand All @@ -56,6 +57,7 @@ func ParseDomain(bytes []byte) (string, error) {
return hook.Domains[0], nil
}

// ParseReleaseVersion returns the version field from the bytes of a build hook response.
func ParseReleaseVersion(bytes []byte) (int, error) {
var hook BuildHookResponse
if err := json.Unmarshal(bytes, &hook); err != nil {
Expand All @@ -69,9 +71,10 @@ func ParseReleaseVersion(bytes []byte) (int, error) {
return hook.Release["version"], nil
}

// GetDefaultType returns the default process types given a YAML byte array.
func GetDefaultType(bytes []byte) (string, error) {
type YamlTypeMap struct {
DefaultProcessTypes ProcessType `default_process_types`
DefaultProcessTypes ProcessType `yaml:"default_process_types"`
}

var p YamlTypeMap
Expand All @@ -93,6 +96,7 @@ func GetDefaultType(bytes []byte) (string, error) {
return string(retVal), nil
}

// ParseControllerConfig returns configuration key/value pair strings from a config.
func ParseControllerConfig(bytes []byte) ([]string, error) {
var controllerConfig Config
if err := json.Unmarshal(bytes, &controllerConfig); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions builder/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func stringInSlice(list []string, s string) bool {
return false
}

func TestYamlToJsonGood(t *testing.T) {
func TestYamlToJSONGood(t *testing.T) {
goodProcfiles := [][]byte{
[]byte(`web: while true; do echo hello; sleep 1; done`),

Expand All @@ -42,7 +42,7 @@ worker: while true; do echo hello; sleep 1; done`),
goodProcess := "while true; do echo hello; sleep 1; done"

for _, procfile := range goodProcfiles {
data, err := YamlToJson(procfile)
data, err := YamlToJSON(procfile)
if err != nil {
t.Errorf("expected procfile to be valid, got '%v'", err)
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestParseControllerConfigGood(t *testing.T) {
}

func TestTimeSerialize(t *testing.T) {
time, err := json.Marshal(&dtime.Time{time.Now().UTC()})
time, err := json.Marshal(&dtime.Time{Time: time.Now().UTC()})

if err != nil {
t.Errorf("expected to be able to serialize time as json, got '%v'", err)
Expand Down
8 changes: 3 additions & 5 deletions cache/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include ../includes.mk
# the filepath to this repository, relative to $GOPATH/src
repo_path = github.com/deis/deis/cache

GO_PACKAGES = image
GO_PACKAGES = . tests
GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))

COMPONENT = $(notdir $(repo_path))
Expand Down Expand Up @@ -65,10 +65,8 @@ test-style:
# display output, then check
$(GOFMT) $(GO_PACKAGES)
@$(GOFMT) $(GO_PACKAGES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
# FIXME: make this mandatory
-$(GOVET) $(GO_PACKAGES_REPO_PATH)
# FIXME: make this mandatory
-$(GOLINT) ./...
$(GOVET) $(GO_PACKAGES_REPO_PATH)
$(GOLINT) ./...

test-functional:
@docker history deis/test-etcd >/dev/null 2>&1 || docker pull deis/test-etcd:latest
Expand Down
6 changes: 2 additions & 4 deletions deisctl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ test-style:
# display output, then check
$(GOFMT) $(GO_PACKAGES) $(GO_FILES)
@$(GOFMT) $(GO_PACKAGES) $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
# FIXME: make this mandatory
-$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
# FIXME: make this mandatory
-$(GOLINT) ./...
$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
$(GOLINT) ./...

test-unit:
godep go test -v -cover ./...
11 changes: 5 additions & 6 deletions logger/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ include ../includes.mk
repo_path = github.com/deis/deis/logger

GO_FILES = main.go
GO_PACKAGES = syslog syslogd
GO_PACKAGES = syslog syslogd tests
GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))
GO_TESTABLE_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,syslog syslogd)

COMPONENT = $(notdir $(repo_path))
IMAGE = $(IMAGE_PREFIX)$(COMPONENT):$(BUILD_TAG)
Expand Down Expand Up @@ -71,13 +72,11 @@ test-style:
# display output, then check
$(GOFMT) $(GO_PACKAGES) $(GO_FILES)
@$(GOFMT) $(GO_PACKAGES) $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
# FIXME: make this mandatory
-$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
# FIXME: make this mandatory
-$(GOLINT) ./...
$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
$(GOLINT) ./...

test-unit: test-style
$(GOTEST) $(GO_PACKAGES_REPO_PATH)
$(GOTEST) $(GO_TESTABLE_PACKAGES_REPO_PATH)

coverage:
go test -coverprofile coverage.out ./syslog
Expand Down
6 changes: 2 additions & 4 deletions logspout/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ test-style:
# display output, then check
$(GOFMT) $(GO_PACKAGES) $(GO_FILES)
@$(GOFMT) $(GO_PACKAGES) $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
# FIXME: make this mandatory
-$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
# FIXME: make this mandatory
-$(GOLINT) ./...
$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
$(GOLINT) ./...

test-unit:
@echo no unit tests
2 changes: 1 addition & 1 deletion logspout/logspout.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func syslogStreamer(target Target, types []string, logstream chan *Log) {
// HACK: Go's syslog package hardcodes the log format, so let's send our own message
_, err = fmt.Fprintf(conn,
"%s %s[%s]: %s",
time.Now().Format(getopt("DATETIME_FORMAT", dtime.DEIS_DATETIME_FORMAT)),
time.Now().Format(getopt("DATETIME_FORMAT", dtime.DeisDatetimeFormat)),
tag,
pid,
logline.Data)
Expand Down
11 changes: 6 additions & 5 deletions pkg/time/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@ package time

import "time"

const DEIS_DATETIME_FORMAT string = "2006-01-02T15:04:05MST"
// DeisDatetimeFormat is the standard date/time representation used in Deis.
const DeisDatetimeFormat string = "2006-01-02T15:04:05MST"

// Time represents the standard datetime format used across the Deis Platform.
type Time struct {
time.Time
}

func (t *Time) format() string {
return t.Time.Format(DEIS_DATETIME_FORMAT)
return t.Time.Format(DeisDatetimeFormat)
}

// MarshalJSON implements the json.Marshaler interface.
// The time is a quoted string in Deis' datetime format.
func (t *Time) MarshalJSON() ([]byte, error) {
return []byte(t.Time.Format(`"` + DEIS_DATETIME_FORMAT + `"`)), nil
return []byte(t.Time.Format(`"` + DeisDatetimeFormat + `"`)), nil
}

// UnmarshalText implements the encoding.TextUnmarshaler interface.
// The time is expected to be in Deis' datetime format.
func (t *Time) UnmarshalText(data []byte) (err error) {
tt, err := time.Parse(DEIS_DATETIME_FORMAT, string(data))
tt, err := time.Parse(DeisDatetimeFormat, string(data))
*t = Time{tt}
return
}
Expand All @@ -31,7 +32,7 @@ func (t *Time) UnmarshalText(data []byte) (err error) {
// The time is expected to be a quoted string in Deis' datetime format.
func (t *Time) UnmarshalJSON(data []byte) (err error) {
// Fractional seconds are handled implicitly by Parse.
tt, err := time.Parse(`"`+DEIS_DATETIME_FORMAT+`"`, string(data))
tt, err := time.Parse(`"`+DeisDatetimeFormat+`"`, string(data))
*t = Time{tt}
return
}
6 changes: 2 additions & 4 deletions publisher/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ test-style:
# display output, then check
$(GOFMT) $(GO_PACKAGES) $(GO_FILES)
@$(GOFMT) $(GO_PACKAGES) $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
# FIXME: make this mandatory
-$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
# FIXME: make this mandatory
-$(GOLINT) ./...
$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
$(GOLINT) ./...

test-unit:
godep go test -v ./...
Expand Down
2 changes: 1 addition & 1 deletion publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
}
etcdClient := etcd.NewClient([]string{"http://" + etcdHost + ":4001"})

server := &server.Server{client, etcdClient}
server := &server.Server{DockerClient: client, EtcdClient: etcdClient}

go server.Listen(etcdTTL)

Expand Down
5 changes: 2 additions & 3 deletions publisher/server/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *Server) publishContainer(container *docker.APIContainers, ttl time.Dura
}
}

// isPublishableApp determines if the application should be published to etcd.
// IsPublishableApp determines if the application should be published to etcd.
func (s *Server) IsPublishableApp(name string) bool {
r := regexp.MustCompile(appNameRegex)
match := r.FindStringSubmatch(name)
Expand All @@ -115,9 +115,8 @@ func (s *Server) IsPublishableApp(name string) bool {
}
if version >= latestRunningVersion(s.EtcdClient, appName) {
return true
} else {
return false
}
return false
}

// latestRunningVersion retrieves the highest version of the application published
Expand Down
8 changes: 3 additions & 5 deletions router/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include ../includes.mk
repo_path = github.com/deis/deis/router

GO_FILES = boot.go
GO_PACKAGES = logger
GO_PACKAGES = logger tests
GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))

COMPONENT = $(notdir $(repo_path))
Expand Down Expand Up @@ -68,10 +68,8 @@ test-style:
# display output, then check
$(GOFMT) $(GO_PACKAGES) $(GO_FILES)
@$(GOFMT) $(GO_PACKAGES) $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
# FIXME: make this mandatory
-$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
# FIXME: make this mandatory
-$(GOLINT) ./...
$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
$(GOLINT) ./...

test-unit:
@echo no unit tests
2 changes: 2 additions & 0 deletions router/logger/stdout_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"github.com/Sirupsen/logrus"
)

// StdOutFormatter formats log messages from the router component.
type StdOutFormatter struct {
}

// Format rewrites a log entry for stdout as a byte array.
func (f *StdOutFormatter) Format(entry *logrus.Entry) ([]byte, error) {
b := &bytes.Buffer{}
fmt.Fprintf(b, "[%s] - %s\n", strings.ToUpper(entry.Level.String()), entry.Message)
Expand Down
8 changes: 3 additions & 5 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ test-style:
# display output, then check
$(GOFMT) $(GO_PACKAGES) $(GO_FILES)
@$(GOFMT) $(GO_PACKAGES) $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
# FIXME: make this mandatory
-$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
# FIXME: make this mandatory
-$(GOLINT) ./...
$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
$(GOLINT) ./...

nuke_from_orbit:
-docker kill `docker ps -q`
-docker rm `docker ps -a -q`
-docker rm -v `docker ps -a -q`
-docker rmi -f `docker images -q`
1 change: 0 additions & 1 deletion tests/dockercli/dockercli.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Package dockercli provides helper functions for testing with Docker.

package dockercli

import (
Expand Down
1 change: 0 additions & 1 deletion tests/etcdutils/etcdutils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Package etcdutils helps test interactions with etcd.

package etcdutils

import (
Expand Down
1 change: 0 additions & 1 deletion tests/mock/mock.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Package mock provides mock objects and setup for Deis tests.

package mock

import (
Expand Down
1 change: 0 additions & 1 deletion tests/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Package utils contains commonly useful functions from Deis testing.

package utils

import (
Expand Down
1 change: 1 addition & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package version

// Version identifies this Deis product revision.
const Version = "1.4.0-dev"

0 comments on commit 1b5055e

Please sign in to comment.