• Victor Nogueira's avatar
    selftests: tc-testing: Add matchJSON to tdc · 95d9a3da
    Victor Nogueira authored
    This allows the use of a matchJSON field in tests to match
    against JSON output from the command under test, if that
    command outputs JSON.
    
    You specify what you want to match against as a JSON array
    or object in the test's matchJSON field. You can leave out
    any fields you don't want to match against that are present
    in the output and they will be skipped.
    
    An example matchJSON value would look like this:
    
    "matchJSON": [
      {
        "Value": {
          "neighIP": {
            "family": 4,
            "addr": "AQIDBA==",
            "width": 32
          },
          "nsflags": 142,
          "ncflags": 0,
          "LLADDR": "ESIzRFVm"
        }
      }
    ]
    
    The real output from the command under test might have some
    extra fields that we don't care about for matching, and
    since we didn't include them in our matchJSON value, those
    fields will not be attempted to be matched. If everything
    we included above has the same values as the real command
    output, the test will pass.
    
    The matchJSON field's type must be the same as the command
    output's type, otherwise the test will fail. So if the
    command outputs an array, then the value of matchJSON must
    also be an array.
    
    If matchJSON is an array, it must not contain more elements
    than the command output's array, otherwise the test will
    fail.
    Signed-off-by: default avatarJeremy Carter <jeremy@mojatatu.com>
    Signed-off-by: default avatarVictor Nogueira <victor@mojatatu.com>
    Acked-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
    Link: https://lore.kernel.org/r/20221024111603.2185410-1-victor@mojatatu.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
    95d9a3da
tdc.py 30.3 KB