Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt integration tests to reuse the packed charm #13

Merged
merged 14 commits into from
Aug 25, 2023
1 change: 1 addition & 0 deletions .trivyignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ CVE-2022-28948
CVE-2022-3064
CVE-2022-32149
CVE-2022-41723
CVE-2023-2515
33 changes: 18 additions & 15 deletions mattermost.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ RUN apt-get -y update && \
apt-get -y --no-install-recommends install \
git \
curl \
make \
&& \
curl -s https://deb.nodesource.com/setup_16.x | bash && \
apt-get -y update && \
apt-get -y --no-install-recommends install nodejs
make && \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash && \
bash -c "source /root/.nvm/nvm.sh && nvm install v16.14.0"

ENV PATH="$PATH:/root/.nvm/versions/node/v16.14.0/bin"

# Patch the https-proxy-agent library used by npm to limit the open socket
# number connected to proxy server.
Expand All @@ -31,16 +31,19 @@ RUN apt-get -y update && \
COPY files/canonical_flavour/https-proxy-agent.patch patch/https-proxy-agent.patch

RUN curl -sSL https://github.com/TooTallNate/node-https-proxy-agent/archive/refs/tags/5.0.1.tar.gz -o node-https-proxy-agent.tar.gz && \
echo "1afed785d8d9deadac371824d6622aeabc7919ed6db3b3a6ad0033bd1105d2f4 node-https-proxy-agent.tar.gz" | shasum -c && \
tar -xf node-https-proxy-agent.tar.gz && \
cd node-https-proxy-agent-5.0.1 && \
git apply /patch/https-proxy-agent.patch && \
npm config set progress=false loglevel=info && \
npm install && \
echo "36ee41503f9245b2b8ce3e4725ac966cf9a391f4 node-https-proxy-agent.tar.gz" | shasum -c && \
tar -xf node-https-proxy-agent.tar.gz

WORKDIR proxy-agents-5.0.1
RUN git apply /patch/https-proxy-agent.patch && \
npm config set progress=false loglevel=info

RUN npm install && \
npm run build && \
rm -rf /usr/lib/node_modules/npm/node_modules/https-proxy-agent/ && \
mv ./dist /usr/lib/node_modules/npm/node_modules/https-proxy-agent && \
cd ..
mv ./dist /root/.nvm/versions/node/v16.14.0/lib/node_modules/https-proxy-agent

WORKDIR /

COPY files/canonical_flavour/themes.patch patch/themes.patch

Expand All @@ -66,10 +69,10 @@ LABEL com.canonical.mattermost-edition=${edition}
# We use "set -o pipefail"
SHELL ["/bin/bash", "-c"]

# python3-yaml needed to run juju actions, xmlsec1 needed if UseNewSAMLLibrary is set to false (the default)
# xmlsec1 needed if UseNewSAMLLibrary is set to false (the default)
RUN apt-get -qy update && \
apt-get -qy upgrade && \
apt-get -qy install curl python3-yaml xmlsec1 && \
apt-get -qy install curl xmlsec1 && \
rm -f /var/lib/apt/lists/*_*

RUN mkdir -p /mattermost/data /mattermost/plugins /mattermost/client/plugins && \
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def pytest_addoption(parser: pytest.Parser):
Args:
parser: Pytest parser used to add arguments to console commands
"""
parser.addoption("--charm-file", action="store")
# Localstack instance URL
parser.addoption("--localstack-url", action="store", default="")
# OCI image of mattermost
Expand Down
14 changes: 11 additions & 3 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ def mattermost_image(request):
return request.config.getoption("--mattermost-image")


@fixture(scope="module")
def charm_file(request):
"""Get the charm file from the --charm-file argument.

Return a the mattermost image name
"""
return request.config.getoption("--charm-file")


@pytest_asyncio.fixture(scope="module", name="model")
async def model_fixture(ops_test: OpsTest) -> ops.model.Model:
"""Provide current test model."""
Expand All @@ -63,15 +72,14 @@ async def app(
model: ops.model.Model,
app_name: str,
mattermost_image: str,
charm_file: str,
):
"""Mattermost charm used for integration testing.

Builds the charm and deploys it and the relations it depends on.
"""
await model.deploy("postgresql-k8s"),

charm = await ops_test.build_charm(".")
application = await model.deploy(charm, application_name=app_name, series="focal")
application = await model.deploy(f".{charm_file}", application_name=app_name, series="focal")
await model.wait_for_idle()

# Change the image that will be used for the mattermost container
Expand Down
Loading