Skip to content

Instantly share code, notes, and snippets.

@dracorp
Created April 12, 2022 07:10
Show Gist options
  • Save dracorp/c365dc1ff6320250ab2d40b1e738e7b9 to your computer and use it in GitHub Desktop.
Save dracorp/c365dc1ff6320250ab2d40b1e738e7b9 to your computer and use it in GitHub Desktop.

Revisions

  1. dracorp created this gist Apr 12, 2022.
    23 changes: 23 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    import groovy.util.Eval

    def compareArrays(def first, def path = '', def second) {
    if (first instanceof java.util.LinkedHashMap) {
    first.each { index, value ->
    if ( index.indexOf('-') > 0 ) {
    index = index.inspect()
    }
    if ( value instanceof java.util.LinkedHashMap ) {
    def newPath = path ? path + "." + index : index
    compareArrays(value, newPath, second)
    } else {
    def newPath = path ? path + "." + index : index
    def secondValue = Eval.me("array", second, "array.$newPath")
    if (secondValue == null ) {
    println "ERROR: Missing path $newPath in second array!"
    } else if ( value != secondValue ) {
    println "ERROR: Different value for path: $newPath, '$value != '$secondValue"
    }
    }
    }
    }
    }
    14 changes: 14 additions & 0 deletions gistfile2.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    def compareArrays(def first, def second) {
    first = first as ConfigObject
    second = second as ConfigObject
    def firstProps = first.toProperties()
    def secondProps = second.toProperties()
    firstProps.each { index, value ->
    def secondValue = secondProps[index]
    if (secondValue == null ) {
    println "ERROR: Missing path $index in second array!"
    } else if ( value != secondValue ) {
    println "ERROR: Different value for path: $index, '$value != '$secondValue"
    }
    }
    }
    23 changes: 23 additions & 0 deletions gistfile3.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    // sample of array
    def First = [
    "PROD": [
    "service1: [
    "key1": "value1",
    "key2": "value2"
    ],
    "service2: [
    "key1": "value1",
    "key2": "value2"
    ]
    ],
    "DEV": [
    "service1: [
    "key1": "value1",
    "key2": "value2"
    ],
    "service2: [
    "key1": "value1",
    "key2": "value2"
    ]
    ]
    ]