Merge lp:~mvo/snappy/snappy-lp1459212-check-required-fields into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Michael Vogt on 2015-05-28
Status: Merged
Approved by: Michael Vogt on 2015-06-09
Approved revision: 484
Merged at revision: 498
Proposed branch: lp:~mvo/snappy/snappy-lp1459212-check-required-fields
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 577 lines (+179/-37)
9 files modified
helpers/helpers.go (+10/-0)
helpers/helpers_test.go (+15/-0)
snappy/click_test.go (+49/-10)
snappy/config_test.go (+2/-0)
snappy/install_test.go (+1/-1)
snappy/parts_test.go (+1/-1)
snappy/purge_test.go (+1/-1)
snappy/snapp.go (+42/-18)
snappy/snapp_test.go (+58/-6)
To merge this branch: bzr merge lp:~mvo/snappy/snappy-lp1459212-check-required-fields
Reviewer Review Type Date Requested Status
Michael Vogt Approve on 2015-06-09
Michael Terry (community) 2015-05-28 Approve on 2015-06-08
Review via email: mp+260509@code.launchpad.net

Commit Message

Check the package.yaml for the required fields.

Description of the Change

Tiny branch to check the package.yaml for the required fields. Open for
ideas about generating the error in a more elegant way.

To post a comment you must log in.
Sergio Schvezov (sergiusens) wrote :

I would check for all the missing fields, append them and then
if len(missingFields) != 0 {
    fmt.Errorf(".... %s", strings.Join(missingFields, ","))
}

Michael Vogt (mvo) wrote :

Thanks Sergio, I updated the branch and tried to make it nicer. Maybe I went a bit overboard, not sure. You will let me know :)

Michael Terry (mterry) wrote :

LP doesn't show the diff, so I'll make all comments here.

===
In helpers_test.go:

+ func (ts *HTestSuite) TestGetattr(c *C) {
+ T := struct{
+ S string

There should be a space between struct and the brace. gofmt complains about it.

===
As for the strings.Join(missingFields, ",")) bit, you didn't want a space after the comma too? (Or fancy ngettext work to make fields singular sometimes? :))

===
Otherwise, it looks great! Nice collection of validation code into validatePackageYamlData.

review: Needs Fixing
Michael Vogt (mvo) wrote :

Thanks a bunch! I fixed the go fmt issue and added a extra space for the ", " join. No fancy ngettext() yet ;) The i18n story is something we have not tackled at all yet.

Michael Terry (mterry) wrote :

Aw, I was going to approve, but now you have conflicts.

Michael Terry (mterry) wrote :

Oh and you need to update your tests now that there is a space after the comma.

Michael Vogt (mvo) wrote :

I updated the tests and merged trunk. Should be ready now.

Michael Terry (mterry) wrote :

Perfect!

review: Approve
Snappy Tarmac (snappydevtarmac) wrote :

Attempt to merge into lp:snappy failed due to conflicts:

text conflict in snappy/snapp_test.go

484. By Michael Vogt on 2015-06-09

merged lp:snappy and resolved conflicts

