@@ -33,6 +33,19 @@ func parse(file string) error {
33
33
return err
34
34
}
35
35
36
+ func parseNoNetwork (file string ) error {
37
+ var p * Parser
38
+ var err error
39
+
40
+ if p , err = NewParser (ParserConfig {DisableNetwork : true }); err != nil {
41
+ return err
42
+ }
43
+
44
+ _ , err = p .Parse (file )
45
+
46
+ return err
47
+ }
48
+
36
49
// Check all the YAML files matching the glob pattern and fail for each file
37
50
// with parsing or validation errors.
38
51
func checkValidFiles (pattern string , t * testing.T ) {
@@ -69,12 +82,39 @@ func TestValidPreviousStandardVersion(t *testing.T) {
69
82
})
70
83
})
71
84
}
72
- func TestInvalidTestcasesV0_3 (t * testing.T ) {
73
- cwd , err := os .Getwd ()
74
- if err != nil {
75
- t .Errorf ("Can't get current working directory" )
85
+
86
+ func TestInvalidTestcasesV0_3_NoNetwork (t * testing.T ) {
87
+ expected := map [string ]error {
88
+ // logo
89
+ "logo_missing_file.yml" : ValidationResults {
90
+ ValidationError {"logo" , "no such file: no_such_file.png" , 18 , 1 },
91
+ },
92
+ "logo_invalid_png.yml" : ValidationResults {
93
+ ValidationError {"logo" , "image: unknown format" , 18 , 1 },
94
+ },
95
+
96
+ // monochromeLogo
97
+ "monochromeLogo_invalid_png.yml" : ValidationResults {
98
+ ValidationWarning {"monochromeLogo" , "This key is DEPRECATED and will be removed in the future" , 18 , 1 },
99
+ ValidationError {"monochromeLogo" , "image: unknown format" , 18 , 1 },
100
+ },
101
+
76
102
}
77
103
104
+ testFiles , _ := filepath .Glob ("testdata/v0.3/invalid/no-network/*yml" )
105
+ for _ , file := range testFiles {
106
+ baseName := path .Base (file )
107
+ if expected [baseName ] == nil {
108
+ t .Errorf ("No expected data for file %s" , baseName )
109
+ }
110
+ t .Run (file , func (t * testing.T ) {
111
+ err := parseNoNetwork (file )
112
+ checkParseErrors (t , err , testType {file , expected [baseName ]})
113
+ })
114
+ }
115
+ }
116
+
117
+ func TestInvalidTestcasesV0_3 (t * testing.T ) {
78
118
expected := map [string ]error {
79
119
// publiccodeYmlVersion
80
120
"publiccodeYmlVersion_missing.yml" : ValidationResults {ValidationError {"publiccodeYmlVersion" , "required" , 0 , 0 }},
@@ -83,7 +123,7 @@ func TestInvalidTestcasesV0_3(t *testing.T) {
83
123
}},
84
124
"publiccodeYmlVersion_wrong_type.yml" : ValidationResults {
85
125
ValidationError {"publiccodeYmlVersion" , "wrong type for this field" , 2 , 1 },
86
- ValidationError { "publiccodeYmlVersion" , "required" , 2 , 1 } },
126
+ },
87
127
88
128
// name
89
129
"name_missing.yml" : ValidationResults {ValidationError {"name" , "required" , 1 , 1 }},
@@ -152,13 +192,10 @@ func TestInvalidTestcasesV0_3(t *testing.T) {
152
192
ValidationError {"logo" , "wrong type for this field" , 18 , 1 },
153
193
},
154
194
"logo_unsupported_extension.yml" : ValidationResults {
155
- ValidationError {"logo" , fmt . Sprintf ( "invalid file extension for: %s/ logo.mpg" , cwd ) , 18 , 1 },
195
+ ValidationError {"logo" , "invalid file extension for: https://raw.githubusercontent.com/italia/developers.italia.it/main/ logo.mpg" , 18 , 1 },
156
196
},
157
197
"logo_missing_file.yml" : ValidationResults {
158
- ValidationError {"logo" , fmt .Sprintf ("no such file: %s/no_such_file.png" , cwd ), 18 , 1 },
159
- },
160
- "logo_invalid_png.yml" : ValidationResults {
161
- ValidationError {"logo" , "image: unknown format" , 18 , 1 },
198
+ ValidationError {"logo" , "no such file: https://raw.githubusercontent.com/italia/developers.italia.it/main/no_such_file.png" , 18 , 1 },
162
199
},
163
200
164
201
// monochromeLogo
@@ -169,18 +206,14 @@ func TestInvalidTestcasesV0_3(t *testing.T) {
169
206
ValidationWarning {"monochromeLogo" , "This key is DEPRECATED and will be removed in the future" , 18 , 1 },
170
207
ValidationError {
171
208
"monochromeLogo" ,
172
- fmt . Sprintf ( "invalid file extension for: %s/ monochromeLogo.mpg" , cwd ) ,
209
+ "invalid file extension for: https://raw.githubusercontent.com/italia/developers.italia.it/main/ monochromeLogo.mpg" ,
173
210
18 ,
174
211
1 ,
175
212
},
176
213
},
177
214
"monochromeLogo_missing_file.yml" : ValidationResults {
178
215
ValidationWarning {"monochromeLogo" , "This key is DEPRECATED and will be removed in the future" , 18 , 1 },
179
- ValidationError {"monochromeLogo" , fmt .Sprintf ("no such file: %s/no_such_file.png" , cwd ), 18 , 1 },
180
- },
181
- "monochromeLogo_invalid_png.yml" : ValidationResults {
182
- ValidationWarning {"monochromeLogo" , "This key is DEPRECATED and will be removed in the future" , 18 , 1 },
183
- ValidationError {"monochromeLogo" , "image: unknown format" , 18 , 1 },
216
+ ValidationError {"monochromeLogo" , "no such file: https://raw.githubusercontent.com/italia/developers.italia.it/main/no_such_file.png" , 18 , 1 },
184
217
},
185
218
186
219
// inputTypes
0 commit comments