Я пытаюсь передать переменную среды между двумя прогонами теста, инициированными из файла bash, чтобы отслеживать общую сумму тестов failed-
и passed
. Все это выполняется внутри контейнера. Но я не могу обновить env var по какой-то причине.
bash file
formatOutput() {
sed -e ''/FAILED/s//$(printf "\033[31mFAILED\033[0m")/'' -e ''/PASSED/s//$(printf "\033[32mPASSED\033[0m")/''
}
exitCodes=()
TestListNetworks() {
echo "TestListNetworks tests..."
local CVN_PID=$(StartCVN "vrrp")
LoadData "listNetworks.sql"
./cloud-volumes-network-client "--profile=listNetworks" | formatOutput
local status=$?
Flush
kill -9 $CVN_PID
exitCodes+=($status)
}
TestInfrastructure() {
echo "TestInfrastructure tests..."
local CVN_PID=$(StartCVN "vrrp")
./cloud-volumes-network-client "--profile=infrastructure" testCounts | formatOutput
local status=$?
kill -9 $CVN_PID
exitCodes+=($status)
}
# running tests synchronously
TestListNetworks
TestInfrastructure
for exitCode in "${exitCodes[@]}"; do
if [ "$exitCode" -eq "1" ]; then
echo "Integration tests failed"
exit "$exitCode"
fi
done
dockerfile
FROM mariadb/server:10.3.9
ENV FAILED_TESTS=$FAILED_TESTS
ENV SUCCESSFUL_TESTS=$SUCCESSFUL_TESTS
COPY ./build/linux/bin/cloud-volumes-network /
COPY ./build/linux/bin/cloud-volumes-network-client /
RUN mkdir -p /scripts/
ADD ./tests/scripts /
RUN chmod +x /*.sh
ENTRYPOINT [ "./setup.sh"]
Go Функция
func executeTests(testFunctionsList []func(cvn cvn.CVN) error, printCounters bool) error {
cvnNew := cvn.New("x-corr-man")
failedTests := getEnvAsInt("FAILED_TESTS", 0)
passedTests := getEnvAsInt("SUCCESSFUL_TESTS", 0)
// TODO: implement logic for skipped tests
fmt.Printf("failedTests->before: %d\n", failedTests)
fmt.Printf("failedTests->before: %d\n", passedTests)
for _, executeTestFunction := range testFunctionsList {
if err := executeTestFunction(cvnNew); err != nil {
fmt.Printf("\tFAILED - %s: %s\n", extractFunctionName(executeTestFunction), err.Error())
failedTests++
} else {
fmt.Printf("\tPASSED - %s\n", extractFunctionName(executeTestFunction))
passedTests++
}
}
fmt.Printf("failedTests->after: %d\n", failedTests)
fmt.Printf("failedTests->after: %d\n", passedTests)
os.Setenv("FAILED_TESTS", strconv.Itoa(failedTests))
os.Setenv("SUCCESSFUL_TESTS", strconv.Itoa(passedTests))
//countersString := "\nFailed tests: %d\nSuccessful tests: %d\nSkipped tests: 0", failedTests, passedTests
if printCounters {
if failedTests > 0 {
return errors.Errorf("\nFailed tests: %d\nSuccessful tests: %d\nSkipped tests: 0", failedTests, passedTests)
}
fmt.Printf("\nFailed tests: %d\nSuccessful tests: %d\nSkipped tests: 0\n", failedTests, passedTests)
return nil
} else {
if failedTests > 0 {
return errors.New("")
}
return nil
}
}