Skip to content

Commit 3bb3a2c

Browse files
Copilotlengau
andcommitted
Use pre-existing charm subdirectories in spread test
Instead of using charmcraft init, include charm/ and upload-dir/ subdirectories with pre-existing charmcraft.yaml file. This follows the pattern used in other spread tests. Co-authored-by: lengau <[email protected]>
1 parent 424a6c4 commit 3bb3a2c

File tree

5 files changed

+42
-12
lines changed

5 files changed

+42
-12
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
type: charm
2+
bases:
3+
- build-on:
4+
- name: ubuntu
5+
channel: "22.04"
6+
run-on:
7+
- name: ubuntu
8+
channel: "22.04"
9+
10+
charmhub:
11+
api-url: https://api.staging.charmhub.io
12+
storage-url: https://storage.staging.snapcraftcontent.com
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ops >= 2.0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2024 Canonical Ltd.
3+
# See LICENSE file for licensing details.
4+
5+
"""Charm for testing upload outside project directory."""
6+
7+
import logging
8+
9+
from ops.charm import CharmBase
10+
from ops.main import main
11+
12+
logger = logging.getLogger(__name__)
13+
14+
15+
class TestCharm(CharmBase):
16+
"""Charm for testing upload outside project directory."""
17+
18+
def __init__(self, *args):
19+
super().__init__(*args)
20+
21+
22+
if __name__ == "__main__": # pragma: nocover
23+
main(TestCharm)

tests/spread/store/upload-outside-project/task.yaml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,28 @@ summary: upload charm from outside project directory
22

33
include:
44
- tests/
5+
- charm/
6+
- upload-dir/
57

68
prepare: |
79
tests.pkgs install jq
8-
charmcraft init --project-dir=charm --name=$CHARM_DEFAULT_NAME --profile=machine
9-
cd charm
10-
11-
cat <<- EOF >> charmcraft.yaml
12-
charmhub:
13-
api-url: https://api.staging.charmhub.io
14-
storage-url: https://storage.staging.snapcraftcontent.com
15-
EOF
1610
1711
restore: |
1812
pushd charm
1913
charmcraft clean
2014
popd
2115
22-
rm -rf charm upload-dir
23-
2416
execute: |
17+
# Set the charm name in the charmcraft.yaml
2518
cd charm
19+
sed -i "1i name: $CHARM_DEFAULT_NAME" charmcraft.yaml
2620
2721
# pack the charm
2822
charmcraft pack --verbose
2923
test -f $CHARM_DEFAULT_NAME*.charm
3024
charm_filepath=$(ls $CHARM_DEFAULT_NAME*.charm)
3125
32-
# Move the charm file to a different directory (outside project)
33-
mkdir -p ../upload-dir
26+
# Move the charm file to the upload directory (outside project)
3427
mv $charm_filepath ../upload-dir/
3528
3629
# Change to the upload directory (which has no charmcraft.yaml)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This directory is used for uploading the charm from outside the project

0 commit comments

Comments
 (0)