Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ jobs:
tar xavf /tmp/helm.tar.gz
mv linux-amd64/helm /usr/local/bin/helm

pip install yq

sudo apt-get update
sudo apt-get install -y --no-install-recommends bats parallel
- name: "Add Helm dependencies"
Expand All @@ -51,10 +49,10 @@ jobs:
helm dependency build
- name: "Unit tests"
run: |
if [ -x ${{ matrix.chart }}/test/unit/run.sh ]; then
if [ -x ${{ matrix.chart }}/test/unit/run.sh ]; then
${{ matrix.chart }}/test/unit/run.sh -j 50
fi
if [ -x ${{ matrix.chart }}/test/unit_common/run.sh ]; then
if [ -x ${{ matrix.chart }}/test/unit_common/run.sh ]; then
${{ matrix.chart }}/test/unit_common/run.sh -j 50
fi
- name: Create package
Expand Down
6 changes: 3 additions & 3 deletions varnish-cache/test/unit/daemonset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ load _helpers
--namespace default \
--show-only templates/daemonset.yaml \
. || echo "---") | tee -a /dev/stderr |
yq -r -c '.spec.updateStrategy' | tee -a /dev/stderr)
yq -r -o=json -I=0 '.spec.updateStrategy' | tee -a /dev/stderr)

[ "${actual}" == "null" ]
}
Expand All @@ -64,7 +64,7 @@ load _helpers
--namespace default \
--show-only templates/daemonset.yaml \
. || echo "---") | tee -a /dev/stderr |
yq -r -c '.spec.updateStrategy' | tee -a /dev/stderr)
yq -r -o=json -I=0 '.spec.updateStrategy' | tee -a /dev/stderr)

[ "${actual}" == '{"rollingUpdate":{"maxUnavailable":1},"type":"RollingUpdate"}' ]
}
Expand All @@ -84,7 +84,7 @@ rollingUpdate:
--namespace default \
--show-only templates/daemonset.yaml \
. || echo "---") | tee -a /dev/stderr |
yq -r -c '.spec.updateStrategy' | tee -a /dev/stderr)
yq -r -o=json -I=0 '.spec.updateStrategy' | tee -a /dev/stderr)

[ "${actual}" == '{"type":"RollingUpdate","rollingUpdate":{"maxUnavailable":1}}' ]
}
Expand Down
6 changes: 3 additions & 3 deletions varnish-cache/test/unit/deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ load _helpers
--namespace default \
--show-only templates/deployment.yaml \
. || echo "---") | tee -a /dev/stderr |
yq -r -c '.spec.strategy' | tee -a /dev/stderr)
yq -r -o=json -I=0 '.spec.strategy' | tee -a /dev/stderr)

[ "${actual}" == "null" ]
}
Expand All @@ -47,7 +47,7 @@ load _helpers
--namespace default \
--show-only templates/deployment.yaml \
. || echo "---") | tee -a /dev/stderr |
yq -r -c '.spec.strategy' | tee -a /dev/stderr)
yq -r -o=json -I=0 '.spec.strategy' | tee -a /dev/stderr)

[ "${actual}" == '{"rollingUpdate":{"maxUnavailable":1},"type":"RollingUpdate"}' ]
}
Expand All @@ -67,7 +67,7 @@ rollingUpdate:
--namespace default \
--show-only templates/deployment.yaml \
. || echo "---") | tee -a /dev/stderr |
yq -r -c '.spec.strategy' | tee -a /dev/stderr)
yq -r -o=json -I=0 '.spec.strategy' | tee -a /dev/stderr)

[ "${actual}" == '{"type":"RollingUpdate","rollingUpdate":{"maxUnavailable":1}}' ]
}
Expand Down
12 changes: 6 additions & 6 deletions varnish-cache/test/unit/extra.bats
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ EOF
. || echo "---") |
tee -a /dev/stderr)

local actual=$(echo "$object" | yq -c | wc -l | tee -a /dev/stderr)
local actual=$(echo "$object" | yq -o=json -I=0 | wc -l | tee -a /dev/stderr)
[ "${actual}" == "2" ]

local actual=$(echo "$object" | yq -r -c 'select(.metadata.name == "release-name-clusterrole")' | tee -a /dev/stderr)
local actual=$(echo "$object" | yq -r -o=json -I=0 'select(.metadata.name == "release-name-clusterrole")' | tee -a /dev/stderr)
[ "${actual}" == '{"apiVersion":"rbac.authorization.k8s.io/v1","kind":"ClusterRole","metadata":{"name":"release-name-clusterrole"},"rules":[{"apiGroups":[""],"resources":["endpoints"],"verbs":["get","list","watch"]}]}' ]

