Explorar el Código

revert back to interface

Alexander Belanger hace 5 años
padre
commit
c15fd12166
Se han modificado 2 ficheros con 40 adiciones y 4 borrados
  1. 3 4
      internal/templater/utils/query.go
  2. 37 0
      internal/templater/utils/query_test.go

+ 3 - 4
internal/templater/utils/query.go

@@ -2,7 +2,6 @@ package utils
 
 
 import (
 import (
 	"fmt"
 	"fmt"
-	"strings"
 
 
 	"github.com/porter-dev/porter/internal/templater"
 	"github.com/porter-dev/porter/internal/templater"
 	"k8s.io/client-go/util/jsonpath"
 	"k8s.io/client-go/util/jsonpath"
@@ -44,15 +43,15 @@ func QueryValues(
 			continue
 			continue
 		}
 		}
 
 
-		queryRes := make([]string, 0)
+		queryRes := make([]interface{}, 0)
 
 
 		for ix := range fullResults {
 		for ix := range fullResults {
 			for _, result := range fullResults[ix] {
 			for _, result := range fullResults[ix] {
-				queryRes = append(queryRes, fmt.Sprintf("%v", result.Interface()))
+				queryRes = append(queryRes, result.Interface())
 			}
 			}
 		}
 		}
 
 
-		res[query.Key] = strings.Join(queryRes, ",")
+		res[query.Key] = queryRes
 	}
 	}
 
 
 	return res, nil
 	return res, nil

+ 37 - 0
internal/templater/utils/query_test.go

@@ -0,0 +1,37 @@
+package utils_test
+
+import (
+	"encoding/json"
+	"testing"
+
+	"github.com/porter-dev/porter/internal/templater"
+	"github.com/porter-dev/porter/internal/templater/utils"
+)
+
+type testType struct {
+	Value interface{} `json:"value,omitempty"`
+}
+
+func TestQueryValues(t *testing.T) {
+	vals := map[string]interface{}{
+		"testing": map[string]interface{}{
+			"hello": "there",
+		},
+	}
+
+	queries := make([]*templater.TemplateReaderQuery, 0)
+
+	query, _ := utils.NewQuery("test", `{ .testing }`)
+
+	queries = append(queries, query)
+
+	res, _ := utils.QueryValues(vals, queries)
+
+	test := &testType{
+		Value: res["test"],
+	}
+
+	bytes, _ := json.Marshal(test)
+
+	t.Errorf(string(bytes))
+}