Skip to content

Commit

Permalink
Merge pull request #554 from asteris-llc/feature/fix-linting-bugs
Browse files Browse the repository at this point in the history
Fix Linting Bugs
  • Loading branch information
BrianHicks authored Dec 21, 2016
2 parents 01ac44b + ae3ffcb commit 2cf73ec
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 40 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bench:
go test -run '^$$' -bench=${BENCH} -benchmem ${BENCHDIRS}

# linting
LINTDIRS = $(eval LINTDIRS := $$(shell find ${SRCDIRS} -type d -not -path './rpc/pb' -not -path './docs*'))$(value LINTDIRS)
LINTDIRS = $(eval LINTDIRS := $(shell find ${SRCDIRS} -type d -not -path './rpc/pb' -not -path './docs*'))$(value LINTDIRS)
.PHONY: lint
lint:
@echo '=== golint ==='
Expand All @@ -107,9 +107,6 @@ lint:
@echo '=== varcheck ==='
@varcheck ${LINTDIRS} # github.com/opennota/check/cmd/varcheck

@echo '=== aligncheck ==='
@aligncheck ${LINTDIRS} # github.com/opennota/check/cmd/aligncheck

@echo '=== gas ==='
@gas ${LINTDIRS} # github.com/HewlettPackard/gas

Expand Down
4 changes: 2 additions & 2 deletions render/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (v *LazyValue) Value() (resource.Value, bool, error) {
case ValueThunk:
val, found, err := result()
v.val = [3]interface{}{val, found, err}
return resource.Value(val), found, err
return val, found, err
default:
return "", false, errors.New("value is not a thunk")
}
Expand Down Expand Up @@ -108,7 +108,7 @@ func getParamOverrides(gFunc func() *graph.Graph, id string) (ValueThunk, bool)
return "", false, fmt.Errorf("Parent of param %s was not a module, was %T", id, parentTask)
}
if val, ok := parent.Params[name[len("param."):]]; ok {
return resource.Value(val), true, nil
return val, true, nil
}
return "", false, nil
}
Expand Down
1 change: 0 additions & 1 deletion resource/docker/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (

const (
containerStatusRunning = "running"
containerStatusCreated = "created"

// DefaultNetworkMode is the mode of the container network
DefaultNetworkMode = "default"
Expand Down
2 changes: 1 addition & 1 deletion resource/docker/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (n *Network) Check(context.Context, resource.Renderer) (resource.TaskStatus
return status, err
}

if invalidGWs != nil && len(invalidGWs) > 0 {
if len(invalidGWs) > 0 {
status.RaiseLevel(resource.StatusCantChange)
return status, fmt.Errorf("%s: gateway(s) are already in use", strings.Join(invalidGWs, ", "))

Expand Down
2 changes: 1 addition & 1 deletion resource/docker/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func volumeState(vol *dc.Volume) State {
}

func mapToString(m map[string]string) string {
if m == nil || len(m) == 0 {
if len(m) == 0 {
return ""
}
strs := make([]string, len(m))
Expand Down
9 changes: 3 additions & 6 deletions resource/file/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,8 @@ func (f *Fetch) Check(context.Context, resource.Renderer) (resource.TaskStatus,
}

status, err = f.DiffFile(status, hsh)
if err != nil {
return status, err
}

return status, nil
return status, err
}

// Apply fetches the file
Expand Down Expand Up @@ -184,7 +181,7 @@ func (f *Fetch) DiffFile(status *resource.Status, hsh hash.Hash) (*resource.Stat
// evaluate the checksums
if actual == f.Hash {
status.AddMessage("file exists")
} else if f.Force == true {
} else if f.Force {
status.AddDifference("checksum", actual, f.Hash, "")
status.AddMessage("checksum mismatch")
status.RaiseLevel(resource.StatusWillChange)
Expand All @@ -194,7 +191,7 @@ func (f *Fetch) DiffFile(status *resource.Status, hsh hash.Hash) (*resource.Stat
return status, errors.New("will not attempt fetch: checksum mismatch")
}
} else {
if f.Force == true {
if f.Force {
status.AddDifference("destination", "<force fetch>", f.Destination, "")
status.AddMessage("file exists, will fetch due to \"force\"")
status.RaiseLevel(resource.StatusWillChange)
Expand Down
4 changes: 2 additions & 2 deletions resource/lvm/lowlevel/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import (

// Cover values for `66%FREE` and likewise (refer LVM manpages for details).
// See also size_test.go for more usage examples
var pctRE = regexp.MustCompile("^(?i)(\\d+)%(PVS|VG|FREE)$")
var pctRE = regexp.MustCompile(`^(?i)(\d+)%(PVS|VG|FREE)$`)

// Cover values for `50G` and likewise (refer LVM manpages for details).
// See also size_test.go for more usage examples.
// Difference between lower/upper cases letters not supported now, see NB above
var sizeRE = regexp.MustCompile("^(?i)(\\d+)([bskmgtpe])b?$")
var sizeRE = regexp.MustCompile(`^(?i)(\d+)([bskmgtpe])b?$`)

// LvmSize represent parsed and validated LVM compatible size
type LvmSize struct {
Expand Down
33 changes: 11 additions & 22 deletions resource/wait/retrier.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,27 @@ type RetryFunc func() (bool, error)
// RetryUntil implements a retry loop
func (r *Retrier) RetryUntil(retryFunc RetryFunc) (bool, error) {
startTime := time.Now()
after := r.GracePeriod
ok := false
var err error
waitLoop:

for {
select {
case <-time.After(after):
if ok {
break waitLoop
}
ok, err := retryFunc()
if err != nil {
return false, err
}

if !ok {
r.RetryCount++
after = r.Interval

ok, err = retryFunc()
if err != nil {
break waitLoop
}

if ok {
after = r.GracePeriod
continue
}

if r.RetryCount >= r.MaxRetry {
break waitLoop
return false, nil
}
time.Sleep(r.GracePeriod)
} else {
break
}
}

r.Duration = time.Since(startTime)
return ok, err
return true, nil
}

// PrepareRetrier generates a Retrier from preparer input
Expand Down
2 changes: 1 addition & 1 deletion resource/wait/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestApply(t *testing.T) {
require.NoError(t, err)

t.Run("retry count", func(t *testing.T) {
assert.Equal(t, 1, wait.RetryCount)
assert.Equal(t, 0, wait.RetryCount)
})

t.Run("status is set", func(t *testing.T) {
Expand Down

0 comments on commit 2cf73ec

Please sign in to comment.