blob: 1c0fd5a2e85495b07b712e754de4efc9015ca110 [file] [log] [blame]
William A. Kennington III7d6fa422021-02-08 17:04:02 -08001#!/bin/bash
Brandon Kimdab96f12021-02-18 11:21:37 -08002# Copyright 2021 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
William A. Kennington III7d6fa422021-02-08 17:04:02 -080016TEST_DIR="$(dirname "${BASH_SOURCE[0]}")"
17source "$TEST_DIR"/test_lib.sh
18
Patrick Williams59486672022-12-08 06:23:47 -060019function TestNormalizeIPInvalidArgs() {
20 ! "$NORMALIZE_IP"
21 ! "$NORMALIZE_IP" '192.168.10.1' 'extra'
William A. Kennington III7d6fa422021-02-08 17:04:02 -080022}
23
Patrick Williams59486672022-12-08 06:23:47 -060024function TestNormalizeIPBadIP() {
25 ! "$NORMALIZE_IP" '0f0.100.595.444'
26 ! "$NORMALIZE_IP" 'fx80::1'
William A. Kennington III7d6fa422021-02-08 17:04:02 -080027}
28
Patrick Williams59486672022-12-08 06:23:47 -060029function TestNormalizeIPv4() {
30 StrEq "$("$NORMALIZE_IP" '192.168.10.1')" '192.168.10.1'
31 StrEq "$("$NORMALIZE_IP" '1.1.1.1')" '1.1.1.1'
William A. Kennington III7d6fa422021-02-08 17:04:02 -080032}
33
Patrick Williams59486672022-12-08 06:23:47 -060034function TestNormalizeIPv6() {
35 StrEq "$("$NORMALIZE_IP" 'fe80:00B1::0000:1')" 'fe80:b1::1'
William A. Kennington III7d6fa422021-02-08 17:04:02 -080036}
37
38TESTS+=(
Patrick Williams59486672022-12-08 06:23:47 -060039 TestNormalizeIPInvalidArgs
40 TestNormalizeIPBadIP
41 TestNormalizeIPv4
42 TestNormalizeIPv6
William A. Kennington III7d6fa422021-02-08 17:04:02 -080043)
44
45return 0 2>/dev/null
46TestAnythingMain