-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
meta: write out metadata links (#4275)
Signed-off-by: Sergio Schvezov <[email protected]>
- Loading branch information
1 parent
833b0f2
commit de56fe6
Showing
3 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,111 @@ def test_assumes(simple_project, new_dir): | |
) | ||
|
||
|
||
def test_links_scalars(simple_project, new_dir): | ||
snap_yaml.write( | ||
simple_project( | ||
contact="[email protected]", | ||
issues="https://hubhub.com/issues", | ||
donation="https://moneyfornothing.com", | ||
source_code="https://closed.acme.com", | ||
website="https://acme.com", | ||
), | ||
prime_dir=Path(new_dir), | ||
arch="amd64", | ||
) | ||
yaml_file = Path("meta/snap.yaml") | ||
assert yaml_file.is_file() | ||
|
||
content = yaml_file.read_text() | ||
assert content == textwrap.dedent( | ||
"""\ | ||
name: mytest | ||
version: 1.29.3 | ||
summary: Single-line elevator pitch for your amazing snap | ||
description: test-description | ||
architectures: | ||
- amd64 | ||
base: core22 | ||
apps: | ||
app1: | ||
command: bin/mytest | ||
confinement: strict | ||
grade: stable | ||
environment: | ||
LD_LIBRARY_PATH: ${SNAP_LIBRARY_PATH}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} | ||
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH | ||
links: | ||
contact: | ||
- [email protected] | ||
donation: | ||
- https://moneyfornothing.com | ||
issues: | ||
- https://hubhub.com/issues | ||
source-code: | ||
- https://closed.acme.com | ||
website: | ||
- https://acme.com | ||
""" | ||
) | ||
|
||
|
||
def test_links_lists(simple_project, new_dir): | ||
snap_yaml.write( | ||
simple_project( | ||
contact=[ | ||
"[email protected]", | ||
"[email protected]", | ||
], | ||
issues=[ | ||
"https://hubhub.com/issues", | ||
"https://corner.com/issues", | ||
], | ||
donation=["https://moneyfornothing.com", "https://prince.com"], | ||
source_code="https://closed.acme.com", | ||
website="https://acme.com", | ||
), | ||
prime_dir=Path(new_dir), | ||
arch="amd64", | ||
) | ||
yaml_file = Path("meta/snap.yaml") | ||
assert yaml_file.is_file() | ||
|
||
content = yaml_file.read_text() | ||
assert content == textwrap.dedent( | ||
"""\ | ||
name: mytest | ||
version: 1.29.3 | ||
summary: Single-line elevator pitch for your amazing snap | ||
description: test-description | ||
architectures: | ||
- amd64 | ||
base: core22 | ||
apps: | ||
app1: | ||
command: bin/mytest | ||
confinement: strict | ||
grade: stable | ||
environment: | ||
LD_LIBRARY_PATH: ${SNAP_LIBRARY_PATH}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} | ||
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH | ||
links: | ||
contact: | ||
- [email protected] | ||
- [email protected] | ||
donation: | ||
- https://moneyfornothing.com | ||
- https://prince.com | ||
issues: | ||
- https://hubhub.com/issues | ||
- https://corner.com/issues | ||
source-code: | ||
- https://closed.acme.com | ||
website: | ||
- https://acme.com | ||
""" | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def complex_project(): | ||
snapcraft_yaml = textwrap.dedent( | ||
|
@@ -1025,3 +1130,60 @@ def test_architectures_all(simple_project, new_dir): | |
"${SNAP_LIBRARY_PATH}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}:" | ||
"$SNAP/lib:$SNAP/usr/lib\n" | ||
) in content | ||
|
||
|
||
############## | ||
# Test Links # | ||
############## | ||
|
||
|
||
def test_links_for_scalars(simple_project): | ||
project = simple_project( | ||
contact="[email protected]", | ||
issues="https://hubhub.com/issues", | ||
donation="https://moneyfornothing.com", | ||
source_code="https://closed.acme.com", | ||
website="https://acme.com", | ||
) | ||
|
||
links = snap_yaml.Links.from_project(project) | ||
|
||
assert links.contact == [project.contact] | ||
assert links.issues == [project.issues] | ||
assert links.donation == [project.donation] | ||
assert links.source_code == [project.source_code] | ||
assert links.website == [project.website] | ||
|
||
assert bool(links) is True | ||
|
||
|
||
def test_links_for_lists(simple_project): | ||
project = simple_project( | ||
contact=[ | ||
"[email protected]", | ||
"[email protected]", | ||
], | ||
issues=[ | ||
"https://hubhub.com/issues", | ||
"https://corner.com/issues", | ||
], | ||
donation=["https://moneyfornothing.com", "https://prince.com"], | ||
) | ||
|
||
links = snap_yaml.Links.from_project(project) | ||
|
||
assert links.contact == project.contact | ||
assert links.issues == project.issues | ||
assert links.donation == project.donation | ||
assert links.source_code is None | ||
assert links.website is None | ||
|
||
assert bool(links) is True | ||
|
||
|
||
def test_no_links(simple_project): | ||
project = simple_project() | ||
|
||
links = snap_yaml.Links.from_project(project) | ||
|
||
assert bool(links) is False |