Skip to content

Commit

Permalink
Checking environment for test running
Browse files Browse the repository at this point in the history
Preparing generic tests for a petstore server
Creating base tests
Add openapi-generator-cli.jar from modules as openapi-generator.jar, and run a `java -jar openapi-generator.jar version` on it
  • Loading branch information
mlebihan committed Jun 2, 2024
1 parent 6136952 commit 03c2e8f
Show file tree
Hide file tree
Showing 13 changed files with 863 additions and 3 deletions.
4 changes: 3 additions & 1 deletion samples/alive/Dockerfile_tester
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
FROM alive/core
ARG JDK_VERSION="17"
ARG TESTER

# Preparing the tester
# --------------------


### 1) Get the test project


ENTRYPOINT ["/bin/bash"]
21 changes: 19 additions & 2 deletions samples/alive/Dockerfile_testing_environment
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ RUN apk add openjdk${JDK_VERSION} maven;
ENV JAVA_HOME /usr/lib/jvm/java-${JDK_VERSION}-openjdk/
RUN export JAVA_HOME;

### Languages
# Installing languages used for testing
# -------------------------------------

# C, C++
ARG GCC_VERSION="latest"
ARG GPP_VERSION="latest"
RUN apk add gcc g++; # TODO How to ask apk any version of C or C++?
RUN apk add gcc g++ cmake; # TODO How to ask apk a specific version of C or C++?

# Go
ARG GO_VERSION=1.22.3
Expand All @@ -29,4 +30,20 @@ RUN wget -c "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" && \
ENV PATH=${PATH}:/usr/local/go/bin
RUN export PATH;

# Installing main build tools and packages
# ----------------------------------------
RUN apk add maven

# Install the openapi-generator.jar that has been prepared by the build_docker.sh script launching us
# ---------------------------------------------------------------------------------------------------
ADD openapi-generator.jar openapi-generator.jar

# Do a checking that java installation allows a compilation of some tests with maven
# ----------------------------------------------------------------------------------
#
# this will also cause downloading of dependencies from the Internet,
# that we will not need to do in children containers
ADD sub-projects/checkJavaMavenInstallation checkJavaMavenInstallation
RUN (cd checkJavaMavenInstallation || exit 1; mvn clean install -Passemblage -Dtester.name=build-environement)

ENTRYPOINT ["/bin/bash"]
25 changes: 25 additions & 0 deletions samples/alive/build_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,34 @@ write() {
echo -e "$4 >> ${target_substep_file}"
}

# copy the openapi generator executable from anywhere to our current folder, before docker building
# whole API_GENERATOR_EXECUTABLE for path where the wished openapi-generator jar to use can be found,
# can be provided, or they will receive default values
copy_openapi_generator_executable() {
if [ -z "$API_GENERATOR_EXECUTABLE" ]; then
API_GENERATOR_EXECUTABLE="../../modules/openapi-generator-cli/target/openapi-generator-cli.jar"
fi

if ! [ -f "${API_GENERATOR_EXECUTABLE}" ]; then
log "ERROR" "The file '${API_GENERATOR_EXECUTABLE}' doesn't exit"
exit 1
fi

cp "${API_GENERATOR_EXECUTABLE}" openapi-generator.jar
}

# --------------------------------------
# Main
# --------------------------------------

volume=$(mktemp --directory)
log "INFO" "Volume for gathering tests results is: ${volume}"

# Copy the openapi generator executable: the docker container will use it
if ! copy_openapi_generator_executable; then
exit $?
fi

# Build test environment, with languages
if ! BUILD_ENV=$(sudo docker build . -t alive/core -f Dockerfile_testing_environment); then
write "0210" "build_env" "${FAILED}" "${BUILD_ENV}"
Expand Down
46 changes: 46 additions & 0 deletions samples/alive/curls_for_petstore_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

# Add new pet
add_petstore() {
local rest_url=$1

local id_pet="$2"
local id_category="$3"
local category_name="$4"
local pet_name="$5"
local photo_url="$6"
local tag_id="$7"
local tag_name="$8"

local pet_to_add
pet_to_add=$(cat - <<END_DOC
{
"id": $id_pet,
"category": {
"id": $id_category,
"name": "$category_name"
},
"name": "$pet_name",
"photoUrls": [
"$photo_url"
],
"tags": [
{
"id": $tag_id,
"name": "$tag_name"
}
]
}
END_DOC
)

echo "$pet_to_add"

curl -X 'POST' \
"$rest_url" \
-H 'accept: application/xml' \
-H 'Content-Type: application/json' \
-d "$pet_to_add"
}

add_petstore "http://localhost:8080/v2/pet" "151" "12" "Dogs" "REX" "http://photosofrex/rex_rage.jpg" "1" "ferocious sales"
Loading

0 comments on commit 03c2e8f

Please sign in to comment.