-
Notifications
You must be signed in to change notification settings - Fork 10
/
_assertions.sh
executable file
·75 lines (65 loc) · 2.07 KB
/
_assertions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2021
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
set -o errexit
set -o nounset
set -o pipefail
KRD_DEBUG="${KRD_DEBUG:-false}"
if [[ ${KRD_DEBUG} == "true" ]]; then
set -o xtrace
fi
# shellcheck source=tests/_utils.sh
source _utils.sh
# assert_non_empty() - This assertion checks if the expected value is not empty
function assert_non_empty {
local input=$1
local error_msg=$2
if [[ $KRD_DEBUG == "true" ]]; then
debug "NonEmpty Assertion - value: $1"
fi
if [ -z "$input" ]; then
error "$error_msg"
fi
}
# assert_are_equal() - This assertion checks if the inputs are equal
function assert_are_equal {
local input=$1
local expected=$2
local error_msg=${3:-"got $input, want $expected"}
if [[ $KRD_DEBUG == "true" ]]; then
debug "Are equal Assertion - value: $1 expected: $2"
fi
if [ "$input" != "$expected" ]; then
error "$error_msg"
fi
}
# assert_are_not_equal() - This assertion checks if the inputs are not equal
function assert_are_not_equal {
local input=$1
local expected=$2
local error_msg=$3
if [[ $KRD_DEBUG == "true" ]]; then
debug "Are not equal Assertion - value: $1 expected: $2"
fi
if [ "$input" == "$expected" ]; then
error "$error_msg"
fi
}
# assert_contains() - This assertion checks if the input contains another value
function assert_contains {
local input=$1
local expected=$2
local error_msg=${3:-"$input doesn't contains $expected"}
if [[ $KRD_DEBUG == "true" ]]; then
debug "Contains Assertion - value: $1 expected: $2"
fi
if [[ $input != *"$expected"* ]]; then
error "$error_msg"
fi
}