xref: /openbmc/google-misc/nemora-postd/subprojects/ncsid/test/normalize_ip_test.sh (revision 5948667977468c8832b332e5d2163d66b8a31be4)
11285115cSWilliam A. Kennington III#!/bin/bash
21285115cSWilliam A. Kennington III# Copyright 2021 Google LLC
31285115cSWilliam A. Kennington III#
41285115cSWilliam A. Kennington III# Licensed under the Apache License, Version 2.0 (the "License");
51285115cSWilliam A. Kennington III# you may not use this file except in compliance with the License.
61285115cSWilliam A. Kennington III# You may obtain a copy of the License at
71285115cSWilliam A. Kennington III#
81285115cSWilliam A. Kennington III#      http://www.apache.org/licenses/LICENSE-2.0
91285115cSWilliam A. Kennington III#
101285115cSWilliam A. Kennington III# Unless required by applicable law or agreed to in writing, software
111285115cSWilliam A. Kennington III# distributed under the License is distributed on an "AS IS" BASIS,
121285115cSWilliam A. Kennington III# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131285115cSWilliam A. Kennington III# See the License for the specific language governing permissions and
141285115cSWilliam A. Kennington III# limitations under the License.
151285115cSWilliam A. Kennington III
161285115cSWilliam A. Kennington IIITEST_DIR="$(dirname "${BASH_SOURCE[0]}")"
171285115cSWilliam A. Kennington IIIsource "$TEST_DIR"/test_lib.sh
181285115cSWilliam A. Kennington III
19*59486679SPatrick Williamsfunction TestNormalizeIPInvalidArgs() {
201285115cSWilliam A. Kennington III    ! "$NORMALIZE_IP"
211285115cSWilliam A. Kennington III    ! "$NORMALIZE_IP" '192.168.10.1' 'extra'
221285115cSWilliam A. Kennington III}
231285115cSWilliam A. Kennington III
24*59486679SPatrick Williamsfunction TestNormalizeIPBadIP() {
251285115cSWilliam A. Kennington III    ! "$NORMALIZE_IP" '0f0.100.595.444'
261285115cSWilliam A. Kennington III    ! "$NORMALIZE_IP" 'fx80::1'
271285115cSWilliam A. Kennington III}
281285115cSWilliam A. Kennington III
29*59486679SPatrick Williamsfunction TestNormalizeIPv4() {
301285115cSWilliam A. Kennington III    StrEq "$("$NORMALIZE_IP" '192.168.10.1')" '192.168.10.1'
311285115cSWilliam A. Kennington III    StrEq "$("$NORMALIZE_IP" '1.1.1.1')" '1.1.1.1'
321285115cSWilliam A. Kennington III}
331285115cSWilliam A. Kennington III
34*59486679SPatrick Williamsfunction TestNormalizeIPv6() {
351285115cSWilliam A. Kennington III    StrEq "$("$NORMALIZE_IP" 'fe80:00B1::0000:1')" 'fe80:b1::1'
361285115cSWilliam A. Kennington III}
371285115cSWilliam A. Kennington III
381285115cSWilliam A. Kennington IIITESTS+=(
391285115cSWilliam A. Kennington III    TestNormalizeIPInvalidArgs
401285115cSWilliam A. Kennington III    TestNormalizeIPBadIP
411285115cSWilliam A. Kennington III    TestNormalizeIPv4
421285115cSWilliam A. Kennington III    TestNormalizeIPv6
431285115cSWilliam A. Kennington III)
441285115cSWilliam A. Kennington III
451285115cSWilliam A. Kennington IIIreturn 0 2>/dev/null
461285115cSWilliam A. Kennington IIITestAnythingMain
47