summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2019-05-02 22:25:54 -0700
committerDave Henderson <dhenderson@gmail.com>2019-05-02 22:28:30 -0700
commit2be2c1168085e0234a0cf06dab93b6d763bf3f7d (patch)
tree8debeb071f9f246785817c97480edceaba1f4cd5 /data
parentb65e14e1fda1c005a07ec9b98e746ce3d699521a (diff)
Linting more (and fixing more)
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'data')
-rw-r--r--data/data.go16
-rw-r--r--data/datasource_file_test.go2
-rw-r--r--data/datasource_http_test.go31
-rw-r--r--data/datasource_vault.go8
4 files changed, 14 insertions, 43 deletions
diff --git a/data/data.go b/data/data.go
index 63596936..1a0c6218 100644
--- a/data/data.go
+++ b/data/data.go
@@ -139,20 +139,20 @@ func parseCSV(args ...string) ([][]string, []string, error) {
func csvParseArgs(args ...string) (in, delim string, hdr []string) {
delim = ","
- if len(args) == 1 {
+ switch len(args) {
+ case 1:
in = args[0]
- }
- if len(args) == 2 {
+ case 2:
in = args[1]
- if len(args[0]) == 1 {
+ switch len(args[0]) {
+ case 1:
delim = args[0]
- } else if len(args[0]) == 0 {
+ case 0:
hdr = []string{}
- } else {
+ default:
hdr = strings.Split(args[0], delim)
}
- }
- if len(args) == 3 {
+ case 3:
delim = args[0]
hdr = strings.Split(args[1], delim)
in = args[2]
diff --git a/data/datasource_file_test.go b/data/datasource_file_test.go
index 1284113e..ebdc4c4a 100644
--- a/data/datasource_file_test.go
+++ b/data/datasource_file_test.go
@@ -59,7 +59,7 @@ func TestReadFile(t *testing.T) {
source.fs = fs
actual, err = readFile(source, "foo.txt")
assert.NoError(t, err)
- assert.Equal(t, []byte(content), actual)
+ assert.Equal(t, content, actual)
mime, err = source.mimeType()
assert.NoError(t, err)
assert.Equal(t, "application/json", mime)
diff --git a/data/datasource_http_test.go b/data/datasource_http_test.go
index 62531241..f35733db 100644
--- a/data/datasource_http_test.go
+++ b/data/datasource_http_test.go
@@ -162,37 +162,6 @@ func TestParseHeaderArgs(t *testing.T) {
assert.Equal(t, expected, parsed)
}
-func TestHTTPFileWithSubPath(t *testing.T) {
- server, client := setupHTTP(200, "application/json; charset=utf-8", `{"hello": "world"}`)
- defer server.Close()
-
- sources := make(map[string]*Source)
- sources["foo"] = &Source{
- Alias: "foo",
- URL: &url.URL{
- Scheme: "http",
- Host: "example.com",
- Path: "/foo",
- },
- hc: client,
- }
- data := &Data{
- Sources: sources,
- }
-
- expected := map[string]interface{}{
- "hello": "world",
- }
-
- actual, err := data.Datasource("foo")
- assert.NoError(t, err)
- assert.Equal(t, must(marshalObj(expected, json.Marshal)), must(marshalObj(actual, json.Marshal)))
-
- actual, err = data.Datasource(server.URL)
- assert.NoError(t, err)
- assert.Equal(t, must(marshalObj(expected, json.Marshal)), must(marshalObj(actual, json.Marshal)))
-}
-
func TestBuildURL(t *testing.T) {
expected := "https://example.com/index.html"
base := mustParseURL(expected)
diff --git a/data/datasource_vault.go b/data/datasource_vault.go
index 143a71e9..18b478be 100644
--- a/data/datasource_vault.go
+++ b/data/datasource_vault.go
@@ -51,17 +51,19 @@ func readVault(source *Source, args ...string) (data []byte, err error) {
}
source.mediaType = jsonMimetype
- if len(params) > 0 {
+ switch {
+ case len(params) > 0:
data, err = source.vc.Write(p, params)
- } else if strings.HasSuffix(p, "/") {
+ case strings.HasSuffix(p, "/"):
source.mediaType = jsonArrayMimetype
data, err = source.vc.List(p)
- } else {
+ default:
data, err = source.vc.Read(p)
}
if err != nil {
return nil, err
}
+
if len(data) == 0 {
return nil, errors.Errorf("no value found for path %s", p)
}