diff options
author | Dominik Ritter <dritter03@googlemail.com> | 2019-02-03 21:20:14 +0300 |
---|---|---|
committer | Dominik Ritter <dritter03@googlemail.com> | 2019-02-03 21:20:14 +0300 |
commit | 40e04e053cae8b49b5b82c047660369f962d1975 (patch) | |
tree | c66bf2e5c13cd91592169a1e679631fc13a394bd /test/segments/vpn_ip.spec | |
parent | 747b94b1b6b8450375a2b1619d8a5c7336be1852 (diff) |
Parse IPs properly
This is done if we want to show a public IP, internal IP, or a VPN.
In the VPN case, what we actually want is to display an indicator
that a VPN is active, instead of the VPN IP itself. We parse the
IP here anyway, because we want to save some specific code there.
Diffstat (limited to 'test/segments/vpn_ip.spec')
-rwxr-xr-x | test/segments/vpn_ip.spec | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/test/segments/vpn_ip.spec b/test/segments/vpn_ip.spec index 3333fd07..13a3e60a 100755 --- a/test/segments/vpn_ip.spec +++ b/test/segments/vpn_ip.spec @@ -95,6 +95,15 @@ function fakeIp() { INNER fi + if [[ "\$*" =~ '-brief.*show' ]]; then + cat <<INNER +lo UNKNOWN 127.0.0.1/8 +${INTERFACE1} UP 1.2.3.4/24 +${INTERFACE2} UP 5.4.3.2/16 +docker0 DOWN 172.17.0.1/16 +INNER + fi + if [[ "\$*" =~ 'show ${INTERFACE1}' ]]; then cat <<INNER 3: ${INTERFACE1}: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 @@ -116,27 +125,33 @@ EOF } function testVpnIpSegmentPrintsNothingOnOsxIfNotConnected() { - alias ifconfig='echo "not connected"' - # Load Powerlevel9k source powerlevel9k.zsh-theme local OS="OSX" # Fake OSX - assertEquals "" "$(prompt_vpn_ip left 1 false "$FOLDER")" + cat > $FOLDER/sbin/ifconfig <<EOF +#!/usr/bin/env zsh + +echo "not connected" +EOF + chmod +x $FOLDER/sbin/ifconfig - unalias ifconfig + assertEquals "" "$(prompt_vpn_ip left 1 false "$FOLDER")" } function testVpnIpSegmentPrintsNothingOnLinuxIfNotConnected() { - alias ip='echo "not connected"' - # Load Powerlevel9k source powerlevel9k.zsh-theme local OS="Linux" # Fake Linux - assertEquals "" "$(prompt_vpn_ip left 1 false "$FOLDER")" + cat > $FOLDER/sbin/ip <<EOF +#!/usr/bin/env zsh - unalias ip +echo "not connected" +EOF + chmod +x $FOLDER/sbin/ip + + assertEquals "" "$(prompt_vpn_ip left 1 false "$FOLDER")" } function testVpnIpSegmentWorksOnOsxWithInterfaceSpecified() { @@ -160,7 +175,7 @@ function testVpnIpSegmentWorksOnLinuxWithInterfaceSpecified() { source powerlevel9k.zsh-theme local OS='Linux' # Fake Linux - assertEquals "%K{006} %F{000}(vpn) %f%F{000}10.0.2.15 " "$(prompt_vpn_ip left 1 false "$FOLDER")" + assertEquals "%K{006} %F{000}(vpn) %f%F{000}1.2.3.4 " "$(prompt_vpn_ip left 1 false "$FOLDER")" } # vpn_ip is not capable of handling multiple vpn interfaces ATM. |