~snappy-dev/snappy/15.04

« back to all changes in this revision

Viewing changes to snappy/build_test.go

  • Committer: Snappy Tarmac
  • Author(s): John R. Lenton, Michael Vogt, Leo Arias, Launchpad Translations on behalf of snappy-dev, Federico Gimenez, Ricardo Mendoza
  • Date: 2015-10-13 06:03:57 UTC
  • mfrom: (711.1.54 snappy)
  • Revision ID: snappy_tarmac-20151013060357-rf1cz6y7190uzzlr
Merge trunk fixes. by snappy-dev approved by chipaca

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
package snappy
21
21
 
22
22
import (
 
23
        "fmt"
23
24
        "io/ioutil"
24
25
        "os"
25
26
        "os/exec"
26
27
        "path/filepath"
 
28
        "regexp"
27
29
        "strings"
28
30
        "syscall"
29
31
 
102
104
  apparmor-profile: meta/hello.apparmor
103
105
`)
104
106
 
105
 
        resultSnap, err := Build(sourceDir, "")
 
107
        resultSnap, err := BuildLegacySnap(sourceDir, "")
106
108
        c.Assert(err, IsNil)
107
109
        defer os.Remove(resultSnap)
108
110
 
138
140
        readFiles, err := exec.Command("dpkg-deb", "-c", "hello_1.0.1_multi.snap").Output()
139
141
        c.Assert(err, IsNil)
140
142
        for _, needle := range []string{"./meta/package.yaml", "./meta/readme.md", "./bin/hello-world", "./symlink -> bin/hello-world"} {
141
 
                c.Assert(strings.Contains(string(readFiles), needle), Equals, true)
 
143
                expr := fmt.Sprintf(`(?ms).*%s.*`, regexp.QuoteMeta(needle))
 
144
                c.Assert(string(readFiles), Matches, expr)
142
145
        }
143
146
}
144
147
 
152
155
 - name: bin/hello-world
153
156
`)
154
157
 
155
 
        resultSnap, err := Build(sourceDir, "")
 
158
        resultSnap, err := BuildLegacySnap(sourceDir, "")
156
159
        c.Assert(err, IsNil)
157
160
        defer os.Remove(resultSnap)
158
161
 
194
197
   start: bin/hello-world
195
198
`)
196
199
 
197
 
        resultSnap, err := Build(sourceDir, "")
 
200
        resultSnap, err := BuildLegacySnap(sourceDir, "")
198
201
        c.Assert(err, IsNil)
199
202
        defer os.Remove(resultSnap)
200
203
 
236
239
        err := ioutil.WriteFile(filepath.Join(hooksDir, "config"), []byte(""), 0755)
237
240
        c.Assert(err, IsNil)
238
241
 
239
 
        resultSnap, err := Build(sourceDir, "")
 
242
        resultSnap, err := BuildLegacySnap(sourceDir, "")
240
243
        c.Assert(err, IsNil)
241
244
        defer os.Remove(resultSnap)
242
245
 
265
268
func (s *SnapTestSuite) TestBuildNoManifestFails(c *C) {
266
269
        sourceDir := makeExampleSnapSourceDir(c, "")
267
270
        c.Assert(os.Remove(filepath.Join(sourceDir, "meta", "package.yaml")), IsNil)
268
 
        _, err := Build(sourceDir, "")
 
271
        _, err := BuildLegacySnap(sourceDir, "")
269
272
        c.Assert(err, NotNil) // XXX maybe make the error more explicit
270
273
}
271
274
 
279
282
  apparmor-profile: meta/hello.apparmor
280
283
explicit-license-agreement: Y
281
284
`)
282
 
        _, err := Build(sourceDir, "")
 
285
        _, err := BuildLegacySnap(sourceDir, "")
283
286
        c.Assert(err, NotNil) // XXX maybe make the error more explicit
284
287
}
285
288
 
