Joey Armstrong | f32accb | 2024-03-07 17:05:09 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bats |
| 2 | # ----------------------------------------------------------------------- |
| 3 | # Copyright 2024 Open Networking Foundation Contributors |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http:#www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # ----------------------------------------------------------------------- |
| 17 | # SPDX-FileCopyrightText: 2024 Open Networking Foundation Contributors |
| 18 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ----------------------------------------------------------------------- |
| 20 | |
| 21 | bats_require_minimum_version 1.5.0 |
| 22 | |
| 23 | # This runs before each of the following tests are executed. |
| 24 | setup() { |
| 25 | source '../../chart_version_check/filter_files.sh' |
| 26 | } |
| 27 | |
| 28 | ## ----------------------------------------------------------------------- |
| 29 | ## Intent: Validate the filter_files function |
| 30 | ## ----------------------------------------------------------------------- |
| 31 | @test 'Validate filter_files()' { |
| 32 | |
| 33 | local -a good=() # control |
| 34 | good+=('bar.c') |
| 35 | good+=('tans.c') |
| 36 | |
| 37 | local -a bad=() # garbage |
| 38 | bad+=('bar.c~') |
| 39 | bad+=('.#bar.c') |
| 40 | bad+=('#bar.c#') |
| 41 | |
| 42 | ## Generate a list of files and paths to filter |
| 43 | local -a src=() |
| 44 | for dir in '' 'foo/'; |
| 45 | do |
| 46 | for fyl in "${good[@]}" "${bad[@]}"; |
| 47 | do |
| 48 | src+=("${dir}${fyl}") |
| 49 | done |
| 50 | done |
| 51 | |
| 52 | local -a got=("${src[@]}") |
| 53 | |
| 54 | # Run is quarky, test ($?==0) and set -e |
| 55 | if false; then |
| 56 | run ! filter_files got |
| 57 | else |
| 58 | filter_files got |
| 59 | local status=$? |
| 60 | [ $status -eq 0 ] |
| 61 | fi |
| 62 | |
| 63 | ## ----------------------------------------- |
| 64 | ## Compare by size, filtered list is smaller |
| 65 | ## ----------------------------------------- |
| 66 | [ ${#src[@]} -eq 10 ] |
| 67 | [ ${#got[@]} -eq 4 ] |
| 68 | |
| 69 | ## ----------------------------------------- |
| 70 | ## Also sanity check strings since we are |
| 71 | ## not (yet) comparing list contents. |
| 72 | ## ----------------------------------------- |
| 73 | [[ ! "${got[*]}" == *'#'* ]] |
| 74 | [[ ! "${got[*]}" == *'~'* ]] |
| 75 | |
| 76 | local val |
| 77 | |
| 78 | ## Verify control values were not filtered |
| 79 | for val in "${good[@]}"; |
| 80 | do |
| 81 | [[ "${src[*]}" == *"$val"* ]] |
| 82 | [[ "${got[*]}" == *"$val"* ]] |
| 83 | done |
| 84 | |
| 85 | ## Verify garbage exists and was filtered |
| 86 | for val in "${bad[@]}"; |
| 87 | do |
| 88 | [[ "${src[*]}" == *"$val"* ]] |
| 89 | [[ ! "${got[*]}" == *"$val"* ]] |
| 90 | done |
| 91 | } |
| 92 | |
| 93 | # [EOF] |