Michael Vogt (mvo) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'helpers/helpers.go'
2--- helpers/helpers.go 2015-06-08 14:25:07 +0000
3+++ helpers/helpers.go 2015-06-09 19:11:58 +0000
4@@ -31,6 +31,7 @@
5 "os/exec"
6 "os/user"
7 "path/filepath"
8+ "reflect"
9 "runtime"
10 "strings"
11 "syscall"
12@@ -370,6 +371,15 @@
13 return uint32((minor & 0xff) | ((major & 0xfff) << 8))
14 }
15
16+// Getattr get the attribute of the given name
17+func Getattr(i interface{}, name string) interface{} {
18+ v := reflect.ValueOf(i)
19+ if v.Kind() == reflect.Ptr {
20+ v = v.Elem()
21+ }
22+ return v.FieldByName(name).Interface()
23+}
24+
25 func fillSnapEnvVars(desc interface{}, vars []string) []string {
26 for i, v := range vars {
27 var templateOut bytes.Buffer
28
29=== modified file 'helpers/helpers_test.go'
30--- helpers/helpers_test.go 2015-06-08 14:25:07 +0000
31+++ helpers/helpers_test.go 2015-06-09 19:11:58 +0000
32@@ -327,7 +327,22 @@
33 err = UnpackTar(f, c.MkDir(), nil)
34 c.Assert(err, IsNil)
35 c.Assert(mknodWasCalled, Equals, true)
36+}
37
38+func (ts *HTestSuite) TestGetattr(c *C) {
39+ T := struct {
40+ S string
41+ I int
42+ }{
43+ S: "foo",
44+ I: 42,
45+ }
46+ // works on values
47+ c.Assert(Getattr(T, "S").(string), Equals, "foo")
48+ c.Assert(Getattr(T, "I").(int), Equals, 42)
49+ // works for pointers too
50+ c.Assert(Getattr(&T, "S").(string), Equals, "foo")
51+ c.Assert(Getattr(&T, "I").(int), Equals, 42)
52 }
53
54 func makeTestFiles(c *C, srcDir, destDir string) {
55
56=== modified file 'snappy/click_test.go'
57--- snappy/click_test.go 2015-06-09 17:02:32 +0000
58+++ snappy/click_test.go 2015-06-09 19:11:58 +0000
59@@ -248,7 +248,11 @@
60 // if the snap asks for accepting a license, and an agreer isn't provided,
61 // install fails
62 func (s *SnapTestSuite) TestLocalSnapInstallMissingAccepterFails(c *C) {
63- pkg := makeTestSnapPackage(c, "explicit-license-agreement: Y")
64+ pkg := makeTestSnapPackage(c, `
65+name: foo
66+version: 1.0
67+vendor: foo
68+explicit-license-agreement: Y`)
69 _, err := installClick(pkg, 0, nil, testOrigin)
70 c.Check(err, Equals, ErrLicenseNotAccepted)
71 }
72@@ -256,7 +260,11 @@
73 // if the snap asks for accepting a license, and an agreer is provided, and
74 // Agreed returns false, install fails
75 func (s *SnapTestSuite) TestLocalSnapInstallNegAccepterFails(c *C) {
76- pkg := makeTestSnapPackage(c, "explicit-license-agreement: Y")
77+ pkg := makeTestSnapPackage(c, `
78+name: foo
79+version: 1.0
80+vendor: foo
81+explicit-license-agreement: Y`)
82 _, err := installClick(pkg, 0, &MockProgressMeter{y: false}, testOrigin)
83 c.Check(err, Equals, ErrLicenseNotAccepted)
84 }
85@@ -267,7 +275,11 @@
86 licenseChecker = func(string) error { return nil }
87 defer func() { licenseChecker = checkLicenseExists }()
88
89- pkg := makeTestSnapPackageFull(c, "explicit-license-agreement: Y", false)
90+ pkg := makeTestSnapPackageFull(c, `
91+name: foo
92+version: 1.0
93+vendor: foo
94+explicit-license-agreement: Y`, false)
95 _, err := installClick(pkg, 0, &MockProgressMeter{y: true}, testOrigin)
96 c.Check(err, Equals, ErrLicenseNotProvided)
97 }
98@@ -275,14 +287,22 @@
99 // if the snap asks for accepting a license, and an agreer is provided, and
100 // Agreed returns true, install succeeds
101 func (s *SnapTestSuite) TestLocalSnapInstallPosAccepterWorks(c *C) {
102- pkg := makeTestSnapPackage(c, "explicit-license-agreement: Y")
103+ pkg := makeTestSnapPackage(c, `
104+name: foo
105+version: 1.0
106+vendor: foo
107+explicit-license-agreement: Y`)
108 _, err := installClick(pkg, 0, &MockProgressMeter{y: true}, testOrigin)
109 c.Check(err, Equals, nil)
110 }
111
112 // Agreed is given reasonable values for intro and license
113 func (s *SnapTestSuite) TestLocalSnapInstallAccepterReasonable(c *C) {
114- pkg := makeTestSnapPackage(c, "name: foobar\nexplicit-license-agreement: Y")
115+ pkg := makeTestSnapPackage(c, `
116+name: foobar
117+version: 1.0
118+vendor: foo
119+explicit-license-agreement: Y`)
120 ag := &MockProgressMeter{y: true}
121 _, err := installClick(pkg, 0, ag, testOrigin)
122 c.Assert(err, Equals, nil)
123@@ -294,7 +314,11 @@
124 // isn't called
125 func (s *SnapTestSuite) TestPreviouslyAcceptedLicense(c *C) {
126 ag := &MockProgressMeter{y: true}
127- yaml := "name: foox\nexplicit-license-agreement: Y\nlicense-version: 2\n"
128+ yaml := `name: foox
129+explicit-license-agreement: Y
130+license-version: 2
131+vendor: foo
132+`
133 yamlFile, err := makeInstalledMockSnap(s.tempdir, yaml+"version: 1")
134 pkgdir := filepath.Dir(filepath.Dir(yamlFile))
135 c.Assert(os.MkdirAll(filepath.Join(pkgdir, ".click", "info"), 0755), IsNil)
136@@ -314,7 +338,11 @@
137 // explicit license agreement set, the agreer *is* called
138 func (s *SnapTestSuite) TestSameLicenseVersionButNotRequired(c *C) {
139 ag := &MockProgressMeter{y: true}
140- yaml := "name: foox\nlicense-version: 2\n"
141+ yaml := `name: foox
142+license-version: 2
143+version: 1.0
144+vendor: foo
145+`
146 yamlFile, err := makeInstalledMockSnap(s.tempdir, yaml+"version: 1")
147 pkgdir := filepath.Dir(filepath.Dir(yamlFile))
148 c.Assert(os.MkdirAll(filepath.Join(pkgdir, ".click", "info"), 0755), IsNil)
149@@ -323,7 +351,7 @@
150 c.Assert(err, IsNil)
151 c.Assert(part.activate(true, ag), IsNil)
152
153- pkg := makeTestSnapPackage(c, yaml+"version: 2\nexplicit-license-agreement: Y")
154+ pkg := makeTestSnapPackage(c, yaml+"version: 2\nexplicit-license-agreement: Y\nvendor: foo")
155 _, err = installClick(pkg, 0, ag, testOrigin)
156 c.Assert(err, Equals, nil)
157 c.Check(ag.license, Equals, "WTFPL")
158@@ -333,7 +361,10 @@
159 // agreer *is* called
160 func (s *SnapTestSuite) TestDifferentLicenseVersion(c *C) {
161 ag := &MockProgressMeter{y: true}
162- yaml := "name: foox\nexplicit-license-agreement: Y\n"
163+ yaml := `name: foox
164+vendor: foo
165+explicit-license-agreement: Y
166+`
167 yamlFile, err := makeInstalledMockSnap(s.tempdir, yaml+"license-version: 2\nversion: 1")
168 pkgdir := filepath.Dir(filepath.Dir(yamlFile))
169 c.Assert(os.MkdirAll(filepath.Join(pkgdir, ".click", "info"), 0755), IsNil)
170@@ -897,7 +928,11 @@
171
172 func (s *SnapTestSuite) setupSnappyDependentServices(c *C) (string, *MockProgressMeter) {
173 inter := &MockProgressMeter{}
174- fmkYaml := "name: fmk\ntype: framework\nversion: "
175+ fmkYaml := `name: fmk
176+version: 1.0
177+vendor: foo
178+type: framework
179+version: `
180 fmkFile := makeTestSnapPackage(c, fmkYaml+"1")
181 _, err := installClick(fmkFile, AllowUnauthenticated, inter, "")
182 c.Assert(err, IsNil)
183@@ -1122,6 +1157,7 @@
184 yaml := `name: foo
185 version: 1
186 type: framework
187+vendor: foo
188 services:
189 - name: bar
190 bus-name: foo.bar.baz
191@@ -1140,6 +1176,7 @@
192 func (s *SnapTestSuite) TestAddPackageServicesBusPolicyNoFramework(c *C) {
193 yaml := `name: foo
194 version: 1
195+vendor: foo
196 type: app
197 services:
198 - name: bar
199@@ -1401,6 +1438,7 @@
200 func (s *SnapTestSuite) TestPackageYamlAddSecurityPolicy(c *C) {
201 m, err := parsePackageYamlData([]byte(`name: foo
202 version: 1.0
203+vendor: foo
204 binaries:
205 - name: foo
206 services:
207@@ -1424,6 +1462,7 @@
208 func (s *SnapTestSuite) TestPackageYamlRemoveSecurityPolicy(c *C) {
209 m, err := parsePackageYamlData([]byte(`name: foo
210 version: 1.0
211+vendor: foo
212 binaries:
213 - name: foo
214 services:
215
216=== modified file 'snappy/config_test.go'
217--- snappy/config_test.go 2015-06-02 20:46:07 +0000
218+++ snappy/config_test.go 2015-06-09 19:11:58 +0000
219@@ -98,6 +98,7 @@
220
221 snapDir, err := s.makeInstalledMockSnapWithConfig(c, mockConfig, `name: fmk
222 type: framework
223+vendor: foo
224 version: 42`)
225 c.Assert(err, IsNil)
226 _, err = snapConfig(snapDir, testOrigin, configYaml)
227@@ -105,6 +106,7 @@
228
229 snapDir, err = s.makeInstalledMockSnapWithConfig(c, mockConfig, `name: potato
230 type: potato
231+vendor: foo
232 version: 42`)
233 c.Assert(err, IsNil)
234 _, err = snapConfig(snapDir, testOrigin, configYaml)
235
236=== modified file 'snappy/install_test.go'
237--- snappy/install_test.go 2015-06-08 17:21:44 +0000
238+++ snappy/install_test.go 2015-06-09 19:11:58 +0000
239@@ -105,7 +105,7 @@
240 }
241
242 func (s *SnapTestSuite) TestInstallAppTwiceFails(c *C) {
243- snapPackage := makeTestSnapPackage(c, "name: foo\nversion: 2")
244+ snapPackage := makeTestSnapPackage(c, "name: foo\nversion: 2\nvendor: foo")
245 snapR, err := os.Open(snapPackage)
246 c.Assert(err, IsNil)
247 defer snapR.Close()
248
249=== modified file 'snappy/parts_test.go'
250--- snappy/parts_test.go 2015-06-08 17:21:45 +0000
251+++ snappy/parts_test.go 2015-06-09 19:11:58 +0000
252@@ -161,7 +161,7 @@
253 }
254
255 func (s *SnapTestSuite) TestFindSnapsByNameAndVersionFmk(c *C) {
256- _, err := makeInstalledMockSnap(s.tempdir, "name: fmk\ntype: framework\nversion: 1")
257+ _, err := makeInstalledMockSnap(s.tempdir, "name: fmk\ntype: framework\nversion: 1\nvendor: foo")
258 repo := NewLocalSnapRepository(snapAppsDir)
259 installed, err := repo.Installed()
260 c.Assert(err, IsNil)
261
262=== modified file 'snappy/purge_test.go'
263--- snappy/purge_test.go 2015-06-08 18:56:56 +0000
264+++ snappy/purge_test.go 2015-06-09 19:11:58 +0000
265@@ -71,7 +71,7 @@
266 panic("dunno what to do with args")
267 }
268 app := "hello-app." + testOrigin
269- yaml := "name: hello-app\nversion: " + version + "\n" + extra
270+ yaml := "version: 1.0\nvendor: foo\nname: hello-app\nversion: " + version + "\n" + extra
271 yamlFile, err := makeInstalledMockSnap(s.tempdir, yaml)
272 c.Assert(err, IsNil)
273 pkgdir := filepath.Dir(filepath.Dir(yamlFile))
274
275=== modified file 'snappy/snapp.go'
276--- snappy/snapp.go 2015-06-09 17:11:43 +0000
277+++ snappy/snapp.go 2015-06-09 19:11:58 +0000
278@@ -264,6 +264,44 @@
279 return parsePackageYamlData(yamlData)
280 }
281
282+func validatePackageYamlData(file string, yamlData []byte, m *packageYaml) error {
283+ // check mandatory fields
284+ missing := []string{}
285+ for _, name := range []string{"Name", "Version", "Vendor"} {
286+ s := helpers.Getattr(m, name).(string)
287+ if s == "" {
288+ missing = append(missing, strings.ToLower(name))
289+ }
290+ }
291+ if len(missing) > 0 {
292+ return &ErrInvalidYaml{
293+ file: file,
294+ yaml: yamlData,
295+ err: fmt.Errorf("missing required fields '%s'", strings.Join(missing, ", ")),
296+ }
297+ }
298+
299+ // this is to prevent installation of legacy packages such as those that
300+ // contain the origin/origin in the package name.
301+ if strings.ContainsRune(m.Name, '.') {
302+ return ErrPackageNameNotSupported
303+ }
304+
305+ // do all checks here
306+ for _, binary := range m.Binaries {
307+ if err := verifyBinariesYaml(binary); err != nil {
308+ return err
309+ }
310+ }
311+ for _, service := range m.Services {
312+ if err := verifyServiceYaml(service); err != nil {
313+ return err
314+ }
315+ }
316+
317+ return nil
318+}
319+
320 func parsePackageYamlData(yamlData []byte) (*packageYaml, error) {
321 var m packageYaml
322 err := yaml.Unmarshal(yamlData, &m)
323@@ -271,6 +309,10 @@
324 return nil, &ErrInvalidYaml{file: "package.yaml", err: err, yaml: yamlData}
325 }
326
327+ if err := validatePackageYamlData("package.yaml", yamlData, &m); err != nil {
328+ return nil, err
329+ }
330+
331 if m.Architectures == nil {
332 if m.DeprecatedArchitecture == nil {
333 m.Architectures = []string{"all"}
334@@ -279,12 +321,6 @@
335 }
336 }
337
338- // this is to prevent installation of legacy packages such as those that
339- // contain the origin/origin in the package name.
340- if strings.ContainsRune(m.Name, '.') {
341- return nil, ErrPackageNameNotSupported
342- }
343-
344 if m.DeprecatedFramework != "" {
345 logger.Noticef(`Use of deprecated "framework" key in yaml`)
346 if len(m.Frameworks) != 0 {
347@@ -295,18 +331,6 @@
348 m.DeprecatedFramework = ""
349 }
350
351- // do all checks here
352- for _, binary := range m.Binaries {
353- if err := verifyBinariesYaml(binary); err != nil {
354- return nil, err
355- }
356- }
357- for _, service := range m.Services {
358- if err := verifyServiceYaml(service); err != nil {
359- return nil, err
360- }
361- }
362-
363 // For backward compatiblity we allow that there is no "exec:" line
364 // in the binary definition and that its derived from the name.
365 //
366
367=== modified file 'snappy/snapp_test.go'
368--- snappy/snapp_test.go 2015-06-09 17:02:32 +0000
369+++ snappy/snapp_test.go 2015-06-09 19:11:58 +0000
370@@ -187,6 +187,7 @@
371 func (s *SnapTestSuite) TestLocalSnapFrameworks(c *C) {
372 snapYaml, err := makeInstalledMockSnap(s.tempdir, `name: foo
373 version: 1.0
374+vendor: foo
375 frameworks:
376 - one
377 - two
378@@ -678,6 +679,7 @@
379 func (s *SnapTestSuite) TestRemoteSnapUpgradeService(c *C) {
380 snapPackage := makeTestSnapPackage(c, `name: foo
381 version: 1.0
382+vendor: foo
383 services:
384 - name: svc
385 `)
386@@ -858,7 +860,11 @@
387
388 func (s *SnapTestSuite) TestPackageYamlLicenseParsing(c *C) {
389 y := filepath.Join(s.tempdir, "package.yaml")
390- ioutil.WriteFile(y, []byte(`explicit-license-agreement: Y`), 0644)
391+ ioutil.WriteFile(y, []byte(`
392+name: foo
393+version: 1.0
394+vendor: foo
395+explicit-license-agreement: Y`), 0644)
396 m, err := parsePackageYamlFile(y)
397 c.Assert(err, IsNil)
398 c.Assert(m.ExplicitLicenseAgreement, Equals, true)
399@@ -998,6 +1004,8 @@
400
401 func (s *SnapTestSuite) TestPackageYamlFrameworkParsing(c *C) {
402 m, err := parsePackageYamlData([]byte(`name: foo
403+version: 1.0
404+vendor: foo
405 framework: one, two
406 `))
407 c.Assert(err, IsNil)
408@@ -1008,6 +1016,8 @@
409
410 func (s *SnapTestSuite) TestPackageYamlFrameworksParsing(c *C) {
411 m, err := parsePackageYamlData([]byte(`name: foo
412+version: 1.0
413+vendor: foo
414 frameworks:
415 - one
416 - two
417@@ -1020,6 +1030,8 @@
418
419 func (s *SnapTestSuite) TestPackageYamlFrameworkAndFrameworksFails(c *C) {
420 _, err := parsePackageYamlData([]byte(`name: foo
421+version: 1.0
422+vendor: foo
423 frameworks:
424 - one
425 - two
426@@ -1029,7 +1041,7 @@
427 }
428
429 func (s *SnapTestSuite) TestDetectsAlreadyInstalled(c *C) {
430- data := "name: afoo\nversion: 1"
431+ data := "name: afoo\nversion: 1\nvendor: foo"
432 yamlPath, err := makeInstalledMockSnap(s.tempdir, data)
433 c.Assert(err, IsNil)
434 c.Assert(makeSnapActive(yamlPath), IsNil)
435@@ -1043,7 +1055,7 @@
436 // XXX: should this be allowed? right now it is (=> you can re-sideload the same version of your apps)
437 // (remote snaps are stopped before clickInstall gets to run)
438
439- data := "name: afoo\nversion: 1"
440+ data := "name: afoo\nversion: 1\nvendor: foo"
441 yamlPath, err := makeInstalledMockSnap(s.tempdir, data)
442 c.Assert(err, IsNil)
443 c.Assert(makeSnapActive(yamlPath), IsNil)
444@@ -1054,7 +1066,7 @@
445 }
446
447 func (s *SnapTestSuite) TestIgnoresAlreadyInstalledFrameworks(c *C) {
448- data := "name: afoo\nversion: 1\ntype: framework"
449+ data := "name: afoo\nversion: 1\nvendor: foo\ntype: framework"
450 yamlPath, err := makeInstalledMockSnap(s.tempdir, data)
451 c.Assert(err, IsNil)
452 c.Assert(makeSnapActive(yamlPath), IsNil)
453@@ -1067,6 +1079,7 @@
454 func (s *SnapTestSuite) TestDetectsNameClash(c *C) {
455 data := []byte(`name: afoo
456 version: 1.0
457+vendor: foo
458 services:
459 - name: foo
460 binaries:
461@@ -1081,6 +1094,7 @@
462 func (s *SnapTestSuite) TestDetectsMissingFrameworks(c *C) {
463 data := []byte(`name: afoo
464 version: 1.0
465+vendor: foo
466 frameworks:
467 - missing
468 - also-missing
469@@ -1094,6 +1108,7 @@
470 func (s *SnapTestSuite) TestDetectsFrameworksInUse(c *C) {
471 _, err := makeInstalledMockSnap(s.tempdir, `name: foo
472 version: 1.0
473+vendor: foo
474 frameworks:
475 - fmk
476 `)
477@@ -1101,6 +1116,7 @@
478
479 yaml, err := parsePackageYamlData([]byte(`name: fmk
480 version: 1.0
481+vendor: foo
482 type: framework`))
483 c.Assert(err, IsNil)
484 part := &SnapPart{m: yaml}
485@@ -1131,6 +1147,7 @@
486
487 _, err := makeInstalledMockSnap(s.tempdir, `name: foo
488 version: 1.0
489+vendor: foo
490 frameworks:
491 - fmk
492 binaries:
493@@ -1144,13 +1161,13 @@
494 d2 := c.MkDir()
495 dp := filepath.Join("meta", "framework-policy", "apparmor", "policygroups")
496
497- yaml := "name: fmk\ntype: framework\nversion: 1\n"
498+ yaml := "name: fmk\ntype: framework\nversion: 1\nvendor: foo"
499 _, err = makeInstalledMockSnap(d1, yaml)
500 c.Assert(err, IsNil)
501 c.Assert(os.MkdirAll(filepath.Join(d1, dp), 0755), IsNil)
502 c.Assert(ioutil.WriteFile(filepath.Join(d1, dp, "foo"), []byte(""), 0644), IsNil)
503
504- _, err = makeInstalledMockSnap(d2, "name: fmk\ntype: framework\nversion: 2\n")
505+ _, err = makeInstalledMockSnap(d2, "name: fmk\ntype: framework\nversion: 2\nvendor: foo")
506 c.Assert(err, IsNil)
507 c.Assert(os.MkdirAll(filepath.Join(d2, dp), 0755), IsNil)
508 c.Assert(ioutil.WriteFile(filepath.Join(d2, dp, "foo"), []byte("x"), 0644), IsNil)
509@@ -1165,12 +1182,14 @@
510 func (s *SnapTestSuite) TestRemoveChecksFrameworks(c *C) {
511 yamlFile, err := makeInstalledMockSnap(s.tempdir, `name: fmk
512 version: 1.0
513+vendor: foo
514 type: framework`)
515 c.Assert(err, IsNil)
516 yaml, err := parsePackageYamlFile(yamlFile)
517
518 _, err = makeInstalledMockSnap(s.tempdir, `name: foo
519 version: 1.0
520+vendor: foo
521 frameworks:
522 - fmk
523 `)
524@@ -1316,6 +1335,8 @@
525
526 func (s *SnapTestSuite) TestIllegalPackageNameWithOrigin(c *C) {
527 _, err := parsePackageYamlData([]byte(`name: foo.something
528+version: 1.0
529+vendor: foo
530 `))
531
532 c.Assert(err, Equals, ErrPackageNameNotSupported)
533@@ -1323,6 +1344,7 @@
534
535 var hardwareYaml = []byte(`name: oem-foo
536 version: 1.0
537+vendor: someone
538 oem:
539 hardware:
540 assign:
541@@ -1434,6 +1456,36 @@
542 c.Assert(udevName, Equals, "foo")
543 }
544
545+func (s *SnapTestSuite) TestParsePackageYamlDataChecksName(c *C) {
546+ _, err := parsePackageYamlData([]byte(`
547+version: 1.0
548+vendor: Foo Bar <foo@example.com>
549+`))
550+ c.Assert(err, ErrorMatches, "can not parse package.yaml: missing required fields 'name'.*")
551+}
552+
553+func (s *SnapTestSuite) TestParsePackageYamlDataChecksVersion(c *C) {
554+ _, err := parsePackageYamlData([]byte(`
555+name: foo
556+vendor: Foo Bar <foo@example.com>
557+`))
558+ c.Assert(err, ErrorMatches, "can not parse package.yaml: missing required fields 'version'.*")
559+}
560+
561+func (s *SnapTestSuite) TestParsePackageYamlDataChecksVendor(c *C) {
562+ _, err := parsePackageYamlData([]byte(`
563+name: foo
564+version: 1.0
565+`))
566+ c.Assert(err, ErrorMatches, "can not parse package.yaml: missing required fields 'vendor'.*")
567+}
568+
569+func (s *SnapTestSuite) TestParsePackageYamlDataChecksMultiple(c *C) {
570+ _, err := parsePackageYamlData([]byte(`
571+`))
572+ c.Assert(err, ErrorMatches, "can not parse package.yaml: missing required fields 'name, version, vendor'.*")
573+}
574+
575 func (s *SnapTestSuite) TestIntegrateBoring(c *C) {
576 m := &packageYaml{}
577 m.legacyIntegration()

Subscribers

People subscribed via source and target branches