local actual=$(echo "$object" | yq -r -c 'select(.metadata.name == "release-name-clusterrolebinding")' | tee -a /dev/stderr)
local actual=$(echo "$object" | yq -r -o=json -I=0 'select(.metadata.name == "release-name-clusterrolebinding")' | tee -a /dev/stderr)
[ "${actual}" == '{"apiVersion":"rbac.authorization.k8s.io/v1","kind":"ClusterRoleBinding","metadata":{"name":"release-name-clusterrolebinding"},"roleRef":{"kind":"ClusterRole","name":"release-name-clusterrole","apiGroup":"rbac.authorization.k8s.io"},"subjects":[{"kind":"ServiceAccount","name":"release-name","namespace":"default"}]}' ]
}

Expand Down Expand Up @@ -100,12 +100,12 @@ EOF
. || echo "---") |
tee -a /dev/stderr)

local actual=$(echo "$object" | yq -c | wc -l | tee -a /dev/stderr)
local actual=$(echo "$object" | yq -o=json -I=0 | wc -l | tee -a /dev/stderr)
[ "${actual}" == "2" ]

local actual=$(echo "$object" | yq -r -c 'select(.metadata.name == "varnish-cache-clusterrole")' | tee -a /dev/stderr)
local actual=$(echo "$object" | yq -r -o=json -I=0 'select(.metadata.name == "varnish-cache-clusterrole")' | tee -a /dev/stderr)
[ "${actual}" == '{"apiVersion":"rbac.authorization.k8s.io/v1","kind":"ClusterRole","metadata":{"name":"varnish-cache-clusterrole"},"rules":[{"apiGroups":[""],"resources":["endpoints"],"verbs":["get","list","watch"]}]}' ]

local actual=$(echo "$object" | yq -r -c 'select(.metadata.name == "varnish-cache-clusterrolebinding")' | tee -a /dev/stderr)
local actual=$(echo "$object" | yq -r -o=json -I=0 'select(.metadata.name == "varnish-cache-clusterrolebinding")' | tee -a /dev/stderr)
[ "${actual}" == '{"apiVersion":"rbac.authorization.k8s.io/v1","kind":"ClusterRoleBinding","metadata":{"name":"varnish-cache-clusterrolebinding"},"roleRef":{"apiGroup":"rbac.authorization.k8s.io","kind":"ClusterRole","name":"varnish-cache-clusterrole"},"subjects":[{"kind":"ServiceAccount","name":"varnish-cache","namespace":"default"}]}' ]
}
18 changes: 9 additions & 9 deletions varnish-cache/test/unit/hpa.bats
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ load _helpers
. || echo "---") | tee -a /dev/stderr)

local actual=$(echo "$object" |
yq -r -c 'length > 0' |
yq -r -o=json -I=0 'length > 0' |
tee -a /dev/stderr)
[ "${actual}" == "true" ]

local actual=$(echo "$object" |
yq -r -c '.spec.minReplicas' |
yq -r -o=json -I=0 '.spec.minReplicas' |
tee -a /dev/stderr)
[ "${actual}" == "2" ]

local actual=$(echo "$object" |
yq -r -c '.spec.maxReplicas' |
yq -r -o=json -I=0 '.spec.maxReplicas' |
tee -a /dev/stderr)
[ "${actual}" == "10" ]

local actual=$(echo "$object" |
yq -r -c '.spec.maxReplicas | type' |
yq -r -o=json -I=0 '.spec.maxReplicas | type' |
tee -a /dev/stderr)
[ "${actual}" == "number" ]
[ "${actual}" == "!!int" ]
}

@test "HorizontalPodAutoscaler/behavior: can be set" {
Expand All @@ -57,7 +57,7 @@ load _helpers
. || echo "---") | tee -a /dev/stderr)

local actual=$(echo "$object" |
yq -r -c '.spec.behavior' |
yq -r -o=json -I=0 '.spec.behavior' |
tee -a /dev/stderr)
[ "${actual}" == '{"scaleDown":{"policies":[{"periodSeconds":60,"type":"Pods","value":4}]}}' ]
}
Expand All @@ -80,7 +80,7 @@ scaleDown:
. || echo "---") | tee -a /dev/stderr)

local actual=$(echo "$object" |
yq -r -c '.spec.behavior' |
yq -r -o=json -I=0 '.spec.behavior' |
tee -a /dev/stderr)
[ "${actual}" == '{"scaleDown":{"policies":[{"type":"Pods","value":4,"periodSeconds":60}]}}' ]
}
Expand All @@ -99,7 +99,7 @@ scaleDown:
. || echo "---") | tee -a /dev/stderr)

local actual=$(echo "$object" |
yq -r -c '.spec.metrics' |
yq -r -o=json -I=0 '.spec.metrics' |
tee -a /dev/stderr)
[ "${actual}" == '[{"resource":{"name":"cpu","target":{"averageUtilization":50,"type":"Utilization"}},"type":"Resource"}]' ]
}
Expand All @@ -123,7 +123,7 @@ scaleDown:
. || echo "---") | tee -a /dev/stderr)

local actual=$(echo "$object" |
yq -r -c '.spec.metrics' |
yq -r -o=json -I=0 '.spec.metrics' |
tee -a /dev/stderr)
[ "${actual}" == '[{"type":"Resources","resource":{"name":"cpu","target":{"type":"Utilization","averageUtilization":50}}}]' ]
}
40 changes: 20 additions & 20 deletions varnish-cache/test/unit/pdb.bats
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ load _helpers
. || echo "---") | tee -a /dev/stderr)

local actual=$(echo "$object" |
yq -r -c 'length > 0' |
yq -r -o=json -I=0 'length > 0' |
tee -a /dev/stderr)
[ "${actual}" == "true" ]

local actual=$(echo "$object" |
yq -r -c '.spec.minAvailable' |
yq -r -o=json -I=0 '.spec.minAvailable' |
tee -a /dev/stderr)
[ "${actual}" == "30%" ]

local actual=$(echo "$object" |
yq -r -c '.spec.minAvailable | type' |
yq -r -o=json -I=0 '.spec.minAvailable | type' |
tee -a /dev/stderr)
[ "${actual}" == "string" ]
[ "${actual}" == "!!str" ]

local actual=$(echo "$object" |
yq -r -c '.spec.maxUnavailable' |
yq -r -o=json -I=0 '.spec.maxUnavailable' |
tee -a /dev/stderr)
[ "${actual}" == "null" ]
}
Expand All @@ -55,22 +55,22 @@ load _helpers
. || echo "---") | tee -a /dev/stderr)

local actual=$(echo "$object" |
yq -r -c 'length > 0' |
yq -r -o=json -I=0 'length > 0' |
tee -a /dev/stderr)
[ "${actual}" == "true" ]

local actual=$(echo "$object" |
yq -r -c '.spec.minAvailable' |
yq -r -o=json -I=0 '.spec.minAvailable' |
tee -a /dev/stderr)
[ "${actual}" == "5" ]

local actual=$(echo "$object" |
yq -r -c '.spec.minAvailable | type' |
yq -r -o=json -I=0 '.spec.minAvailable | type' |
tee -a /dev/stderr)
[ "${actual}" == "number" ]
[ "${actual}" == "!!int" ]

local actual=$(echo "$object" |
yq -r -c '.spec.maxUnavailable' |
yq -r -o=json -I=0 '.spec.maxUnavailable' |
tee -a /dev/stderr)
[ "${actual}" == "null" ]
}
Expand All @@ -86,24 +86,24 @@ load _helpers
. || echo "---") | tee -a /dev/stderr)

local actual=$(echo "$object" |
yq -r -c 'length > 0' |
yq -r -o=json -I=0 'length > 0' |
tee -a /dev/stderr)
[ "${actual}" == "true" ]

local actual=$(echo "$object" |
yq -r -c '.spec.minAvailable' |
yq -r -o=json -I=0 '.spec.minAvailable' |
tee -a /dev/stderr)
[ "${actual}" == "null" ]

local actual=$(echo "$object" |
yq -r -c '.spec.maxUnavailable' |
yq -r -o=json -I=0 '.spec.maxUnavailable' |
tee -a /dev/stderr)
[ "${actual}" == "30%" ]

local actual=$(echo "$object" |
yq -r -c '.spec.maxUnavailable | type' |
yq -r -o=json -I=0 '.spec.maxUnavailable | type' |
tee -a /dev/stderr)
[ "${actual}" == "string" ]
[ "${actual}" == "!!str" ]
}

# Kubernetes only accept maxUnavailable as a string only for percent.
Expand All @@ -118,24 +118,24 @@ load _helpers
. || echo "---") | tee -a /dev/stderr)

local actual=$(echo "$object" |
yq -r -c 'length > 0' |
yq -r -o=json -I=0 'length > 0' |
tee -a /dev/stderr)
[ "${actual}" == "true" ]

local actual=$(echo "$object" |
yq -r -c '.spec.minAvailable' |
yq -r -o=json -I=0 '.spec.minAvailable' |
tee -a /dev/stderr)
[ "${actual}" == "null" ]

local actual=$(echo "$object" |
yq -r -c '.spec.maxUnavailable' |
yq -r -o=json -I=0 '.spec.maxUnavailable' |
tee -a /dev/stderr)
[ "${actual}" == "5" ]

local actual=$(echo "$object" |
yq -r -c '.spec.maxUnavailable | type' |
yq -r -o=json -I=0 '.spec.maxUnavailable | type' |
tee -a /dev/stderr)
[ "${actual}" == "number" ]
[ "${actual}" == "!!int" ]
}

@test "PodDisruptionBudget: cannot be enabled without minAvailable or maxUnavailable" {
Expand Down
4 changes: 2 additions & 2 deletions varnish-cache/test/unit/service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ load _helpers
tee -a /dev/stderr)

local actual=$(echo "$object" |
yq -r -c '.spec.externalTrafficPolicy' |
yq -r -o=json -I=0 '.spec.externalTrafficPolicy' |
tee -a /dev/stderr)

[ "${actual}" == "Cluster" ]
Expand All @@ -29,7 +29,7 @@ load _helpers
tee -a /dev/stderr)

local actual=$(echo "$object" |
yq -r -c '.spec.externalTrafficPolicy' |
yq -r -o=json -I=0 '.spec.externalTrafficPolicy' |
tee -a /dev/stderr)

[ "${actual}" == "Local" ]
Expand Down
12 changes: 6 additions & 6 deletions varnish-cache/test/unit/statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ load _helpers
--namespace default \
--show-only templates/statefulset.yaml \
. || echo "---") | tee -a /dev/stderr |
yq -r -c '.spec.updateStrategy' | tee -a /dev/stderr)
yq -r -o=json -I=0 '.spec.updateStrategy' | tee -a /dev/stderr)

[ "${actual}" == "null" ]
}
Expand All @@ -62,7 +62,7 @@ load _helpers
--namespace default \
--show-only templates/statefulset.yaml \
. || echo "---") | tee -a /dev/stderr |
yq -r -c '.spec.updateStrategy' | tee -a /dev/stderr)
yq -r -o=json -I=0 '.spec.updateStrategy' | tee -a /dev/stderr)

[ "${actual}" == '{"rollingUpdate":{"maxUnavailable":1},"type":"RollingUpdate"}' ]
}
Expand All @@ -82,7 +82,7 @@ rollingUpdate:
--namespace default \
--show-only templates/statefulset.yaml \
. || echo "---") | tee -a /dev/stderr |
yq -r -c '.spec.updateStrategy' | tee -a /dev/stderr)
yq -r -o=json -I=0 '.spec.updateStrategy' | tee -a /dev/stderr)

[ "${actual}" == '{"type":"RollingUpdate","rollingUpdate":{"maxUnavailable":1}}' ]
}
Expand All @@ -98,7 +98,7 @@ rollingUpdate:
tee -a /dev/stderr)

local actual=$(echo "$object" |
yq -r -c '.spec.volumeClaimTemplates' | tee -a /dev/stderr)
yq -r -o=json -I=0 '.spec.volumeClaimTemplates' | tee -a /dev/stderr)
[ "${actual}" == 'null' ]
}

Expand All @@ -116,7 +116,7 @@ rollingUpdate:
tee -a /dev/stderr)

local actual=$(echo "$object" |
yq -r -c '.spec.volumeClaimTemplates' | tee -a /dev/stderr)
yq -r -o=json -I=0 '.spec.volumeClaimTemplates' | tee -a /dev/stderr)
[ "${actual}" == '[{"metadata":{"name":"hello-pv"},"spec":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"10Gi"}}}}]' ]
}

Expand All @@ -142,6 +142,6 @@ rollingUpdate:
tee -a /dev/stderr)

local actual=$(echo "$object" |
yq -r -c '.spec.volumeClaimTemplates' | tee -a /dev/stderr)
yq -r -o=json -I=0 '.spec.volumeClaimTemplates' | tee -a /dev/stderr)
[ "${actual}" == '[{"metadata":{"name":"release-name-pv"},"spec":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"10Gi"}}}}]' ]
}
Loading