Skip to content

Commit 027683e

Browse files
committed
wip
1 parent 2e5071e commit 027683e

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

parser_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,47 @@ func TestDecodeValueErrorsRemote(t *testing.T) {
688688
}
689689
}
690690

691+
// Test that files in fields with relative paths or URLs (ie. logo, screenshots, etc.)
692+
// are checked and expanded correctly
693+
func TestRelativePathsOrURLs(t *testing.T) {
694+
testRemoteFiles := []testType{
695+
// Should look for the logo relative to this URL
696+
{"https://raw.githubusercontent.com/italia/publiccode-parser-go/refs/heads/relative-paths/testdata/v0/invalid/description_en_screenshots_missing_file.yml", ValidationResults{
697+
ValidationError{"description.en.screenshots[0]", "'no_such_file.png' is not an image: HTTP GET failed for https://raw.githubusercontent.com/italia/publiccode-parser-go/refs/heads/testdata/v0/invalid/no_such_file.png: not found", 20, 5},
698+
}},
699+
700+
// Should look for the logo relative to this path
701+
{"testdata/v0/invalid/description_en_screenshots_missing_file.yml", ValidationResults{
702+
ValidationError{"description.en.screenshots[0]", "'no_such_file.png' is not an image: no_such_file.png: not found", 20, 5},
703+
}},
704+
705+
//
706+
{"https://raw.githubusercontent.com/italia/publiccode-parser-go/refs/heads/relative-paths/testdata/v0/invalid/logo_missing_url.yml", ValidationResults{
707+
ValidationError{"description.en.screenshots[0]", "'no_such_file.png' is not an image: HTTP GET failed for https://raw.githubusercontent.com/italia/publiccode-parser-go/refs/heads/testdata/v0/invalid/no_such_file.png: not found", 20, 5},
708+
}},
709+
710+
//
711+
{"testdata/v0/invalid/logo_missing_url.yml", ValidationResults{
712+
ValidationError{"description.en.screenshots[0]", "'no_such_file.png' is not an image: no_such_file.png: not found", 20, 5},
713+
}},
714+
}
715+
716+
parser, err := NewDefaultParser()
717+
if err != nil {
718+
t.Errorf("Can't create parser: %v", err)
719+
}
720+
721+
for _, test := range testRemoteFiles {
722+
t.Run(fmt.Sprintf("%v", test.err), func(t *testing.T) {
723+
var err error
724+
725+
_, err = parser.Parse(test.file)
726+
727+
checkParseErrors(t, err, test)
728+
})
729+
}
730+
}
731+
691732
func TestUrlMissingWithoutPath(t *testing.T) {
692733
expected := map[string]error{
693734
"url_missing.yml": ValidationResults{
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
publiccodeYmlVersion: "0.4"
2+
3+
name: Medusa
4+
url: "https://github.com/italia/developers.italia.it.git"
5+
releaseDate: "2017-04-15"
6+
7+
platforms:
8+
- web
9+
10+
categories:
11+
- cloud-management
12+
13+
developmentStatus: development
14+
15+
softwareType: "standalone/other"
16+
17+
# Should NOT validate: logo URL must point to an existing file
18+
logo: "https://google.com/no_such_file.png"
19+
20+
description:
21+
en:
22+
localisedName: Medusa
23+
shortDescription: >
24+
A rather short description which
25+
is probably useless
26+
longDescription: >
27+
Very long description of this software, also split
28+
on multiple rows. You should note what the software
29+
is and why one should need it. This is 158 characters.
30+
Very long description of this software, also split
31+
on multiple rows. You should note what the software
32+
is and why one should need it. This is 316 characters.
33+
Very long description of this software, also split
34+
on multiple rows. You should note what the software
35+
is and why one should need it. This is 474 characters.
36+
Very long description of this software, also split
37+
on multiple rows. You should note what the software
38+
is and why one should need it. This is 632 characters.
39+
features:
40+
- Just one feature
41+
42+
legal:
43+
license: AGPL-3.0-or-later
44+
45+
maintenance:
46+
type: "community"
47+
48+
contacts:
49+
- name: Francesco Rossi
50+
51+
localisation:
52+
localisationReady: true
53+
availableLanguages:
54+
- en
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
publiccodeYmlVersion: "0.4"
2+
3+
name: Medusa
4+
url: "https://github.com/italia/developers.italia.it.git"
5+
6+
# Logo with an URL
7+
logo: "https://raw.githubusercontent.com/italia/publiccode-parser-go/refs/heads/main/testdata/img/logo.png"
8+
9+
platforms:
10+
- web
11+
12+
categories:
13+
- cloud-management
14+
15+
developmentStatus: development
16+
17+
softwareType: "standalone/other"
18+
19+
description:
20+
en_GB:
21+
localisedName: Medusa
22+
shortDescription: >
23+
A rather short description which
24+
is probably useless
25+
longDescription: >
26+
Very long description of this software, also split
27+
on multiple rows. You should note what the software
28+
is and why one should need it. This is 158 characters.
29+
Very long description of this software, also split
30+
on multiple rows. You should note what the software
31+
is and why one should need it. This is 316 characters.
32+
Very long description of this software, also split
33+
on multiple rows. You should note what the software
34+
is and why one should need it. This is 474 characters.
35+
Very long description of this software, also split
36+
on multiple rows. You should note what the software
37+
is and why one should need it. This is 632 characters.
38+
features:
39+
- Just one feature
40+
41+
legal:
42+
license: AGPL-3.0-or-later
43+
44+
maintenance:
45+
type: "community"
46+
47+
contacts:
48+
- name: Francesco Rossi
49+
50+
localisation:
51+
localisationReady: true
52+
availableLanguages:
53+
- en

0 commit comments

Comments
 (0)