diff --git a/test/case/cli_pretty/all.yaml b/test/case/cli_pretty/all.yaml new file mode 100644 index 00000000..e5074989 --- /dev/null +++ b/test/case/cli_pretty/all.yaml @@ -0,0 +1,39 @@ +--- +- case: run.sh + name: "interfaces-empty" + opts: + - "json/empty.json" + - "ietf-interfaces" + +- case: run.sh + name: "interfaces-factory" + opts: + - "json/factory.json" + - "ietf-interfaces" + +- case: run.sh + name: "interfaces-bloated" + opts: + - "json/bloated.json" + - "ietf-interfaces" + +- case: run.sh + name: "interface-ethernet" + opts: + - "json/bloated.json" + - "ietf-interfaces" + - "-n e0" + +- case: run.sh + name: "interface-vlan" + opts: + - "json/bloated.json" + - "ietf-interfaces" + - "-n vlan1" + +- case: run.sh + name: "interface-birdge" + opts: + - "json/bloated.json" + - "ietf-interfaces" + - "-n br0" diff --git a/test/case/cli_pretty/json/bloated.json b/test/case/cli_pretty/json/bloated.json new file mode 100644 index 00000000..77634ade --- /dev/null +++ b/test/case/cli_pretty/json/bloated.json @@ -0,0 +1,321 @@ +{ + "ietf-interfaces:interfaces": { + "interface": [ + { + "TEST-DESCR": "Normal loopback", + "name": "lo", + "type": "iana-if-type:softwareLoopback", + "oper-status": "up", + "if-index": 1, + "phys-address": "00:00:00:00:00:00", + "statistics": { + "in-octets": "3099", + "out-octets": "3099" + }, + "ietf-ip:ipv4": { + "address": [ + { + "ip": "127.0.0.1", + "prefix-length": 8 + } + ] + } + }, + { + "TEST-DESCR": "Bridge interface with IP", + "name": "e0", + "type": "iana-if-type:ethernetCsmacd", + "oper-status": "up", + "if-index": 2, + "phys-address": "02:00:00:00:00:00", + "statistics": { + "in-octets": "0", + "out-octets": "21286" + }, + "ietf-ip:ipv4": { + "mtu": 1500, + "address": [ + { + "ip": "192.168.1.1", + "prefix-length": 24 + } + ] + }, + "infix-interfaces:bridge-port": { + "bridge": "br0" + } + }, + { + "TEST-DESCR": "Bridge interface without IP", + "name": "e1", + "type": "iana-if-type:ethernetCsmacd", + "oper-status": "up", + "if-index": 4, + "phys-address": "02:00:00:00:00:00", + "statistics": { + "in-octets": "0", + "out-octets": "21286" + }, + "ietf-ip:ipv4": { + "mtu": 1500 + }, + "infix-interfaces:bridge-port": { + "bridge": "br0" + } + }, + { + "TEST-DESCR": "Bridge interface without IP", + "name": "e1", + "type": "iana-if-type:ethernetCsmacd", + "oper-status": "up", + "if-index": 4, + "phys-address": "02:00:00:00:00:00", + "statistics": { + "in-octets": "0", + "out-octets": "21286" + }, + "ietf-ip:ipv4": { + "mtu": 1500 + }, + "infix-interfaces:bridge-port": { + "bridge": "br1" + } + }, + { + "TEST-DESCR": "Interface without IP", + "name": "e10", + "type": "iana-if-type:ethernetCsmacd", + "oper-status": "up", + "if-index": 4, + "phys-address": "02:00:00:00:00:00", + "statistics": { + "in-octets": "0", + "out-octets": "21286" + }, + "ietf-ip:ipv4": { + "mtu": 1500 + } + }, + { + "TEST-DESCR": "Interface with single IP", + "name": "e11", + "type": "iana-if-type:ethernetCsmacd", + "oper-status": "up", + "if-index": 4, + "phys-address": "02:00:00:00:ee:ff", + "statistics": { + "in-octets": "21280", + "out-octets": "21281" + }, + "ietf-ip:ipv4": { + "mtu": 1500, + "address": [ + { + "ip": "192.168.5.1", + "prefix-length": 24 + } + ] + } + }, + { + "TEST-DESCR": "Interface with many IP", + "name": "e12", + "type": "iana-if-type:ethernetCsmacd", + "oper-status": "up", + "if-index": 4, + "phys-address": "02:00:00:00:ee:ff", + "statistics": { + "in-octets": "21280", + "out-octets": "21281" + }, + "ietf-ip:ipv4": { + "mtu": 1500, + "address": [ + { + "ip": "192.168.1.1", + "prefix-length": 24 + }, + { + "ip": "192.168.2.1", + "prefix-length": 24 + }, + { + "ip": "192.168.3.1", + "prefix-length": 24 + }, + { + "ip": "192.168.4.1", + "prefix-length": 24 + }, + { + "ip": "10.0.1.1", + "prefix-length": 24 + } + ] + } + }, + { + "TEST-DESCR": "Interface with VLAN on top", + "name": "e20", + "type": "iana-if-type:ethernetCsmacd", + "oper-status": "up", + "if-index": 4, + "phys-address": "02:00:00:00:ee:ff", + "statistics": { + "in-octets": "21280", + "out-octets": "21281" + }, + "ietf-ip:ipv4": { + "mtu": 1500, + "address": [ + { + "ip": "192.168.1.1", + "prefix-length": 24 + } + ] + } + }, + { + "TEST-DESCR": "Bridge without IP", + "name": "br0", + "type": "iana-if-type:bridge", + "oper-status": "up", + "if-index": 2, + "phys-address": "02:00:00:00:00:00", + "statistics": { + "in-octets": "0", + "out-octets": "378" + }, + "ietf-ip:ipv4": { + "mtu": 1500 + } + }, + { + "TEST-DESCR": "Bridge with IP", + "name": "br1", + "type": "iana-if-type:bridge", + "oper-status": "up", + "if-index": 3, + "phys-address": "02:00:00:00:00:00", + "statistics": { + "in-octets": "0", + "out-octets": "378" + }, + "ietf-ip:ipv4": { + "mtu": 1500, + "address": [ + { + "ip": "192.168.1.1", + "prefix-length": 24 + } + ] + } + }, + { + "TEST-DESCR": "Empty bridge with IP", + "name": "br2", + "type": "iana-if-type:bridge", + "oper-status": "up", + "if-index": 3, + "phys-address": "02:00:00:00:00:00", + "statistics": { + "in-octets": "0", + "out-octets": "378" + }, + "ietf-ip:ipv4": { + "mtu": 1500, + "address": [ + { + "ip": "192.168.1.1", + "prefix-length": 24 + }, + { + "ip": "10.0.1.1", + "prefix-length": 24 + } + ] + } + }, + { + "TEST-DESCR": "VLAN on bridge", + "name": "vlan1", + "type": "iana-if-type:l2vlan", + "oper-status": "up", + "if-index": 4, + "phys-address": "02:00:00:00:00:00", + "statistics": { + "in-octets": "0", + "out-octets": "0" + }, + "ietf-if-extensions:parent-interface": "br0", + "ietf-ip:ipv4": { + "mtu": 1500 + }, + "ietf-if-vlan-encapsulation:dot1q-vlan": { + "outer-tag": { + "tag-type": "ieee802-dot1q-types:c-vlan", + "vlan-id": 10 + } + } + }, + { + "TEST-DESCR": "VLAN with IP on bridge", + "name": "vlan2", + "type": "iana-if-type:l2vlan", + "oper-status": "up", + "if-index": 4, + "phys-address": "02:00:00:00:00:00", + "statistics": { + "in-octets": "0", + "out-octets": "0" + }, + "ietf-if-extensions:parent-interface": "br0", + "ietf-ip:ipv4": { + "mtu": 1500, + "address": [ + { + "ip": "192.168.2.1", + "prefix-length": 24 + } + ] + }, + "ietf-if-vlan-encapsulation:dot1q-vlan": { + "outer-tag": { + "tag-type": "ieee802-dot1q-types:c-vlan", + "vlan-id": 20 + } + } + }, + { + "name": "vlan20", + "type": "iana-if-type:l2vlan", + "oper-status": "up", + "if-index": 4, + "phys-address": "02:00:00:00:00:00", + "statistics": { + "in-octets": "0", + "out-octets": "0" + }, + "ietf-if-extensions:parent-interface": "e20", + "ietf-ip:ipv4": { + "mtu": 1500 + }, + "ietf-ip:ipv4": { + "mtu": 1500, + "address": [ + { + "ip": "192.168.2.1", + "prefix-length": 24 + } + ] + }, + "ietf-if-vlan-encapsulation:dot1q-vlan": { + "outer-tag": { + "tag-type": "ieee802-dot1q-types:c-vlan", + "vlan-id": 10 + } + } + } + ] + } +} diff --git a/test/case/cli_pretty/json/empty.json b/test/case/cli_pretty/json/empty.json new file mode 100644 index 00000000..205fab9b --- /dev/null +++ b/test/case/cli_pretty/json/empty.json @@ -0,0 +1,5 @@ +{ + "ietf-interfaces:interfaces": { + "interface": [] + } +} diff --git a/test/case/cli_pretty/json/factory.json b/test/case/cli_pretty/json/factory.json new file mode 100644 index 00000000..37aa1210 --- /dev/null +++ b/test/case/cli_pretty/json/factory.json @@ -0,0 +1,39 @@ +{ + "ietf-interfaces:interfaces": { + "interface": [ + { + "name": "lo", + "type": "infix-if-type:loopback", + "oper-status": "up", + "if-index": 1, + "phys-address": "00:00:00:00:00:00", + "statistics": { + "in-octets": "3035", + "out-octets": "3035" + }, + "ietf-ip:ipv4": { + "address": [ + { + "ip": "127.0.0.1", + "prefix-length": 8 + } + ] + } + }, + { + "name": "e0", + "type": "infix-if-type:ethernet", + "oper-status": "up", + "if-index": 2, + "phys-address": "02:00:00:00:00:00", + "statistics": { + "in-octets": "550", + "out-octets": "13724" + }, + "ietf-ip:ipv4": { + "mtu": 1500 + } + } + ] + } +} diff --git a/test/case/cli_pretty/run.sh b/test/case/cli_pretty/run.sh new file mode 100755 index 00000000..7b286a0a --- /dev/null +++ b/test/case/cli_pretty/run.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +SCRIPT_PATH="$(dirname "$(readlink -f "$0")")" + +set -o pipefail + +if [ $# -lt 2 ]; then + echo "Usage: $0 JSON-FILE MODULE [ ARGS ]" + exit 1 +fi + +json=$1; shift +module=$1; shift + +echo "1..1" + +cat "$SCRIPT_PATH/$json" | \ + "$SCRIPT_PATH"/../../../board/netconf/rootfs/lib/infix/cli-pretty \ + "$module" $* +if [ $? -eq 0 ]; then + echo "ok 1 - $json printed without crashing" + exit 0 +fi + +echo "not ok 1 - $json printing returned non zero" +exit 1