Skip to content

Commit

Permalink
Merge pull request #282 from srm09/fix/api-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akutz authored Dec 1, 2023
2 parents 7b64085 + fa34fde commit 4f9a21c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions api/v1alpha1/virtualmachineimage_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ func convert_v1alpha2_VirtualMachineImageStatusConditions_To_v1alpha1_VirtualMac

func convert_v1alpha1_VirtualMachineImageStatusConditions_To_v1alpha2_VirtualMachineImageStatusConditions(
conditions []Condition) []metav1.Condition {
if conditions == nil || len(conditions) == 0 {
return []metav1.Condition{}
}

var readyCondition *metav1.Condition

// Condition types which are folded into the Ready condition in v1alpha2
Expand Down
17 changes: 14 additions & 3 deletions hack/test-unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cd "$(dirname "${BASH_SOURCE[0]}")/.."
COVERAGE_FILE="${1:-}"
if [ -n "${COVERAGE_FILE}" ]; then
COVERAGE_FILE_NORACE="${COVERAGE_FILE}.norace"
API_COVERAGE_FILE="api.${COVERAGE_FILE}"
fi

COVER_PKGS=(
Expand Down Expand Up @@ -53,8 +54,15 @@ if [ -z "${GITHUB_ACTION:-}" ]; then
GO_TEST_FLAGS+=("-count=1")
fi

GO_TEST_FLAGS+=("-race")

# Test flags for api module
API_TEST_FLAGS=("${GO_TEST_FLAGS[@]}")

# The first argument is the name of the coverage file to use.
if [ -n "${COVERAGE_FILE}" ]; then
API_TEST_FLAGS+=("-coverpkg=github.com/vmware-tanzu/vm-operator/api/..." "-covermode=atomic")
API_TEST_FLAGS+=("-coverprofile=${API_COVERAGE_FILE}")
GO_TEST_FLAGS+=("-coverpkg=${COVER_OPTS}" "-covermode=atomic")
GO_TEST_FLAGS_NORACE=("${GO_TEST_FLAGS[@]+"${GO_TEST_FLAGS[@]}"}")
GO_TEST_FLAGS+=("-coverprofile=${COVERAGE_FILE}")
Expand All @@ -63,7 +71,10 @@ else
GO_TEST_FLAGS_NORACE=("${GO_TEST_FLAGS[@]+"${GO_TEST_FLAGS[@]}"}")
fi

GO_TEST_FLAGS+=("-race")
# Run api unit tests
# Since api is a different go module
go test "${API_TEST_FLAGS[@]+"${API_TEST_FLAGS[@]}"}" \
github.com/vmware-tanzu/vm-operator/api/...

# Run unit tests
# go test: -race requires cgo
Expand All @@ -89,6 +100,6 @@ go test "${GO_TEST_FLAGS_NORACE[@]+"${GO_TEST_FLAGS_NORACE[@]}"}" \
if [ -n "${COVERAGE_FILE:-}" ]; then
TMP_COVERAGE_FILE="$(mktemp)"
mv "${COVERAGE_FILE}" "${TMP_COVERAGE_FILE}"
gocovmerge "${TMP_COVERAGE_FILE}" "${COVERAGE_FILE_NORACE}" >"${COVERAGE_FILE}"
rm -f "${TMP_COVERAGE_FILE}" "${COVERAGE_FILE_NORACE}"
gocovmerge "${API_COVERAGE_FILE}" "${TMP_COVERAGE_FILE}" "${COVERAGE_FILE_NORACE}" >"${COVERAGE_FILE}"
rm -f "${API_COVERAGE_FILE}" "${TMP_COVERAGE_FILE}" "${COVERAGE_FILE_NORACE}"
fi

0 comments on commit 4f9a21c

Please sign in to comment.