Skip to content

Commit

Permalink
fix: adjusting the ci
Browse files Browse the repository at this point in the history
  • Loading branch information
gambol99 committed Aug 27, 2024
1 parent fedb8db commit f3e0afc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
24 changes: 12 additions & 12 deletions test/e2e/integration/infracost.bats
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,44 @@ teardown() {
}

@test "We should skip infracost when not running on aws cloud" {
[[ -z "${INFRACOST_API_KEY}" ]] && touch ${BATS_PARENT_TMPNAME}.skip
[[ "${CLOUD}" == "aws" ]] || touch ${BATS_PARENT_TMPNAME}.skip
[[ -z ${INFRACOST_API_KEY} ]] && touch ${BATS_PARENT_TMPNAME}.skip
[[ ${CLOUD} == "aws" ]] || touch ${BATS_PARENT_TMPNAME}.skip
}

@test "We should have a job created in the terraform-system running the plan" {
labels="terraform.appvia.io/configuration=compute,terraform.appvia.io/stage=plan"

runit "kubectl -n ${NAMESPACE} get job -l ${labels}"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
}

@test "We should see the terraform plan complete successfully" {
labels="terraform.appvia.io/configuration=compute,terraform.appvia.io/stage=plan"

retry 50 "kubectl -n ${NAMESPACE} get job -l ${labels} -o json" "jq -r '.items[0].status.conditions[0].type' | grep -q Complete"
[[ "$status" -eq 0 ]]
retry 50 "kubectl -n ${NAMESPACE} get job -l ${labels} -o json" "jq -r '.items[0].status.conditions[0].type' | egrep -q '(Complete|SuccessCriteriaMet)'"
[[ $status -eq 0 ]]
runit "kubectl -n ${NAMESPACE} get job -l ${labels} -o json" "jq -r '.items[0].status.conditions[0].status' | grep -q True"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
}

@test "We should the predicted costs available on the status" {
runit "kubectl -n ${APP_NAMESPACE} get configuration compute -o json" "jq -r '.status.costs.enabled' | grep -q 'true'"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
runit "kubectl -n ${APP_NAMESPACE} get configuration compute -o json" "jq -r '.status.costs.monthly' | grep -q '^\$[0-9\.]*'"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
}

@test "We should see infracost breakdown in the watcher logs" {
POD=$(kubectl -n ${APP_NAMESPACE} get pod -l terraform.appvia.io/configuration=${RESOURCE_NAME} -l terraform.appvia.io/stage=plan -o json | jq -r '.items[0].metadata.name')
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]

runit "kubectl -n ${APP_NAMESPACE} logs ${POD} 2>&1" "grep -q 'EVALUATING THE COSTS'"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
runit "kubectl -n ${APP_NAMESPACE} logs ${POD} 2>&1" "grep -q 'OVERALL TOTAL'"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
}

@test "We should be able to destroy the aws configuration for costs" {
runit "kubectl -n ${APP_NAMESPACE} delete -f ${BATS_TMPDIR}/resource.yml"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
}
26 changes: 13 additions & 13 deletions test/e2e/integration/plan.bats
Original file line number Diff line number Diff line change
Expand Up @@ -107,41 +107,41 @@ teardown() {
}

@test "We should have a secret in the terraform namespace containing the report" {
[[ "${INFRACOST_API_KEY}" == "" ]] && skip "INFRACOST_API_KEY is not set"
[[ ${INFRACOST_API_KEY} == "" ]] && skip "INFRACOST_API_KEY is not set"

UUID=$(kubectl -n ${APP_NAMESPACE} get configuration ${RESOURCE_NAME} -o json | jq -r '.metadata.uid')
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]

runit "kubectl -n ${NAMESPACE} get secret costs-${UUID}"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
runit "kubectl -n ${NAMESPACE} get secret costs-${UUID} -o json" "jq -r '.data[\"costs.json\"]'"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
}

@test "We should see the cost integration is enabled" {
[[ "${INFRACOST_API_KEY}" == "" ]] && skip "INFRACOST_API_KEY is not set"
[[ ${INFRACOST_API_KEY} == "" ]] && skip "INFRACOST_API_KEY is not set"

runit "kubectl -n ${APP_NAMESPACE} get configuration ${RESOURCE_NAME} -o json" "jq -r '.status.costs.enabled' | grep -q true"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
}

@test "We should see the cost associated to the configuration" {
[[ "${INFRACOST_API_KEY}" == "" ]] && skip "INFRACOST_API_KEY is not set"
[[ ${INFRACOST_API_KEY} == "" ]] && skip "INFRACOST_API_KEY is not set"

runit "kubectl -n ${APP_NAMESPACE} get configuration ${RESOURCE_NAME} -o json" "jq -r '.status.costs.monthly' | grep -q '\$0'"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
runit "kubectl -n ${APP_NAMESPACE} get configuration ${RESOURCE_NAME} -o json" "jq -r '.status.costs.hourly' | grep -q '\$0'"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
}

@test "We should have a copy of the infracost report in the configuration namespace" {
[[ "${INFRACOST_API_KEY}" == "" ]] && skip "INFRACOST_API_KEY is not set"
[[ ${INFRACOST_API_KEY} == "" ]] && skip "INFRACOST_API_KEY is not set"

UUID=$(kubectl -n ${APP_NAMESPACE} get configuration ${RESOURCE_NAME} -o json | jq -r '.metadata.uid')
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]

runit "kubectl -n ${APP_NAMESPACE} get secret costs-${UUID}"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
runit "kubectl -n ${APP_NAMESPACE} get secret costs-${UUID} -o json" "jq -r '.data[\"costs.json\"]'"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
}
6 changes: 3 additions & 3 deletions test/e2e/integration/setup.bats
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ EOF
}

@test "We should be able to provision a secret with infracost api token" {
[[ "${INFRACOST_API_KEY}" == "" ]] && skip "INFRACOST_API_KEY is not set"
[[ ${INFRACOST_API_KEY} == "" ]] && skip "INFRACOST_API_KEY is not set"

if kubectl -n ${NAMESPACE} get secret infracost-api; then
skip "infracost token already exists"
fi

runit "kubectl -n ${NAMESPACE} create secret generic infracost-api --from-literal=INFRACOST_API_KEY=${INFRACOST_API_KEY}"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
runit "kubectl -n ${NAMESPACE} get secret infracost-api"
[[ "$status" -eq 0 ]]
[[ $status -eq 0 ]]
}

0 comments on commit f3e0afc

Please sign in to comment.