mirror of https://github.com/fluxcd/cli-utils.git
fix: Colorize example tests
- Exit on first test failure for each file
This commit is contained in:
parent
d2c4aa9b88
commit
de8f67c0a5
|
@ -32,6 +32,9 @@ BASE=$DEMO_HOME/base
|
|||
mkdir -p $BASE
|
||||
OUTPUT=$DEMO_HOME/output
|
||||
mkdir -p $OUTPUT
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
mkdir $BASE/wordpress
|
||||
mkdir $BASE/mysql
|
||||
|
@ -47,9 +50,13 @@ curl -s -o "$BASE/mysql/#1.yaml" "https://raw.githubusercontent.com\
|
|||
/{secret,deployment,service}.yaml"
|
||||
|
||||
function expectedOutputLine() {
|
||||
test 1 == \
|
||||
$(grep "$@" $OUTPUT/status | wc -l); \
|
||||
echo $?
|
||||
if ! grep -q "$@" "$OUTPUT/status"; then
|
||||
echo -e "${RED}Error: output line not found${NC}"
|
||||
echo -e "${RED}Expected: $@${NC}"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${GREEN}Success: output line found${NC}"
|
||||
fi
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -57,10 +64,10 @@ Use the kapply init command to generate the inventory template. This contains
|
|||
the namespace and inventory id used by apply to create inventory objects.
|
||||
<!-- @createInventoryTemplate @testE2EAgainstLatestRelease-->
|
||||
```
|
||||
kapply init $BASE/mysql > $OUTPUT/status
|
||||
kapply init $BASE/mysql | tee $OUTPUT/status
|
||||
expectedOutputLine "namespace: default is used for inventory object"
|
||||
|
||||
kapply init $BASE/wordpress > $OUTPUT/status
|
||||
kapply init $BASE/wordpress | tee $OUTPUT/status
|
||||
expectedOutputLine "namespace: default is used for inventory object"
|
||||
```
|
||||
|
||||
|
@ -74,7 +81,7 @@ kind create cluster
|
|||
Let's apply the mysql service
|
||||
<!-- @RunMysql @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply apply $BASE/mysql --reconcile-timeout=120s --status-events > $OUTPUT/status;
|
||||
kapply apply $BASE/mysql --reconcile-timeout=120s --status-events | tee $OUTPUT/status
|
||||
|
||||
expectedOutputLine "deployment.apps/mysql is Current: Deployment is available. Replicas: 1"
|
||||
|
||||
|
@ -83,32 +90,32 @@ expectedOutputLine "secret/mysql-pass is Current: Resource is always ready"
|
|||
expectedOutputLine "service/mysql is Current: Service is ready"
|
||||
|
||||
# Verify that we have the mysql resources in the cluster.
|
||||
kubectl get all --no-headers --selector=app=mysql | wc -l | xargs > $OUTPUT/status
|
||||
kubectl get all --no-headers --selector=app=mysql | wc -l | xargs | tee $OUTPUT/status
|
||||
expectedOutputLine "4"
|
||||
|
||||
# Verify that we don't have any of the wordpress resources in the cluster.
|
||||
kubectl get all --no-headers --selector=app=wordpress | wc -l | xargs > $OUTPUT/status
|
||||
kubectl get all --no-headers --selector=app=wordpress | wc -l | xargs | tee $OUTPUT/status
|
||||
expectedOutputLine "0"
|
||||
```
|
||||
|
||||
And the apply the wordpress service
|
||||
<!-- @RunWordpress @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply apply $BASE/wordpress --reconcile-timeout=120s --status-events > $OUTPUT/status;
|
||||
kapply apply $BASE/wordpress --reconcile-timeout=120s --status-events | tee $OUTPUT/status
|
||||
|
||||
expectedOutputLine "service/wordpress is Current: Service is ready"
|
||||
|
||||
expectedOutputLine "deployment.apps/wordpress is Current: Deployment is available. Replicas: 1"
|
||||
|
||||
# Verify that we now have the wordpress resources in the cluster.
|
||||
kubectl get all --no-headers --selector=app=wordpress | wc -l | xargs > $OUTPUT/status
|
||||
kubectl get all --no-headers --selector=app=wordpress | wc -l | xargs | tee $OUTPUT/status
|
||||
expectedOutputLine "4"
|
||||
```
|
||||
|
||||
Destroy one service and make sure that only that service is destroyed and clean-up the cluster.
|
||||
<!-- @destroyAppDeleteKindCluster @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply destroy $BASE/wordpress > $OUTPUT/status;
|
||||
kapply destroy $BASE/wordpress | tee $OUTPUT/status;
|
||||
|
||||
expectedOutputLine "service/wordpress deleted"
|
||||
|
||||
|
@ -117,7 +124,7 @@ expectedOutputLine "deployment.apps/wordpress deleted"
|
|||
expectedOutputLine "2 resource(s) deleted, 0 skipped"
|
||||
|
||||
# Verify that we still have the mysql resources in the cluster.
|
||||
kubectl get all --no-headers --selector=app=mysql | wc -l | xargs > $OUTPUT/status
|
||||
kubectl get all --no-headers --selector=app=mysql | wc -l | xargs | tee $OUTPUT/status
|
||||
expectedOutputLine "4"
|
||||
|
||||
# TODO: When we implement wait for prune/destroy, add a check here to make
|
||||
|
|
|
@ -29,11 +29,18 @@ BASE=$DEMO_HOME/base
|
|||
mkdir -p $BASE
|
||||
OUTPUT=$DEMO_HOME/output
|
||||
mkdir -p $OUTPUT
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
function expectedOutputLine() {
|
||||
test 1 == \
|
||||
$(grep "$@" $OUTPUT/status | wc -l); \
|
||||
echo $?
|
||||
if ! grep -q "$@" "$OUTPUT/status"; then
|
||||
echo -e "${RED}Error: output line not found${NC}"
|
||||
echo -e "${RED}Expected: $@${NC}"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${GREEN}Success: output line found${NC}"
|
||||
fi
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -115,21 +122,21 @@ the namespace and inventory id used by apply to create inventory objects.
|
|||
```
|
||||
kapply init $BASE
|
||||
|
||||
ls -1 $BASE > $OUTPUT/status
|
||||
ls -1 $BASE | tee $OUTPUT/status
|
||||
expectedOutputLine "inventory-template.yaml"
|
||||
```
|
||||
|
||||
Use the `kapply` binary in `MYGOBIN` to apply both the CRD and the CR.
|
||||
<!-- @runApply @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply apply $BASE --reconcile-timeout=1m --status-events> $OUTPUT/status
|
||||
kapply apply $BASE --reconcile-timeout=1m --status-events | tee $OUTPUT/status
|
||||
|
||||
expectedOutputLine "foo.custom.io/example-foo is Current: Resource is current"
|
||||
|
||||
kubectl get crd --no-headers | awk '{print $1}' > $OUTPUT/status
|
||||
kubectl get crd --no-headers | awk '{print $1}' | tee $OUTPUT/status
|
||||
expectedOutputLine "foos.custom.io"
|
||||
|
||||
kubectl get foos.custom.io --no-headers | awk '{print $1}' > $OUTPUT/status
|
||||
kubectl get foos.custom.io --no-headers | awk '{print $1}' | tee $OUTPUT/status
|
||||
expectedOutputLine "example-foo"
|
||||
|
||||
kind delete cluster
|
||||
|
|
|
@ -33,17 +33,28 @@ BASE=$DEMO_HOME/base
|
|||
mkdir -p $BASE
|
||||
OUTPUT=$DEMO_HOME/output
|
||||
mkdir -p $OUTPUT
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
function expectedOutputLine() {
|
||||
test 1 == \
|
||||
$(grep "$@" $OUTPUT/status | wc -l); \
|
||||
echo $?
|
||||
if ! grep -q "$@" "$OUTPUT/status"; then
|
||||
echo -e "${RED}Error: output line not found${NC}"
|
||||
echo -e "${RED}Expected: $@${NC}"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${GREEN}Success: output line found${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
function expectedNotFound() {
|
||||
test 0 == \
|
||||
$(grep "$@" $OUTPUT/status | wc -l); \
|
||||
echo $?
|
||||
if grep -q "$@" $OUTPUT/status; then
|
||||
echo -e "${RED}Error: output line found:${NC}"
|
||||
echo -e "${RED}Found: $@${NC}"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${GREEN}Success: output line not found found${NC}"
|
||||
fi
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -154,30 +165,30 @@ the namespace and inventory id used by apply to create inventory objects.
|
|||
```
|
||||
kapply init $BASE
|
||||
|
||||
ls -1 $BASE > $OUTPUT/status
|
||||
ls -1 $BASE | tee $OUTPUT/status
|
||||
expectedOutputLine "inventory-template.yaml"
|
||||
```
|
||||
|
||||
Run preview to check which commands will be executed
|
||||
<!-- @previewHelloApp @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply preview $BASE > $OUTPUT/status
|
||||
kapply preview $BASE | tee $OUTPUT/status
|
||||
|
||||
expectedOutputLine "3 resource(s) applied. 3 created, 0 unchanged, 0 configured, 0 failed (preview)"
|
||||
|
||||
kapply preview $BASE --server-side > $OUTPUT/status
|
||||
kapply preview $BASE --server-side | tee $OUTPUT/status
|
||||
|
||||
expectedOutputLine "3 resource(s) applied. 0 created, 0 unchanged, 0 configured, 0 failed, 3 serverside applied (preview-server)"
|
||||
|
||||
# Verify that preview didn't create any resources.
|
||||
kubectl get all -n hellospace > $OUTPUT/status 2>&1
|
||||
kubectl get all -n hellospace 2>&1 | tee $OUTPUT/status
|
||||
expectedOutputLine "No resources found in hellospace namespace."
|
||||
```
|
||||
|
||||
Use the `kapply` binary in `MYGOBIN` to apply a deployment and verify it is successful.
|
||||
<!-- @runHelloApp @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply apply $BASE --reconcile-timeout=1m --status-events > $OUTPUT/status
|
||||
kapply apply $BASE --reconcile-timeout=1m --status-events | tee $OUTPUT/status
|
||||
|
||||
expectedOutputLine "deployment.apps/the-deployment is Current: Deployment is available. Replicas: 3"
|
||||
|
||||
|
@ -186,7 +197,7 @@ expectedOutputLine "service/the-service is Current: Service is ready"
|
|||
expectedOutputLine "configmap/the-map1 is Current: Resource is always ready"
|
||||
|
||||
# Verify that we have the pods running in the cluster
|
||||
kubectl get --no-headers pod -n hellospace | wc -l | xargs > $OUTPUT/status
|
||||
kubectl get --no-headers pod -n hellospace | wc -l | xargs | tee $OUTPUT/status
|
||||
expectedOutputLine "3"
|
||||
```
|
||||
|
||||
|
@ -207,14 +218,14 @@ EOF
|
|||
|
||||
rm $BASE/configMap.yaml
|
||||
|
||||
kapply apply $BASE --reconcile-timeout=120s --status-events > $OUTPUT/status;
|
||||
kapply apply $BASE --reconcile-timeout=120s --status-events | tee $OUTPUT/status
|
||||
|
||||
expectedOutputLine "configmap/the-map2 is Current: Resource is always ready"
|
||||
|
||||
expectedOutputLine "configmap/the-map1 pruned"
|
||||
|
||||
# Verify that the new configmap has been created and the old one pruned.
|
||||
kubectl get cm -n hellospace --no-headers | awk '{print $1}' > $OUTPUT/status
|
||||
kubectl get cm -n hellospace --no-headers | awk '{print $1}' | tee $OUTPUT/status
|
||||
expectedOutputLine "the-map2"
|
||||
expectedNotFound "the-map1"
|
||||
```
|
||||
|
@ -222,7 +233,7 @@ expectedNotFound "the-map1"
|
|||
Clean-up the cluster
|
||||
<!-- @deleteKindCluster @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply preview $BASE --destroy > $OUTPUT/status;
|
||||
kapply preview $BASE --destroy | tee $OUTPUT/status
|
||||
|
||||
expectedOutputLine "deployment.apps/the-deployment deleted (preview)"
|
||||
|
||||
|
@ -230,7 +241,7 @@ expectedOutputLine "configmap/the-map2 deleted (preview)"
|
|||
|
||||
expectedOutputLine "service/the-service deleted (preview)"
|
||||
|
||||
kapply preview $BASE --destroy --server-side > $OUTPUT/status;
|
||||
kapply preview $BASE --destroy --server-side | tee $OUTPUT/status
|
||||
|
||||
expectedOutputLine "deployment.apps/the-deployment deleted (preview-server)"
|
||||
|
||||
|
@ -239,10 +250,10 @@ expectedOutputLine "configmap/the-map2 deleted (preview-server)"
|
|||
expectedOutputLine "service/the-service deleted (preview-server)"
|
||||
|
||||
# Verify that preview all resources are still there after running preview.
|
||||
kubectl get --no-headers all -n hellospace | wc -l | xargs > $OUTPUT/status
|
||||
kubectl get --no-headers all -n hellospace | wc -l | xargs | tee $OUTPUT/status
|
||||
expectedOutputLine "6"
|
||||
|
||||
kapply destroy $BASE > $OUTPUT/status;
|
||||
kapply destroy $BASE | tee $OUTPUT/status;
|
||||
|
||||
expectedOutputLine "deployment.apps/the-deployment deleted"
|
||||
|
||||
|
|
|
@ -25,11 +25,18 @@ BASE=$DEMO_HOME/base
|
|||
mkdir -p $BASE
|
||||
OUTPUT=$DEMO_HOME/output
|
||||
mkdir -p $OUTPUT
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
function expectedOutputLine() {
|
||||
test 1 == \
|
||||
$(grep "$@" $OUTPUT/status | wc -l); \
|
||||
echo $?
|
||||
if ! grep -q "$@" "$OUTPUT/status"; then
|
||||
echo -e "${RED}Error: output line not found${NC}"
|
||||
echo -e "${RED}Expected: $@${NC}"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${GREEN}Success: output line found${NC}"
|
||||
fi
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -93,7 +100,7 @@ Use the kapply init command to generate the inventory template. This contains
|
|||
the namespace and inventory id used by apply to create inventory objects.
|
||||
<!-- @createInventoryTemplate @testE2EAgainstLatestRelease-->
|
||||
```
|
||||
kapply init $BASE > $OUTPUT/status
|
||||
kapply init $BASE | tee $OUTPUT/status
|
||||
expectedOutputLine "namespace: test-namespace is used for inventory object"
|
||||
```
|
||||
|
||||
|
@ -116,7 +123,7 @@ EOF
|
|||
# Remove the initial inventory template.
|
||||
rm -f $BASE/inventory-template.yaml
|
||||
|
||||
kapply init $BASE > $OUTPUT/status
|
||||
kapply init $BASE | tee $OUTPUT/status
|
||||
expectedOutputLine "namespace: default is used for inventory object"
|
||||
```
|
||||
|
||||
|
@ -150,7 +157,7 @@ rules:
|
|||
verbs: ["get", "watch", "list"]
|
||||
EOF
|
||||
|
||||
kapply init $BASE > $OUTPUT/status
|
||||
kapply init $BASE | tee $OUTPUT/status
|
||||
expectedOutputLine "namespace: test-namespace is used for inventory object"
|
||||
```
|
||||
|
||||
|
|
|
@ -27,11 +27,18 @@ BASE=$DEMO_HOME/base
|
|||
mkdir -p $BASE
|
||||
OUTPUT=$DEMO_HOME/output
|
||||
mkdir -p $OUTPUT
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
function expectedOutputLine() {
|
||||
test 1 == \
|
||||
$(grep "$@" $OUTPUT/status | wc -l); \
|
||||
echo $?
|
||||
if ! grep -q "$@" "$OUTPUT/status"; then
|
||||
echo -e "${RED}Error: output line not found${NC}"
|
||||
echo -e "${RED}Expected: $@${NC}"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${GREEN}Success: output line found${NC}"
|
||||
fi
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -75,7 +82,7 @@ Use the kapply init command to generate the inventory template. This contains
|
|||
the namespace and inventory id used by apply to create inventory objects.
|
||||
<!-- @createInventoryTemplate @testE2EAgainstLatestRelease-->
|
||||
```
|
||||
kapply init --namespace=test-namespace $BASE > $OUTPUT/status
|
||||
kapply init --namespace=test-namespace $BASE | tee $OUTPUT/status
|
||||
expectedOutputLine "namespace: test-namespace is used for inventory object"
|
||||
```
|
||||
|
||||
|
@ -85,24 +92,24 @@ test-namespace is created first, so the following resources within the namespace
|
|||
(including the inventory object) will not fail.
|
||||
<!-- @runApply @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply apply $BASE --reconcile-timeout=1m > $OUTPUT/status
|
||||
kapply apply $BASE --reconcile-timeout=1m | tee $OUTPUT/status
|
||||
expectedOutputLine "namespace/test-namespace unchanged"
|
||||
expectedOutputLine "configmap/cm-a created"
|
||||
expectedOutputLine "2 resource(s) applied. 1 created, 1 unchanged, 0 configured"
|
||||
|
||||
# There should be only one inventory object
|
||||
kubectl get cm -n test-namespace --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get cm -n test-namespace --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
|
||||
# Capture the inventory object name for later testing
|
||||
invName=$(kubectl get cm -n test-namespace --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | awk '{print $1}')
|
||||
|
||||
# There should be one config map that is not the inventory object
|
||||
kubectl get cm -n test-namespace --selector='name=test-config-map-label' --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get cm -n test-namespace --selector='name=test-config-map-label' --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
|
||||
# ConfigMap cm-a had been created in the cluster
|
||||
kubectl get configmap/cm-a -n test-namespace --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get configmap/cm-a -n test-namespace --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
```
|
||||
|
||||
|
@ -111,15 +118,15 @@ that the subsequent apply does not prune this omitted namespace.
|
|||
<!-- @noPruneInventoryNamespace @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
rm -f $BASE/test-namespace.yaml
|
||||
kapply apply $BASE --reconcile-timeout=1m > $OUTPUT/status
|
||||
kapply apply $BASE --reconcile-timeout=1m | tee $OUTPUT/status
|
||||
expectedOutputLine "0 resource(s) pruned, 1 skipped"
|
||||
|
||||
# Inventory namespace should still exist
|
||||
kubectl get ns test-namespace --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get ns test-namespace --no-headers | wc -l | tee $OUTPUT/status
|
||||
|
||||
# Inventory object should still exist
|
||||
kubectl get cm/${invName} -n test-namespace --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get cm/${invName} -n test-namespace --no-headers | wc -l | tee $OUTPUT/status
|
||||
|
||||
# ConfigMap cm-a should still exist
|
||||
kubectl get configmap/cm-a -n test-namespace --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get configmap/cm-a -n test-namespace --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
|
|
|
@ -26,11 +26,28 @@ BASE=$DEMO_HOME/base
|
|||
mkdir -p $BASE
|
||||
OUTPUT=$DEMO_HOME/output
|
||||
mkdir -p $OUTPUT
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
function expectedOutputLine() {
|
||||
test 1 == \
|
||||
$(grep "$@" $OUTPUT/status | wc -l); \
|
||||
echo $?
|
||||
if ! grep -q "$@" "$OUTPUT/status"; then
|
||||
echo -e "${RED}Error: output line not found${NC}"
|
||||
echo -e "${RED}Expected: $@${NC}"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${GREEN}Success: output line found${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
function expectedNotFound() {
|
||||
if grep -q "$@" $OUTPUT/status; then
|
||||
echo -e "${RED}Error: output line found:${NC}"
|
||||
echo -e "${RED}Found: $@${NC}"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${GREEN}Success: output line not found found${NC}"
|
||||
fi
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -107,7 +124,7 @@ Use the kapply init command to generate the inventory template. This contains
|
|||
the namespace and inventory id used by apply to create inventory objects.
|
||||
<!-- @createInventoryTemplate @testE2EAgainstLatestRelease-->
|
||||
```
|
||||
kapply init $BASE > $OUTPUT/status
|
||||
kapply init $BASE | tee $OUTPUT/status
|
||||
expectedOutputLine "namespace: default is used for inventory object"
|
||||
|
||||
```
|
||||
|
@ -115,7 +132,7 @@ expectedOutputLine "namespace: default is used for inventory object"
|
|||
Apply the three resources to the cluster.
|
||||
<!-- @runApply @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply apply $BASE --reconcile-timeout=1m > $OUTPUT/status
|
||||
kapply apply $BASE --reconcile-timeout=1m | tee $OUTPUT/status
|
||||
```
|
||||
|
||||
Use the preview command to show what will happen if we run destroy. This should
|
||||
|
@ -123,7 +140,7 @@ show that secondmap and thirdmap will not be deleted even when using the destroy
|
|||
command.
|
||||
<!-- @runDestroyPreview @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply preview --destroy $BASE > $OUTPUT/status
|
||||
kapply preview --destroy $BASE | tee $OUTPUT/status
|
||||
|
||||
expectedOutputLine "configmap/firstmap deleted (preview)"
|
||||
|
||||
|
@ -137,7 +154,7 @@ has been deleted, while the resources with the annotations (secondmap and thirdm
|
|||
cluster.
|
||||
<!-- @runDestroy @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply destroy $BASE > $OUTPUT/status
|
||||
kapply destroy $BASE | tee $OUTPUT/status
|
||||
|
||||
expectedOutputLine "configmap/firstmap deleted"
|
||||
|
||||
|
@ -148,10 +165,10 @@ expectedOutputLine "configmap/thirdmap delete skipped"
|
|||
expectedOutputLine "1 resource(s) deleted, 2 skipped"
|
||||
expectedNotFound "resource(s) pruned"
|
||||
|
||||
kubectl get cm --no-headers | awk '{print $1}' > $OUTPUT/status
|
||||
kubectl get cm --no-headers | awk '{print $1}' | tee $OUTPUT/status
|
||||
expectedOutputLine "secondmap"
|
||||
|
||||
kubectl get cm --no-headers | awk '{print $1}' > $OUTPUT/status
|
||||
kubectl get cm --no-headers | awk '{print $1}' | tee $OUTPUT/status
|
||||
expectedOutputLine "thirdmap"
|
||||
```
|
||||
|
||||
|
@ -159,7 +176,7 @@ Apply the resources back to the cluster so we can demonstrate the lifecycle
|
|||
directive with pruning.
|
||||
<!-- @runApplyAgain @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply apply $BASE --inventory-policy=adopt --reconcile-timeout=1m > $OUTPUT/status
|
||||
kapply apply $BASE --inventory-policy=adopt --reconcile-timeout=1m | tee $OUTPUT/status
|
||||
```
|
||||
|
||||
Delete the manifest for secondmap and thirdmap
|
||||
|
@ -174,7 +191,7 @@ Run preview to see that while secondmap and thirdmap would normally be pruned, t
|
|||
will instead be skipped due to the lifecycle directive.
|
||||
<!-- @runPreviewForPrune @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply preview $BASE > $OUTPUT/status
|
||||
kapply preview $BASE | tee $OUTPUT/status
|
||||
|
||||
expectedOutputLine "configmap/secondmap prune skipped (preview)"
|
||||
|
||||
|
@ -184,16 +201,16 @@ expectedOutputLine "configmap/thirdmap prune skipped (preview)"
|
|||
Run apply and verify that secondmap and thirdmap are still in the cluster.
|
||||
<!-- @runApplyToPrune @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply apply $BASE > $OUTPUT/status
|
||||
kapply apply $BASE | tee $OUTPUT/status
|
||||
|
||||
expectedOutputLine "configmap/secondmap prune skipped"
|
||||
|
||||
expectedOutputLine "configmap/thirdmap prune skipped"
|
||||
|
||||
kubectl get cm --no-headers | awk '{print $1}' > $OUTPUT/status
|
||||
kubectl get cm --no-headers | awk '{print $1}' | tee $OUTPUT/status
|
||||
expectedOutputLine "secondmap"
|
||||
|
||||
kubectl get cm --no-headers | awk '{print $1}' > $OUTPUT/status
|
||||
kubectl get cm --no-headers | awk '{print $1}' | tee $OUTPUT/status
|
||||
expectedOutputLine "thirdmap"
|
||||
|
||||
kind delete cluster;
|
||||
|
|
|
@ -28,11 +28,18 @@ BASE=$DEMO_HOME/base
|
|||
mkdir -p $BASE
|
||||
OUTPUT=$DEMO_HOME/output
|
||||
mkdir -p $OUTPUT
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
function expectedOutputLine() {
|
||||
test 1 == \
|
||||
$(grep "$@" $OUTPUT/status | wc -l); \
|
||||
echo $?
|
||||
if ! grep -q "$@" "$OUTPUT/status"; then
|
||||
echo -e "${RED}Error: output line not found${NC}"
|
||||
echo -e "${RED}Expected: $@${NC}"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${GREEN}Success: output line found${NC}"
|
||||
fi
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -86,7 +93,7 @@ Use the kapply init command to generate the inventory template. This contains
|
|||
the namespace and inventory id used by apply to create inventory objects.
|
||||
<!-- @createInventoryTemplate @testE2EAgainstLatestRelease-->
|
||||
```
|
||||
kapply init $BASE > $OUTPUT/status
|
||||
kapply init $BASE | tee $OUTPUT/status
|
||||
expectedOutputLine "namespace: default is used for inventory object"
|
||||
```
|
||||
|
||||
|
@ -94,27 +101,27 @@ Apply the "app" to the cluster. All the config maps should be created, and
|
|||
no resources should be pruned.
|
||||
<!-- @runApply @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply apply $BASE --reconcile-timeout=1m > $OUTPUT/status
|
||||
kapply apply $BASE --reconcile-timeout=1m | tee $OUTPUT/status
|
||||
expectedOutputLine "configmap/cm-a created"
|
||||
expectedOutputLine "configmap/cm-b created"
|
||||
expectedOutputLine "configmap/cm-c created"
|
||||
|
||||
# There should be only one inventory object
|
||||
kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
# Capture the inventory object name for later testing
|
||||
invName=$(kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | awk '{print $1}')
|
||||
# There should be three config maps
|
||||
kubectl get cm --selector='name=test-config-map-label' --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get cm --selector='name=test-config-map-label' --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "3"
|
||||
# ConfigMap cm-a had been created in the cluster
|
||||
kubectl get configmap/cm-a --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get configmap/cm-a --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
# ConfigMap cm-b had been created in the cluster
|
||||
kubectl get configmap/cm-b --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get configmap/cm-b --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
# ConfigMap cm-c had been created in the cluster
|
||||
kubectl get configmap/cm-c --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get configmap/cm-c --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
```
|
||||
|
||||
|
@ -146,7 +153,7 @@ cm-b, cm-c should be unchanged.
|
|||
cm-d should be created.
|
||||
<!-- @applySecondTime @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply apply $BASE --reconcile-timeout=1m > $OUTPUT/status
|
||||
kapply apply $BASE --reconcile-timeout=1m | tee $OUTPUT/status
|
||||
expectedOutputLine "configmap/cm-a pruned"
|
||||
expectedOutputLine "configmap/cm-b unchanged"
|
||||
expectedOutputLine "configmap/cm-c unchanged"
|
||||
|
@ -154,21 +161,21 @@ expectedOutputLine "configmap/cm-d created"
|
|||
expectedOutputLine "1 resource(s) pruned, 0 skipped"
|
||||
|
||||
# There should be only one inventory object
|
||||
kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
# The inventory object should have the same name
|
||||
kubectl get configmap/${invName} --no-headers > $OUTPUT/status
|
||||
kubectl get configmap/${invName} --no-headers | tee $OUTPUT/status
|
||||
expectedOutputLine "${invName}"
|
||||
# There should be three config maps
|
||||
kubectl get cm --selector='name=test-config-map-label' --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get cm --selector='name=test-config-map-label' --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "3"
|
||||
# ConfigMap cm-b had been created in the cluster
|
||||
kubectl get configmap/cm-b --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get configmap/cm-b --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
# ConfigMap cm-c had been created in the cluster
|
||||
kubectl get configmap/cm-c --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get configmap/cm-c --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
# ConfigMap cm-d had been created in the cluster
|
||||
kubectl get configmap/cm-d --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get configmap/cm-d --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
```
|
||||
|
|
|
@ -33,11 +33,18 @@ BASE=$DEMO_HOME/base
|
|||
mkdir -p $BASE
|
||||
OUTPUT=$DEMO_HOME/output
|
||||
mkdir -p $OUTPUT
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
function expectedOutputLine() {
|
||||
test 1 == \
|
||||
$(grep "$@" $OUTPUT/status | wc -l); \
|
||||
echo $?
|
||||
if ! grep -q "$@" "$OUTPUT/status"; then
|
||||
echo -e "${RED}Error: output line not found${NC}"
|
||||
echo -e "${RED}Expected: $@${NC}"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${GREEN}Success: output line found${NC}"
|
||||
fi
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -100,7 +107,7 @@ Use the kapply init command to generate the inventory template. This contains
|
|||
the namespace and inventory id used by apply to create inventory objects.
|
||||
<!-- @createInventoryTemplate @testE2EAgainstLatestRelease-->
|
||||
```
|
||||
kapply init $BASE > $OUTPUT/status
|
||||
kapply init $BASE | tee $OUTPUT/status
|
||||
expectedOutputLine "namespace: default is used for inventory object"
|
||||
```
|
||||
|
||||
|
@ -108,7 +115,7 @@ Apply the "app" to the cluster. All the config maps should be created, and
|
|||
no resources should be pruned.
|
||||
<!-- @runApply @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply apply $BASE --reconcile-timeout=1m > $OUTPUT/status
|
||||
kapply apply $BASE --reconcile-timeout=1m | tee $OUTPUT/status
|
||||
expectedOutputLine "namespace/test-namespace created"
|
||||
expectedOutputLine "configmap/cm-a created"
|
||||
expectedOutputLine "configmap/cm-b created"
|
||||
|
@ -116,25 +123,25 @@ expectedOutputLine "configmap/cm-c created"
|
|||
expectedOutputLine "4 resource(s) applied. 4 created, 0 unchanged, 0 configured"
|
||||
|
||||
# There should be only one inventory object
|
||||
kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
# Capture the inventory object name for later testing
|
||||
invName=$(kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | awk '{print $1}')
|
||||
# There should be four config maps: one inventory in default, two in test-namespace, one in default namespace
|
||||
kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
kubectl get cm -n test-namespace --selector='name=test-config-map-label' --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get cm -n test-namespace --selector='name=test-config-map-label' --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "2"
|
||||
kubectl get cm --selector='name=test-config-map-label' --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get cm --selector='name=test-config-map-label' --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
# ConfigMap cm-a had been created in the cluster
|
||||
kubectl get configmap/cm-a -n test-namespace --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get configmap/cm-a -n test-namespace --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
# ConfigMap cm-b had been created in the cluster
|
||||
kubectl get configmap/cm-b --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get configmap/cm-b --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
# ConfigMap cm-c had been created in the cluster
|
||||
kubectl get configmap/cm-c -n test-namespace --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get configmap/cm-c -n test-namespace --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
```
|
||||
|
||||
|
@ -162,22 +169,22 @@ test-namespace should **not** be pruned.
|
|||
|
||||
<!-- @applySecondTime @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply apply $BASE --reconcile-timeout=1m > $OUTPUT/status
|
||||
kapply apply $BASE --reconcile-timeout=1m | tee $OUTPUT/status
|
||||
expectedOutputLine "configmap/cm-a pruned"
|
||||
expectedOutputLine "configmap/cm-b pruned"
|
||||
expectedOutputLine "configmap/cm-c unchanged"
|
||||
expectedOutputLine "2 resource(s) pruned, 1 skipped"
|
||||
|
||||
# The test-namespace should not be pruned.
|
||||
kubectl get ns test-namespace --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get ns test-namespace --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
# Inventory object should have two items: namespace and cm-c.
|
||||
kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | awk '{print $2}' > $OUTPUT/status
|
||||
kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | awk '{print $2}' | tee $OUTPUT/status
|
||||
expectedOutputLine "2"
|
||||
# The inventory object should have the same name
|
||||
kubectl get configmap/${invName} --no-headers > $OUTPUT/status
|
||||
kubectl get configmap/${invName} --no-headers | tee $OUTPUT/status
|
||||
expectedOutputLine "${invName}"
|
||||
# ConfigMap cm-c remains in the cluster.
|
||||
kubectl get configmap/cm-c -n test-namespace --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get configmap/cm-c -n test-namespace --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
```
|
||||
|
|
|
@ -26,11 +26,18 @@ BASE=$DEMO_HOME/base
|
|||
mkdir -p $BASE
|
||||
OUTPUT=$DEMO_HOME/output
|
||||
mkdir -p $OUTPUT
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
function expectedOutputLine() {
|
||||
test 1 == \
|
||||
$(grep "$@" $OUTPUT/status | wc -l); \
|
||||
echo $?
|
||||
if ! grep -q "$@" "$OUTPUT/status"; then
|
||||
echo -e "${RED}Error: output line not found${NC}"
|
||||
echo -e "${RED}Expected: $@${NC}"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${GREEN}Success: output line found${NC}"
|
||||
fi
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -77,7 +84,7 @@ Use the kapply init command to generate the inventory template. This contains
|
|||
the namespace and inventory id used by apply to create inventory objects.
|
||||
<!-- @createInventoryTemplate @testE2EAgainstLatestRelease-->
|
||||
```
|
||||
kapply init $BASE > $OUTPUT/status
|
||||
kapply init $BASE | tee $OUTPUT/status
|
||||
expectedOutputLine "namespace: default is used for inventory object"
|
||||
```
|
||||
|
||||
|
@ -85,22 +92,22 @@ Apply the "app" to the cluster. All the config maps should be created, and
|
|||
no resources should be pruned.
|
||||
<!-- @runServerSideApply @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply apply $BASE --server-side --reconcile-timeout=1m > $OUTPUT/status
|
||||
kapply apply $BASE --server-side --reconcile-timeout=1m | tee $OUTPUT/status
|
||||
expectedOutputLine "configmap/cm-a serversideapplied"
|
||||
expectedOutputLine "configmap/cm-b serversideapplied"
|
||||
expectedOutputLine "2 serverside applied"
|
||||
|
||||
# There should be only one inventory object
|
||||
kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
# There should be two config maps that are not the inventory object
|
||||
kubectl get cm --selector='name=test-config-map-label' --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get cm --selector='name=test-config-map-label' --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "2"
|
||||
# ConfigMap cm-a had been created in the cluster
|
||||
kubectl get configmap/cm-a --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get configmap/cm-a --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
# ConfigMap cm-b had been created in the cluster
|
||||
kubectl get configmap/cm-b --no-headers | wc -l > $OUTPUT/status
|
||||
kubectl get configmap/cm-b --no-headers | wc -l | tee $OUTPUT/status
|
||||
expectedOutputLine "1"
|
||||
```
|
||||
|
||||
|
@ -121,7 +128,7 @@ data:
|
|||
foo: baz
|
||||
EOF
|
||||
|
||||
kapply apply $BASE --server-side --field-manager=sean --force-conflicts --reconcile-timeout=1m > $OUTPUT/status
|
||||
kapply apply $BASE --server-side --field-manager=sean --force-conflicts --reconcile-timeout=1m | tee $OUTPUT/status
|
||||
expectedOutputLine "configmap/cm-a serversideapplied"
|
||||
expectedOutputLine "configmap/cm-b serversideapplied"
|
||||
expectedOutputLine "2 serverside applied"
|
||||
|
|
|
@ -7,7 +7,39 @@ set -o nounset
|
|||
set -o errexit
|
||||
set -o pipefail
|
||||
|
||||
mdrip -alsologtostderr -v 10 --blockTimeOut 6m0s --mode test \
|
||||
--label testE2EAgainstLatestRelease examples/alphaTestExamples
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo "Example e2e tests passed against ."
|
||||
succeeded=0
|
||||
failed=0
|
||||
|
||||
function run_test() {
|
||||
mdrip -alsologtostderr -v 10 --blockTimeOut 6m0s --mode test \
|
||||
--label testE2EAgainstLatestRelease "${1}"
|
||||
}
|
||||
|
||||
for path in examples/alphaTestExamples/*.md; do
|
||||
test_name="$(basename "${path}")"
|
||||
echo "-----------------------------------"
|
||||
echo "Example Test: ${test_name}"
|
||||
echo "-----------------------------------"
|
||||
if run_test "${path}"; then
|
||||
echo
|
||||
echo -e "${GREEN}Example Test Succeeded: ${test_name}${NC}"
|
||||
let "succeeded+=1"
|
||||
else
|
||||
echo
|
||||
echo -e "${RED}Example Test Failed: ${test_name}${NC}"
|
||||
let "failed+=1"
|
||||
fi
|
||||
echo
|
||||
done
|
||||
|
||||
if [[ ${failed} -gt 0 ]]; then
|
||||
echo -e "${RED}Example Tests Complete (succeeded: ${succeeded}, failed: ${failed})${NC}"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${GREEN}Example Tests Complete (succeeded: ${succeeded}, failed: ${failed})${NC}"
|
||||
exit 0
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue