Skip to content

Commit

Permalink
Fixing issues identified by gofmt, golint, and spell checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfarina committed Oct 2, 2019
1 parent eeabc0e commit 1c4ac02
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 80 deletions.
2 changes: 2 additions & 0 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func generatePrivateKey(typ string) string {
return string(pem.EncodeToMemory(pemBlockForKey(priv)))
}

// DSAKeyFormat stores the format for DSA keys.
// Used by pemBlockForKey
type DSAKeyFormat struct {
Version int
P, Q, G, Y, X *big.Int
Expand Down
2 changes: 1 addition & 1 deletion dict_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestMerge(t *testing.T) {
"i": "eye", // overridden twice
"j": "jay", // overridden and merged
"k": map[string]interface{}{
"l": true, // overriden
"l": true, // overridden
},
}
assert.Equal(t, expected, dict["dst"])
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Sprig: Template functions for Go.
Package sprig provides template functions for Go.
This package contains a number of utility functions for working with data
inside of Go `html/template` and `text/template` files.
Expand Down
2 changes: 1 addition & 1 deletion functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func GenericFuncMap() map[string]interface{} {
}

// These functions are not guaranteed to evaluate to the same result for given input, because they
// refer to the environemnt or global state.
// refer to the environment or global state.
var nonhermeticFunctions = []string{
// Date functions
"date",
Expand Down
4 changes: 2 additions & 2 deletions strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ func strslice(v interface{}) []string {
default:
if v == nil {
return []string{}
} else {
return []string{strval(v)}
}

return []string{strval(v)}
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions url.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

func dictGetOrEmpty(dict map[string]interface{}, key string) string {
value, ok := dict[key]; if !ok {
value, ok := dict[key]
if !ok {
return ""
}
tp := reflect.TypeOf(value).Kind()
Expand All @@ -20,19 +21,19 @@ func dictGetOrEmpty(dict map[string]interface{}, key string) string {
// parses given URL to return dict object
func urlParse(v string) map[string]interface{} {
dict := map[string]interface{}{}
parsedUrl, err := url.Parse(v)
parsedURL, err := url.Parse(v)
if err != nil {
panic(fmt.Sprintf("unable to parse url: %s", err))
}
dict["scheme"] = parsedUrl.Scheme
dict["host"] = parsedUrl.Host
dict["hostname"] = parsedUrl.Hostname()
dict["path"] = parsedUrl.Path
dict["query"] = parsedUrl.RawQuery
dict["opaque"] = parsedUrl.Opaque
dict["fragment"] = parsedUrl.Fragment
if parsedUrl.User != nil {
dict["userinfo"] = parsedUrl.User.String()
dict["scheme"] = parsedURL.Scheme
dict["host"] = parsedURL.Host
dict["hostname"] = parsedURL.Hostname()
dict["path"] = parsedURL.Path
dict["query"] = parsedURL.RawQuery
dict["opaque"] = parsedURL.Opaque
dict["fragment"] = parsedURL.Fragment
if parsedURL.User != nil {
dict["userinfo"] = parsedURL.User.String()
} else {
dict["userinfo"] = ""
}
Expand All @@ -42,25 +43,24 @@ func urlParse(v string) map[string]interface{} {

// join given dict to URL string
func urlJoin(d map[string]interface{}) string {
resUrl := url.URL{
resURL := url.URL{
Scheme: dictGetOrEmpty(d, "scheme"),
Host: dictGetOrEmpty(d, "host"),
Path: dictGetOrEmpty(d, "path"),
RawQuery: dictGetOrEmpty(d, "query"),
Opaque: dictGetOrEmpty(d, "opaque"),
Fragment: dictGetOrEmpty(d, "fragment"),

}
userinfo := dictGetOrEmpty(d, "userinfo")
var user *url.Userinfo = nil
var user *url.Userinfo
if userinfo != "" {
tempUrl, err := url.Parse(fmt.Sprintf("proto://%s@host", userinfo))
tempURL, err := url.Parse(fmt.Sprintf("proto://%s@host", userinfo))
if err != nil {
panic(fmt.Sprintf("unable to parse userinfo in dict: %s", err))
}
user = tempUrl.User
user = tempURL.User
}

resUrl.User = user
return resUrl.String()
resURL.User = user
return resURL.String()
}
112 changes: 55 additions & 57 deletions url_test.go
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
package sprig

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

var urlTests = map[string]map[string]interface{}{
"proto://auth@host:80/path?query#fragment": {
"fragment": "fragment",
"host": "host:80",
"hostname": "host",
"opaque": "",
"path": "/path",
"query": "query",
"scheme": "proto",
"userinfo": "auth",
},
"proto://host:80/path": {
"fragment": "",
"host": "host:80",
"hostname": "host",
"opaque": "",
"path": "/path",
"query": "",
"scheme": "proto",
"userinfo": "",
},
"something":{
"fragment": "",
"host": "",
"hostname": "",
"opaque": "",
"path": "something",
"query": "",
"scheme": "",
"userinfo": "",
},
"proto://user:passwor%20d@host:80/path":{
"fragment": "",
"host": "host:80",
"hostname": "host",
"opaque": "",
"path": "/path",
"query": "",
"scheme": "proto",
"userinfo": "user:passwor%20d",
},
"proto://host:80/pa%20th?key=val%20ue":{
"fragment": "",
"host": "host:80",
"hostname": "host",
"opaque": "",
"path": "/pa th",
"query": "key=val%20ue",
"scheme": "proto",
"userinfo": "",
},
}

"proto://auth@host:80/path?query#fragment": {
"fragment": "fragment",
"host": "host:80",
"hostname": "host",
"opaque": "",
"path": "/path",
"query": "query",
"scheme": "proto",
"userinfo": "auth",
},
"proto://host:80/path": {
"fragment": "",
"host": "host:80",
"hostname": "host",
"opaque": "",
"path": "/path",
"query": "",
"scheme": "proto",
"userinfo": "",
},
"something": {
"fragment": "",
"host": "",
"hostname": "",
"opaque": "",
"path": "something",
"query": "",
"scheme": "",
"userinfo": "",
},
"proto://user:passwor%20d@host:80/path": {
"fragment": "",
"host": "host:80",
"hostname": "host",
"opaque": "",
"path": "/path",
"query": "",
"scheme": "proto",
"userinfo": "user:passwor%20d",
},
"proto://host:80/pa%20th?key=val%20ue": {
"fragment": "",
"host": "host:80",
"hostname": "host",
"opaque": "",
"path": "/pa th",
"query": "key=val%20ue",
"scheme": "proto",
"userinfo": "",
},
}

func TestUrlParse(t *testing.T) {
// testing that function is exported and working properly
Expand All @@ -73,10 +73,8 @@ func TestUrlParse(t *testing.T) {

func TestUrlJoin(t *testing.T) {
tests := map[string]string{
`{{ urlJoin (dict "fragment" "fragment" "host" "host:80" "path" "/path" "query" "query" "scheme" "proto") }}`:
"proto://host:80/path?query#fragment",
`{{ urlJoin (dict "fragment" "fragment" "host" "host:80" "path" "/path" "scheme" "proto" "userinfo" "ASDJKJSD") }}`:
"proto://ASDJKJSD@host:80/path#fragment",
`{{ urlJoin (dict "fragment" "fragment" "host" "host:80" "path" "/path" "query" "query" "scheme" "proto") }}`: "proto://host:80/path?query#fragment",
`{{ urlJoin (dict "fragment" "fragment" "host" "host:80" "path" "/path" "scheme" "proto" "userinfo" "ASDJKJSD") }}`: "proto://ASDJKJSD@host:80/path#fragment",
}
for tpl, expected := range tests {
assert.NoError(t, runt(tpl, expected))
Expand Down

0 comments on commit 1c4ac02

Please sign in to comment.