From 139585f84a82f08027ca72b3d3266b7f58db2883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 23 Nov 2016 18:53:50 +0100 Subject: [PATCH] tpl: Simplify --- tpl/template_funcs.go | 4 ++-- tpl/template_resources.go | 2 +- tpl/template_resources_test.go | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tpl/template_funcs.go b/tpl/template_funcs.go index 3e1b67706..747641c04 100644 --- a/tpl/template_funcs.go +++ b/tpl/template_funcs.go @@ -1593,7 +1593,7 @@ func dfault(dflt interface{}, given ...interface{}) (interface{}, error) { // argument when the key is missing: {{ index . "key" | default "foo" }} // The Go template will complain that we got 1 argument when we expectd 2. - if given == nil || len(given) == 0 { + if len(given) == 0 { return dflt, nil } if len(given) != 1 { @@ -1922,7 +1922,7 @@ func humanize(in interface{}) (string, error) { _, ok := in.(int) // original param was literal int value _, err = strconv.Atoi(word) // original param was string containing an int value - if ok == true || err == nil { + if ok || err == nil { return inflect.Ordinalize(word), nil } return inflect.Humanize(word), nil diff --git a/tpl/template_resources.go b/tpl/template_resources.go index 116d5df61..ee6305793 100644 --- a/tpl/template_resources.go +++ b/tpl/template_resources.go @@ -233,7 +233,7 @@ func getCSV(sep string, urlParts ...string) [][]string { for i := 0; i <= resRetries; i++ { c, err := resGetResource(url) - if err == nil && false == bytes.Contains(c, []byte(sep)) { + if err == nil && !bytes.Contains(c, []byte(sep)) { err = errors.New("Cannot find separator " + sep + " in CSV.") } diff --git a/tpl/template_resources_test.go b/tpl/template_resources_test.go index 4f13cc7df..3385c5ef7 100644 --- a/tpl/template_resources_test.go +++ b/tpl/template_resources_test.go @@ -72,7 +72,7 @@ func TestScpCache(t *testing.T) { t.Errorf("Cache ignored but content is not nil: %s", string(c)) } } else { - if bytes.Compare(c, test.content) != 0 { + if !bytes.Equal(c, test.content) { t.Errorf("\nExpected: %s\nActual: %s\n", string(test.content), string(c)) } } @@ -104,7 +104,7 @@ func TestScpGetLocal(t *testing.T) { if err != nil { t.Errorf("Error getting resource content: %s", err) } - if bytes.Compare(c, test.content) != 0 { + if !bytes.Equal(c, test.content) { t.Errorf("\nExpected: %s\nActual: %s\n", string(test.content), string(c)) } } @@ -148,7 +148,7 @@ func TestScpGetRemote(t *testing.T) { if err != nil { t.Errorf("Error getting resource content: %s", err) } - if bytes.Compare(c, test.content) != 0 { + if !bytes.Equal(c, test.content) { t.Errorf("\nNet Expected: %s\nNet Actual: %s\n", string(test.content), string(c)) } cc, cErr := resGetCache(test.path, fs, test.ignore) @@ -160,7 +160,7 @@ func TestScpGetRemote(t *testing.T) { t.Errorf("Cache ignored but content is not nil: %s", string(cc)) } } else { - if bytes.Compare(cc, test.content) != 0 { + if !bytes.Equal(cc, test.content) { t.Errorf("\nCache Expected: %s\nCache Actual: %s\n", string(test.content), string(cc)) } }