test: add new cli-pretty unit test

This test is a "unit" test, which implies that it can be executed
locally without access to a Infix target environment.

Signed-off-by: Richard Alpe <richard@bit42.se>
This commit is contained in:
Richard Alpe
2023-09-06 16:11:59 +02:00
committed by Joachim Wiberg
parent 7b0bd77d16
commit 1ea658ad1d
5 changed files with 430 additions and 0 deletions
+39
View File
@@ -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"
+321
View File
@@ -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
}
}
}
]
}
}
+5
View File
@@ -0,0 +1,5 @@
{
"ietf-interfaces:interfaces": {
"interface": []
}
}
+39
View File
@@ -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
}
}
]
}
}
+26
View File
@@ -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