diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2021-04-03 13:18:17 -0400 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2021-04-03 14:23:00 -0400 |
| commit | d334a3619a9897ff43b76b8f60fa1a0a41b9cbe9 (patch) | |
| tree | 97f9fe27182604e41f08183fc42a2e4b4bded7ba /data | |
| parent | 507d41ae8a2536584eb032c98abc46496a77ea86 (diff) | |
Update linting and fix field alignment issues
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'data')
| -rw-r--r-- | data/data_test.go | 14 | ||||
| -rw-r--r-- | data/datasource.go | 4 | ||||
| -rw-r--r-- | data/datasource_aws_sm_test.go | 66 | ||||
| -rw-r--r-- | data/datasource_awssmp_test.go | 4 | ||||
| -rw-r--r-- | data/datasource_git_test.go | 52 |
5 files changed, 73 insertions, 67 deletions
diff --git a/data/data_test.go b/data/data_test.go index 08c49015..9c67ccab 100644 --- a/data/data_test.go +++ b/data/data_test.go @@ -324,18 +324,18 @@ func TestCSVByColumn(t *testing.T) { } testdata := []struct { - args []string out map[string][]string + args []string }{ - {[]string{"first,second,third\n1,2,3\n4,5,6"}, expected}, - {[]string{"first,second,third", "1,2,3\n4,5,6"}, expected}, - {[]string{";", "first;second;third", "1;2;3\n4;5;6"}, expected}, - {[]string{";", "first;second;third\r\n1;2;3\r\n4;5;6"}, expected}, - {[]string{"", "1,2,3\n4,5,6"}, map[string][]string{ + {expected, []string{"first,second,third\n1,2,3\n4,5,6"}}, + {expected, []string{"first,second,third", "1,2,3\n4,5,6"}}, + {expected, []string{";", "first;second;third", "1;2;3\n4;5;6"}}, + {expected, []string{";", "first;second;third\r\n1;2;3\r\n4;5;6"}}, + {map[string][]string{ "A": {"1", "4"}, "B": {"2", "5"}, "C": {"3", "6"}, - }}, + }, []string{"", "1,2,3\n4,5,6"}}, } for _, d := range testdata { out, err := CSVByColumn(d.args...) diff --git a/data/datasource.go b/data/datasource.go index 0f2c44fa..77dc7990 100644 --- a/data/datasource.go +++ b/data/datasource.go @@ -138,9 +138,7 @@ func FromConfig(ctx context.Context, cfg *config.Config) *Data { // Source - a data source type Source struct { - Alias string URL *url.URL - mediaType string fs afero.Fs // used for file: URLs, nil otherwise hc *http.Client // used for http[s]: URLs, nil otherwise vc *vault.Vault // used for vault: URLs, nil otherwise @@ -148,6 +146,8 @@ type Source struct { asmpg awssmpGetter // used for aws+smp:, nil otherwise awsSecretsManager awsSecretsManagerGetter // used for aws+sm, nil otherwise header http.Header // used for http[s]: URLs, nil otherwise + Alias string + mediaType string } func (s *Source) inherit(parent *Source) { diff --git a/data/datasource_aws_sm_test.go b/data/datasource_aws_sm_test.go index 3ed0aa45..c29a9b0b 100644 --- a/data/datasource_aws_sm_test.go +++ b/data/datasource_aws_sm_test.go @@ -45,52 +45,54 @@ func TestAWSSecretsManager_ParseAWSSecretsManagerArgs(t *testing.T) { _, _, err := parseDatasourceURLArgs(mustParseURL("base"), "extra", "too many!") assert.Error(t, err) + tplain := map[string]interface{}{"type": "text/plain"} + data := []struct { - u *url.URL - args []string - expectedParams map[string]interface{} - expectedPath string + eParams map[string]interface{} + u string + ePath string + args string }{ - {mustParseURL("noddy"), nil, nil, "noddy"}, - {mustParseURL("base"), []string{"extra"}, nil, "base/extra"}, - {mustParseURL("/foo/"), []string{"/extra"}, nil, "/foo/extra"}, - {mustParseURL("aws+sm:///foo"), []string{"bar"}, nil, "/foo/bar"}, - {mustParseURL("aws+sm:foo"), nil, nil, "foo"}, - {mustParseURL("aws+sm:foo/bar"), nil, nil, "foo/bar"}, - {mustParseURL("aws+sm:/foo/bar"), nil, nil, "/foo/bar"}, - {mustParseURL("aws+sm:foo"), []string{"baz"}, nil, "foo/baz"}, - {mustParseURL("aws+sm:foo/bar"), []string{"baz"}, nil, "foo/bar/baz"}, - {mustParseURL("aws+sm:/foo/bar"), []string{"baz"}, nil, "/foo/bar/baz"}, - {mustParseURL("aws+sm:///foo"), []string{"dir/"}, nil, "/foo/dir/"}, - {mustParseURL("aws+sm:///foo/"), nil, nil, "/foo/"}, - {mustParseURL("aws+sm:///foo/"), []string{"baz"}, nil, "/foo/baz"}, - - {mustParseURL("aws+sm:foo?type=text/plain"), []string{"baz"}, - map[string]interface{}{"type": "text/plain"}, "foo/baz"}, - {mustParseURL("aws+sm:foo/bar?type=text/plain"), []string{"baz"}, - map[string]interface{}{"type": "text/plain"}, "foo/bar/baz"}, - {mustParseURL("aws+sm:/foo/bar?type=text/plain"), []string{"baz"}, - map[string]interface{}{"type": "text/plain"}, "/foo/bar/baz"}, + {u: "noddy", ePath: "noddy"}, + {u: "base", ePath: "base/extra", args: "extra"}, + {u: "/foo/", ePath: "/foo/extra", args: "/extra"}, + {u: "aws+sm:///foo", ePath: "/foo/bar", args: "bar"}, + {u: "aws+sm:foo", ePath: "foo"}, + {u: "aws+sm:foo/bar", ePath: "foo/bar"}, + {u: "aws+sm:/foo/bar", ePath: "/foo/bar"}, + {u: "aws+sm:foo", ePath: "foo/baz", args: "baz"}, + {u: "aws+sm:foo/bar", ePath: "foo/bar/baz", args: "baz"}, + {u: "aws+sm:/foo/bar", ePath: "/foo/bar/baz", args: "baz"}, + {u: "aws+sm:///foo", ePath: "/foo/dir/", args: "dir/"}, + {u: "aws+sm:///foo/", ePath: "/foo/"}, + {u: "aws+sm:///foo/", ePath: "/foo/baz", args: "baz"}, + {eParams: tplain, u: "aws+sm:foo?type=text/plain", ePath: "foo/baz", args: "baz"}, + {eParams: tplain, u: "aws+sm:foo/bar?type=text/plain", ePath: "foo/bar/baz", args: "baz"}, + {eParams: tplain, u: "aws+sm:/foo/bar?type=text/plain", ePath: "/foo/bar/baz", args: "baz"}, { - mustParseURL("aws+sm:/foo/bar?type=text/plain"), - []string{"baz/qux?type=application/json¶m=quux"}, - map[string]interface{}{ + eParams: map[string]interface{}{ "type": "application/json", "param": "quux", }, - "/foo/bar/baz/qux", + u: "aws+sm:/foo/bar?type=text/plain", + ePath: "/foo/bar/baz/qux", + args: "baz/qux?type=application/json¶m=quux", }, } for _, d := range data { - params, p, err := parseDatasourceURLArgs(d.u, d.args...) + args := []string{d.args} + if d.args == "" { + args = nil + } + params, p, err := parseDatasourceURLArgs(mustParseURL(d.u), args...) assert.NoError(t, err) - if d.expectedParams == nil { + if d.eParams == nil { assert.Empty(t, params) } else { - assert.EqualValues(t, d.expectedParams, params) + assert.EqualValues(t, d.eParams, params) } - assert.Equal(t, d.expectedPath, p) + assert.Equal(t, d.ePath, p) } } diff --git a/data/datasource_awssmp_test.go b/data/datasource_awssmp_test.go index bb0a03c8..3c14e325 100644 --- a/data/datasource_awssmp_test.go +++ b/data/datasource_awssmp_test.go @@ -15,11 +15,11 @@ import ( // DummyParamGetter - test double type DummyParamGetter struct { + err awserr.Error t *testing.T param *ssm.Parameter - params []*ssm.Parameter - err awserr.Error mockGetParameter func(*ssm.GetParameterInput) (*ssm.GetParameterOutput, error) + params []*ssm.Parameter } func (d DummyParamGetter) GetParameterWithContext(ctx context.Context, input *ssm.GetParameterInput, opts ...request.Option) (*ssm.GetParameterOutput, error) { diff --git a/data/datasource_git_test.go b/data/datasource_git_test.go index 73780184..f48393c3 100644 --- a/data/datasource_git_test.go +++ b/data/datasource_git_test.go @@ -100,78 +100,78 @@ func TestParseGitPath(t *testing.T) { data := []struct { url string - args []string + args string repo, path string }{ {"git+https://github.com/hairyhenderson/gomplate//docs-src/content/functions/aws.yml", - nil, + "", "git+https://github.com/hairyhenderson/gomplate", "/docs-src/content/functions/aws.yml"}, {"git+ssh://github.com/hairyhenderson/gomplate.git", - nil, + "", "git+ssh://github.com/hairyhenderson/gomplate.git", "/"}, {"https://github.com", - nil, + "", "https://github.com", "/"}, {"git://example.com/foo//file.txt#someref", - nil, + "", "git://example.com/foo#someref", "/file.txt"}, {"git+file:///home/foo/repo//file.txt#someref", - nil, + "", "git+file:///home/foo/repo#someref", "/file.txt"}, {"git+file:///repo", - nil, + "", "git+file:///repo", "/"}, {"git+file:///foo//foo", - nil, + "", "git+file:///foo", "/foo"}, {"git+file:///foo//foo", - []string{"/bar"}, + "/bar", "git+file:///foo", "/foo/bar"}, {"git+file:///foo//bar", // in this case the // is meaningless - []string{"/baz//qux"}, + "/baz//qux", "git+file:///foo", "/bar/baz/qux"}, {"git+https://example.com/foo", - []string{"/bar"}, + "/bar", "git+https://example.com/foo/bar", "/"}, {"git+https://example.com/foo", - []string{"//bar"}, + "//bar", "git+https://example.com/foo", "/bar"}, {"git+https://example.com//foo", - []string{"/bar"}, + "/bar", "git+https://example.com", "/foo/bar"}, {"git+https://example.com/foo//bar", - []string{"//baz"}, + "//baz", "git+https://example.com/foo", "/bar/baz"}, {"git+https://example.com/foo", - []string{"/bar//baz"}, + "/bar//baz", "git+https://example.com/foo/bar", "/baz"}, {"git+https://example.com/foo?type=t", - []string{"/bar//baz"}, + "/bar//baz", "git+https://example.com/foo/bar?type=t", "/baz"}, {"git+https://example.com/foo#master", - []string{"/bar//baz"}, + "/bar//baz", "git+https://example.com/foo/bar#master", "/baz"}, {"git+https://example.com/foo", - []string{"/bar//baz?type=t"}, + "/bar//baz?type=t", "git+https://example.com/foo/bar?type=t", "/baz"}, {"git+https://example.com/foo", - []string{"/bar//baz#master"}, + "/bar//baz#master", "git+https://example.com/foo/bar#master", "/baz"}, {"git+https://example.com/foo", - []string{"//bar?type=t"}, + "//bar?type=t", "git+https://example.com/foo?type=t", "/bar"}, {"git+https://example.com/foo", - []string{"//bar#master"}, + "//bar#master", "git+https://example.com/foo#master", "/bar"}, {"git+https://example.com/foo?type=t", - []string{"//bar#master"}, + "//bar#master", "git+https://example.com/foo?type=t#master", "/bar"}, {"git+https://example.com/foo?type=t#v1", - []string{"//bar?type=j#v2"}, + "//bar?type=j#v2", "git+https://example.com/foo?type=t&type=j#v2", "/bar"}, } @@ -180,7 +180,11 @@ func TestParseGitPath(t *testing.T) { t.Run(fmt.Sprintf("%d:(%q,%q)==(%q,%q)", i, d.url, d.args, d.repo, d.path), func(t *testing.T) { t.Parallel() u, _ := url.Parse(d.url) - repo, path, err := g.parseGitPath(u, d.args...) + args := []string{d.args} + if d.args == "" { + args = nil + } + repo, path, err := g.parseGitPath(u, args...) assert.NilError(t, err) assert.Equal(t, d.repo, repo.String()) assert.Equal(t, d.path, path) |
