| #!/bin/bash |
| # Copyright 2021 Google LLC |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| TEST_DIR="$(dirname "${BASH_SOURCE[0]}")" |
| source "$TEST_DIR"/test_lib.sh |
| |
| function TestNormalizeIPInvalidArgs() { |
| ! "$NORMALIZE_IP" |
| ! "$NORMALIZE_IP" '192.168.10.1' 'extra' |
| } |
| |
| function TestNormalizeIPBadIP() { |
| ! "$NORMALIZE_IP" '0f0.100.595.444' |
| ! "$NORMALIZE_IP" 'fx80::1' |
| } |
| |
| function TestNormalizeIPv4() { |
| StrEq "$("$NORMALIZE_IP" '192.168.10.1')" '192.168.10.1' |
| StrEq "$("$NORMALIZE_IP" '1.1.1.1')" '1.1.1.1' |
| } |
| |
| function TestNormalizeIPv6() { |
| StrEq "$("$NORMALIZE_IP" 'fe80:00B1::0000:1')" 'fe80:b1::1' |
| } |
| |
| TESTS+=( |
| TestNormalizeIPInvalidArgs |
| TestNormalizeIPBadIP |
| TestNormalizeIPv4 |
| TestNormalizeIPv6 |
| ) |
| |
| return 0 2>/dev/null |
| TestAnythingMain |