Skip to content

Commit

Permalink
Upgrade to 3.11 gatling-gradle syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
kkulak committed Dec 23, 2024
1 parent 50c1af4 commit 1a82c25
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 3 deletions.
41 changes: 40 additions & 1 deletion pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,40 @@ func GetGatlingRunnerCommand(
generateLocalReport bool) string {

template := `
can_use_gatling_3_11_syntax() {
version=$1
# if the version can't be find/parsed, it's better to allow use of newer syntax
if [ -z "${version}" ]; then
echo 0
return
fi
ver_major=$(echo "$version" | cut -d. -f1)
ver_minor=$(echo "$version" | cut -d. -f2)
# Compare major versions
if [ "$ver_major" -gt "3" ]; then
echo 0
return
elif [ "$ver_major" -lt "3" ]; then
echo 1
return
fi
# Compare minor versions
if [ "$ver_minor" -gt "10" ]; then
echo 0
return
elif [ "$ver_minor" -lt "10" ]; then
echo 1
return
fi
# you can't use 3.11 syntax, you're running 3.10.x
echo 1
}
SIMULATIONS_FORMAT=%s
SIMULATIONS_DIR_PATH=%s
TEMP_SIMULATIONS_DIR_PATH=%s
Expand Down Expand Up @@ -73,7 +107,12 @@ fi
if [ ${SIMULATIONS_FORMAT} = "bundle" ]; then
gatling.sh -sf ${SIMULATIONS_DIR_PATH} -s ${SIMULATION_CLASS} -rsf ${RESOURCES_DIR_PATH} -rf ${RESULTS_DIR_PATH} %s %s
elif [ ${SIMULATIONS_FORMAT} = "gradle" ]; then
gradle -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun-${SIMULATION_CLASS}
gatling_ver=$(find . -name "build.gradle*" -execdir gradle buildEnvironment \; | grep 'gatling-gradle-plugin:' | sed -n 's/.*:gatling-gradle-plugin:\(.*\)$/\1/p')
if [ $(can_use_gatling_3_11_syntax "${gatling_ver}") -eq 0 ]; then
gradle -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun --simulation=${SIMULATION_CLASS}
else
gradle -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun-${SIMULATION_CLASS}
fi
fi
GATLING_EXIT_STATUS=$?
Expand Down
82 changes: 80 additions & 2 deletions pkg/commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,40 @@ var _ = Describe("GetGatlingRunnerCommand", func() {
It("GetCommandsWithLocalReport", func() {
generateLocalReport = true
expectedValue = `
can_use_gatling_3_11_syntax() {
version=$1
# if the version can't be find/parsed, it's better to allow use of newer syntax
if [ -z "${version}" ]; then
echo 0
return
fi
ver_major=$(echo "$version" | cut -d. -f1)
ver_minor=$(echo "$version" | cut -d. -f2)
# Compare major versions
if [ "$ver_major" -gt "3" ]; then
echo 0
return
elif [ "$ver_major" -lt "3" ]; then
echo 1
return
fi
# Compare minor versions
if [ "$ver_minor" -gt "10" ]; then
echo 0
return
elif [ "$ver_minor" -lt "10" ]; then
echo 1
return
fi
# you can't use 3.11 syntax, you're running 3.10.x
echo 1
}
SIMULATIONS_FORMAT=bundle
SIMULATIONS_DIR_PATH=testSimulationDirectoryPath
TEMP_SIMULATIONS_DIR_PATH=testTempSimulationsDirectoryPath
Expand Down Expand Up @@ -91,7 +125,12 @@ fi
if [ ${SIMULATIONS_FORMAT} = "bundle" ]; then
gatling.sh -sf ${SIMULATIONS_DIR_PATH} -s ${SIMULATION_CLASS} -rsf ${RESOURCES_DIR_PATH} -rf ${RESULTS_DIR_PATH} -rm local
elif [ ${SIMULATIONS_FORMAT} = "gradle" ]; then
gradle -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun-${SIMULATION_CLASS}
gatling_ver=$(find . -name "build.gradle*" -execdir gradle buildEnvironment \; | grep 'gatling-gradle-plugin:' | sed -n 's/.*:gatling-gradle-plugin:\(.*\)$/\1/p')
if [ $(can_use_gatling_3_11_syntax "${gatling_ver}") -eq 0 ]; then
gradle -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun --simulation=${SIMULATION_CLASS}
else
gradle -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun-${SIMULATION_CLASS}
fi
fi
GATLING_EXIT_STATUS=$?
Expand All @@ -108,6 +147,40 @@ exit $GATLING_EXIT_STATUS
It("GetCommandWithoutLocalReport", func() {
generateLocalReport = false
expectedValue = `
can_use_gatling_3_11_syntax() {
version=$1
# if the version can't be find/parsed, it's better to allow use of newer syntax
if [ -z "${version}" ]; then
echo 0
return
fi
ver_major=$(echo "$version" | cut -d. -f1)
ver_minor=$(echo "$version" | cut -d. -f2)
# Compare major versions
if [ "$ver_major" -gt "3" ]; then
echo 0
return
elif [ "$ver_major" -lt "3" ]; then
echo 1
return
fi
# Compare minor versions
if [ "$ver_minor" -gt "10" ]; then
echo 0
return
elif [ "$ver_minor" -lt "10" ]; then
echo 1
return
fi
# you can't use 3.11 syntax, you're running 3.10.x
echo 1
}
SIMULATIONS_FORMAT=bundle
SIMULATIONS_DIR_PATH=testSimulationDirectoryPath
TEMP_SIMULATIONS_DIR_PATH=testTempSimulationsDirectoryPath
Expand Down Expand Up @@ -144,7 +217,12 @@ fi
if [ ${SIMULATIONS_FORMAT} = "bundle" ]; then
gatling.sh -sf ${SIMULATIONS_DIR_PATH} -s ${SIMULATION_CLASS} -rsf ${RESOURCES_DIR_PATH} -rf ${RESULTS_DIR_PATH} -nr -rm local
elif [ ${SIMULATIONS_FORMAT} = "gradle" ]; then
gradle -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun-${SIMULATION_CLASS}
gatling_ver=$(find . -name "build.gradle*" -execdir gradle buildEnvironment \; | grep 'gatling-gradle-plugin:' | sed -n 's/.*:gatling-gradle-plugin:\(.*\)$/\1/p')
if [ $(can_use_gatling_3_11_syntax "${gatling_ver}") -eq 0 ]; then
gradle -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun --simulation=${SIMULATION_CLASS}
else
gradle -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun-${SIMULATION_CLASS}
fi
fi
GATLING_EXIT_STATUS=$?
Expand Down

0 comments on commit 1a82c25

Please sign in to comment.