Make test-cmd work with OS-X tooling

OS-X thips with the BSD versions of `date` and `grep`. Those don't have
certain features the script relies on:
- BSD date does not support nanoseconds (`%N`)
- BSD grep does not support perl RegEx (`-P`)

As we use `bash` specifically in the hashbang anyway it is probably fine
to rely on the `$RANDOM` bashism here.
This commit is contained in:
Hannes Hörl 2018-03-19 18:52:27 +00:00
parent 18d9e1c450
commit 1bb3537c98

View File

@ -3868,7 +3868,7 @@ run_assert_categories_tests() {
set -o errexit
kube::log::status "Testing propagation of categories for resources"
output_message=$(kubectl get --raw=/api/v1 | grep -Po '"name":"pods".*?}')
output_message=$(kubectl get --raw=/api/v1 | grep -o '"name":"pods"[^}]*}')
kube::test::if_has_string "${output_message}" '"categories":\["all"\]'
set +o nounset
@ -4729,13 +4729,15 @@ runTests() {
kube::log::status "Checking kubectl version"
kubectl version
# use timestamp as the name of namespace because increasing the variable inside subshell
# does not affect the value of the variable outside the subshell.
# Generate a random namespace name, based on the current time (to make
# debugging slightly easier) and a random number. Don't use `date +%N`
# because that doesn't work on OSX.
create_and_use_new_namespace() {
namespace_number=$(date +%s%N)
kube::log::status "Creating namespace namespace${namespace_number}"
kubectl create namespace "namespace${namespace_number}"
kubectl config set-context "${CONTEXT}" --namespace="namespace${namespace_number}"
local ns_name
ns_name="namespace-$(date +%s)-${RANDOM}"
kube::log::status "Creating namespace ${ns_name}"
kubectl create namespace "$ns_name"
kubectl config set-context "${CONTEXT}" --namespace="$ns_name"
}
kube_flags=(