Skip to content

Commit 424a6c4

Browse files
Copilotlengau
andcommitted
Add spread test for upload outside project directory
Co-authored-by: lengau <[email protected]>
1 parent 72d15d3 commit 424a6c4

File tree

1 file changed

+56
-0
lines changed
  • tests/spread/store/upload-outside-project

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
summary: upload charm from outside project directory
2+
3+
include:
4+
- tests/
5+
6+
prepare: |
7+
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
16+
17+
restore: |
18+
pushd charm
19+
charmcraft clean
20+
popd
21+
22+
rm -rf charm upload-dir
23+
24+
execute: |
25+
cd charm
26+
27+
# pack the charm
28+
charmcraft pack --verbose
29+
test -f $CHARM_DEFAULT_NAME*.charm
30+
charm_filepath=$(ls $CHARM_DEFAULT_NAME*.charm)
31+
32+
# Move the charm file to a different directory (outside project)
33+
mkdir -p ../upload-dir
34+
mv $charm_filepath ../upload-dir/
35+
36+
# Change to the upload directory (which has no charmcraft.yaml)
37+
cd ../upload-dir
38+
39+
# Verify we're outside the project directory
40+
if [ -f charmcraft.yaml ]; then
41+
echo "ERROR: charmcraft.yaml should not exist in upload directory"
42+
exit 1
43+
fi
44+
45+
# Upload the charm from outside the project directory
46+
# This should NOT crash with "Project not configured yet" error
47+
charm_file=$(ls $CHARM_DEFAULT_NAME*.charm)
48+
uploaded_revno=$(charmcraft upload $charm_file --format=json | jq .revision)
49+
50+
# Verify we got a valid revision number
51+
if [ -z "$uploaded_revno" ] || [ "$uploaded_revno" == "null" ]; then
52+
echo "ERROR: Failed to upload charm or get revision number"
53+
exit 1
54+
fi
55+
56+
echo "Successfully uploaded charm from outside project directory. Revision: $uploaded_revno"

0 commit comments

Comments
 (0)