Skip to content

Commit

Permalink
Merge pull request #66 from JoshKCarroll/64-bug-fixes
Browse files Browse the repository at this point in the history
Bug fixes related to #64
  • Loading branch information
JoshuaC215 authored Jan 10, 2018
2 parents 677dc19 + 431921c commit da17ca4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package: github.com/qntfy/kazaam
import:
- package: github.com/qntfy/jsonparser
version: ^1.0.0
version: ^1.0.1
- package: github.com/satori/go.uuid
version: v1.1.0
5 changes: 4 additions & 1 deletion transform/coalesce.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func Coalesce(spec *Config, data []byte) ([]byte, error) {
ignoreSlice := [][]byte{[]byte("null")}
ignoreList, ignoreOk := (*spec.Spec)["ignore"]
if ignoreOk {
delete((*spec.Spec), "ignore")
for _, iItem := range ignoreList.([]interface{}) {
iByte, err := json.Marshal(iItem)
if err != nil {
Expand All @@ -35,6 +34,10 @@ func Coalesce(spec *Config, data []byte) ([]byte, error) {
}

for k, v := range *spec.Spec {
if k == "ignore" {
continue
}

var keyList []string

// check if `v` is a list and build a list of keys to evaluate
Expand Down
12 changes: 12 additions & 0 deletions transform/coalesce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@ func TestCoalesceWithIgnore(t *testing.T) {
t.Log("Actual: ", string(kazaamOut))
t.FailNow()
}

// confirm that no configs were harmed in the making of this transform
kazaamOut, _ = getTransformTestWrapper(Coalesce, cfg, jsonInput)
areEqual, _ = checkJSONBytesEqual(kazaamOut, []byte(jsonOut))

if !areEqual {
t.Error("Transformed data does not match expectation on second iteration.")
t.Log("Expected: ", jsonOut)
t.Log("Actual: ", string(kazaamOut))
t.FailNow()
}

}
24 changes: 24 additions & 0 deletions transform/shift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,30 @@ func TestShiftDeepNoArraysRequire(t *testing.T) {
}
}

func TestShiftDeepTrickyPath(t *testing.T) {
spec := `{"Rating": "rating.exist"}`
jsonIn := `{"rating":"bar","foo":{"exist":"baz"}}`
jsonOut := `{"Rating":null}`

cfg := getConfig(spec, false)
kazaamOut, err := getTransformTestWrapper(Shift, cfg, jsonIn)

if err != nil {
t.Error("Error on transform.")
t.Log("Expected: ", jsonOut)
t.Log("Error: ", err.Error())
t.FailNow()
}

areEqual, _ := checkJSONBytesEqual(kazaamOut, []byte(jsonOut))
if !areEqual {
t.Error("Transformed data does not match expectation.")
t.Log("Expected: ", jsonOut)
t.Log("Actual: ", string(kazaamOut))
t.FailNow()
}
}

func TestShiftWithEncapsulate(t *testing.T) {
jsonOut := `{"data":[{"rating":{"example":{"value":3},"primary":{"value":3}}}]}`
spec := `{"data": ["$"]}`
Expand Down

0 comments on commit da17ca4

Please # to comment.