295
298
`)
296
299
        lic := filepath.Join(sourceDir, "meta", "license.txt")
297
300
        ioutil.WriteFile(lic, []byte("\n"), 0755)
298
 
        _, err := Build(sourceDir, "")
 
301
        _, err := BuildLegacySnap(sourceDir, "")
299
302
        c.Assert(err, Equals, ErrLicenseBlank)
300
303
}
301
304
 
341
344
        c.Check(string(out), Matches, `(?m)Only in \S+: foo~`)
342
345
}
343
346
 
 
347
func (s *SnapTestSuite) TestCopyExcludesTopLevelDEBIAN(c *C) {
 
348
        sourceDir := makeExampleSnapSourceDir(c, "name: hello")
 
349
        target := c.MkDir()
 
350
        // add a toplevel DEBIAN
 
351
        c.Assert(os.MkdirAll(filepath.Join(sourceDir, "DEBIAN", "foo"), 0755), IsNil)
 
352
        // and a non-toplevel DEBIAN
 
353
        c.Assert(os.MkdirAll(filepath.Join(sourceDir, "bar", "DEBIAN", "baz"), 0755), IsNil)
 
354
        c.Assert(copyToBuildDir(sourceDir, target), IsNil)
 
355
        cmd := exec.Command("diff", "-qr", sourceDir, target)
 
356
        cmd.Env = append(cmd.Env, "LANG=C")
 
357
        out, err := cmd.Output()
 
358
        c.Check(err, NotNil)
 
359
        c.Check(string(out), Matches, `(?m)Only in \S+: DEBIAN`)
 
360
        // but *only one* DEBIAN is skipped
 
361
        c.Check(strings.Count(string(out), "Only in"), Equals, 1)
 
362
}
 
363
 
344
364
func (s *SnapTestSuite) TestCopyExcludesWholeDirs(c *C) {
345
365
        sourceDir := makeExampleSnapSourceDir(c, "name: hello")
346
366
        target := c.MkDir()
390
410
 
391
411
        outputDir := filepath.Join(c.MkDir(), "output")
392
412
        snapOutput := filepath.Join(outputDir, "hello_1.0.1_multi.snap")
393
 
        resultSnap, err := Build(sourceDir, outputDir)
 
413
        resultSnap, err := BuildLegacySnap(sourceDir, outputDir)
394
414
        c.Assert(err, IsNil)
395
415
 
396
416
        // check that there is result
425
445
        readFiles, err := exec.Command("dpkg-deb", "-c", snapOutput).Output()
426
446
        c.Assert(err, IsNil)
427
447
        for _, needle := range []string{"./meta/package.yaml", "./meta/readme.md", "./bin/hello-world"} {
428
 
                c.Assert(strings.Contains(string(readFiles), needle), Equals, true)
 
448
                expr := fmt.Sprintf(`(?ms).*%s.*`, regexp.QuoteMeta(needle))
 
449
                c.Assert(string(readFiles), Matches, expr)
429
450
        }
430
451
}
431
452
 
438
459
binaries:
439
460
 - name: foo
440
461
`)
441
 
        _, err := Build(sourceDir, "")
 
462
        _, err := BuildLegacySnap(sourceDir, "")
442
463
        c.Assert(err, ErrorMatches, ".*binary and service both called foo.*")
443
464
}
444
465
 
469
490
vendor: Foo <foo@example.com>
470
491
`)
471
492
 
472
 
        resultSnap, err := Build(sourceDir, "")
 
493
        resultSnap, err := BuildLegacySnap(sourceDir, "")
473
494
        c.Assert(err, IsNil)
474
495
        defer os.Remove(resultSnap)
475
496
 
490
511
        err := syscall.Mkfifo(filepath.Join(sourceDir, "fifo"), 0644)
491
512
        c.Assert(err, IsNil)
492
513
 
493
 
        _, err = Build(sourceDir, "")
 
514
        _, err = BuildLegacySnap(sourceDir, "")
494
515
        c.Assert(err, ErrorMatches, "can not handle type of file .*")
495
516
}
 
517
 
 
518
func (s *SnapTestSuite) TestBuildSnapfsSimple(c *C) {
 
519
        sourceDir := makeExampleSnapSourceDir(c, `name: hello
 
520
version: 1.0.1
 
521
vendor: Foo <foo@example.com>
 
522
architecture: ["i386", "amd64"]
 
523
integration:
 
524
 app:
 
525
  apparmor-profile: meta/hello.apparmor
 
526
`)
 
527
 
 
528
        resultSnap, err := BuildSnapfsSnap(sourceDir, "")
 
529
        c.Assert(err, IsNil)
 
530
        defer os.Remove(resultSnap)
 
531
 
 
532
        // check that there is result
 
533
        _, err = os.Stat(resultSnap)
 
534
        c.Assert(err, IsNil)
 
535
        c.Assert(resultSnap, Equals, "hello_1.0.1_multi.snap")
 
536
 
 
537
        // check that the content looks sane
 
538
        output, err := exec.Command("unsquashfs", "-ll", "hello_1.0.1_multi.snap").CombinedOutput()
 
539
        c.Assert(err, IsNil)
 
540
        for _, needle := range []string{
 
541
                "meta/package.yaml",
 
542
                "meta/readme.md",
 
543
                "bin/hello-world",
 
544
                "symlink -> bin/hello-world",
 
545
        } {
 
546
                expr := fmt.Sprintf(`(?ms).*%s.*`, regexp.QuoteMeta(needle))
 
547
                c.Assert(string(output), Matches, expr)
 
548
        }
 
549
}