Skip to content

Commit

Permalink
Add changes test to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Sauder committed Jun 19, 2018
1 parent e8df91b commit b61d48c
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 1 deletion.
77 changes: 76 additions & 1 deletion deb/changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,33 @@ import (
"os"
"path/filepath"

"github.com/aptly-dev/aptly/aptly"
"github.com/aptly-dev/aptly/console"
"github.com/aptly-dev/aptly/database"
"github.com/aptly-dev/aptly/files"

. "gopkg.in/check.v1"
)

type ChangesSuite struct {
Dir, Path string
Dir, Path string
Reporter aptly.ResultReporter
db database.Storage
localRepoCollection *LocalRepoCollection
packageCollection *PackageCollection
packagePool aptly.PackagePool
checksumStorage aptly.ChecksumStorage
progress aptly.Progress
}

var _ = Suite(&ChangesSuite{})

func (s *ChangesSuite) SetUpTest(c *C) {
s.Reporter = &aptly.RecordingResultReporter{
Warnings: []string{},
AddedLines: []string{},
RemovedLines: []string{},
}
s.Dir = c.MkDir()
s.Path = filepath.Join(s.Dir, "calamares.changes")

Expand All @@ -22,6 +39,20 @@ func (s *ChangesSuite) SetUpTest(c *C) {

f.WriteString(changesFile)
f.Close()

s.db, _ = database.NewOpenDB(c.MkDir())
s.localRepoCollection = NewLocalRepoCollection(s.db)
s.packageCollection = NewPackageCollection(s.db)

s.checksumStorage = files.NewMockChecksumStorage()
s.packagePool = files.NewPackagePool(s.Dir, false)
s.progress = console.NewProgress()
s.progress.Start()
}

func (s *ChangesSuite) TearDownTest(c *C) {
s.progress.Shutdown()
s.db.Close()
}

func (s *ChangesSuite) TestParseAndVerify(c *C) {
Expand All @@ -44,6 +75,50 @@ func (s *ChangesSuite) TestParseAndVerify(c *C) {
c.Check(changes.Binary, DeepEquals, []string{"calamares", "calamares-dbg"})
}

func (s *ChangesSuite) TestCollectChangesFiles(c *C) {
changesFiles, failedFiles := CollectChangesFiles([]string{"testdata/changes"}, s.Reporter)

c.Check(failedFiles, HasLen, 0)
c.Check(changesFiles, DeepEquals, []string{
"testdata/changes/hardlink_0.2.1-invalidfiles_amd64.changes",
"testdata/changes/hardlink_0.2.1-invalidsig_amd64.changes",
"testdata/changes/hardlink_0.2.1_amd64.changes",
})
}

func (s *ChangesSuite) TestImportChangesFiles(c *C) {
repo := NewLocalRepo("test", "Test Comment")
c.Assert(s.localRepoCollection.Add(repo), IsNil)

processedFiles, failedFiles, err := ImportChangesFiles(
[]string{
"testdata/changes/hardlink_0.2.1_amd64.changes",
"testdata/changes/hardlink_0.2.1-invalidsig_amd64.changes",
"testdata/changes/hardlink_0.2.1-invalidfiles_amd64.changes",
"testdata/changes/notexistent.changes",
},
s.Reporter, true, true, false, true, &NullVerifier{},
"test", s.progress, s.localRepoCollection, s.packageCollection, s.packagePool, s.checksumStorage,
nil, nil)
c.Assert(err, IsNil)
c.Check(failedFiles, DeepEquals, []string{
"testdata/changes/hardlink_0.2.1-invalidsig_amd64.changes",
"testdata/changes/hardlink_0.2.1-invalidfiles_amd64.changes",
"testdata/changes/notexistent.changes",
})
c.Check(processedFiles, HasLen, 4)
}

func (s *ChangesSuite) TestPrepare(c *C) {
changes, err := NewChanges("testdata/changes/hardlink_0.2.1_amd64.changes")
c.Assert(err, IsNil)
err = changes.Prepare()
c.Assert(err, IsNil)

_, err = os.Stat(filepath.Join(changes.TempDir, "hardlink_0.2.1_amd64.changes"))
c.Check(err, IsNil)
}

func (s *ChangesSuite) TestPackageQuery(c *C) {
changes, err := NewChanges(s.Path)
c.Assert(err, IsNil)
Expand Down
22 changes: 22 additions & 0 deletions deb/testdata/changes/hardlink_0.2.1-invalidfiles_amd64.changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Format: 1.8
Date: Sat, 12 May 2014 12:57:02 +0200
Source: hardlink
Binary: hardlink
Architecture: source amd64
Version: 0.2.1
Distribution: unstable
Urgency: low
Maintainer: Julian Andres Klode <jak@debian.org>
Changed-By: Aptly Tester (don't use it) <test@aptly.info>
Description:
hardlink - Hardlinks multiple copies of the same file
Changes:
hardlink (0.2.1) unstable; urgency=low
.
* Update just to try it out :)
Checksums-Sha1:
ff306b8f923653b78e00c45ebbc6c1c734859cdf 949 invalidhardlink_0.2.1.dsc
Checksums-Sha256:
c0d7458aa2ca3886cd6885f395a289efbc9a396e6765cbbca45f51fde859ea70 949 invalidhardlink_0.2.1.dsc
Files:
4efce26825af5842f43961096dd890b3 949 utils optional invalidhardlink_0.2.1.dsc
39 changes: 39 additions & 0 deletions deb/testdata/changes/hardlink_0.2.1-invalidsig_amd64.changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.8
Date: Sat, 12 May 2014 12:57:02 +0200
Source: hardlink
Binary: hardlink
Architecture: source amd64
Version: 0.2.1
Distribution: unstable
Urgency: low
Maintainer: Julian Andres Klode <jak@debian.org>
Changed-By: Aptly Tester (don't use it) <test@aptly.info>
Description:
hardlink - Hardlinks multiple copies of the same file
Changes:
hardlink (0.2.1) unstable; urgency=low
.
* Update just to try it out :)
Checksums-Sha1:
ff306b8f923653b78e00c45ebbc6c1c734859cdf 949 hardlink_0.2.1.dsc
6e95b8cba450343ab4dc01902e521f29fbd87ac2 12516 hardlink_0.2.1.tar.gz
1ac0e962854dff46f14fa7943746660d3cad1679 12468 hardlink_0.2.1_amd64.deb
Checksums-Sha256:
c0d7458aa2ca3886cd6885f395a289efbc9a396e6765cbbca45f51fde859ea70 949 hardlink_0.2.1.dsc
4df0adce005526a1f0e1b38171ddb1f017faae9205f5b1c6dfb0fb4207767271 12516 hardlink_0.2.1.tar.gz
668399580590bf1ffcd9eb161b6e574751e15f71820c6e08245dac7c5111a0ee 12468 hardlink_0.2.1_amd64.deb
Files:
4efce26825af5842f43961096dd890b3 949 utils optional hardlink_0.2.1.dsc
8e2caa4d82f228bac08dc9a38bc6edb3 12516 utils optional hardlink_0.2.1.tar.gz
2081e20b36c47f82811c25841cc0e41b 12468 utils optional hardlink_0.2.1_amd64.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlUFwywACgkQIdu4nBbbPm1DLACgwW4V8qLQC/QHC/7+t3Iq47Ez
eesAn3ZYLQvLYRw3wPTKVAPI+AW6Fjxi
=hRBo
-----END PGP SIGNATURE-----
19 changes: 19 additions & 0 deletions deb/testdata/changes/hardlink_0.2.1.dsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Format: 1.0
Source: hardlink
Binary: hardlink
Architecture: any
Version: 0.2.1
Maintainer: Julian Andres Klode <jak@debian.org>
Homepage: http://jak-linux.org/projects/hardlink/
Standards-Version: 3.9.3
Vcs-Browser: http://git.debian.org/?p=users/jak/hardlink.git;a=summary
Vcs-Git: git://git.debian.org/git/users/jak/hardlink.git
Build-Depends: debhelper (>= 9), pkg-config, libpcre3-dev
Package-List:
hardlink deb utils optional
Checksums-Sha1:
6e95b8cba450343ab4dc01902e521f29fbd87ac2 12516 hardlink_0.2.1.tar.gz
Checksums-Sha256:
4df0adce005526a1f0e1b38171ddb1f017faae9205f5b1c6dfb0fb4207767271 12516 hardlink_0.2.1.tar.gz
Files:
8e2caa4d82f228bac08dc9a38bc6edb3 12516 hardlink_0.2.1.tar.gz
Binary file added deb/testdata/changes/hardlink_0.2.1.tar.gz
Binary file not shown.
28 changes: 28 additions & 0 deletions deb/testdata/changes/hardlink_0.2.1_amd64.changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Format: 1.8
Date: Sat, 12 May 2014 12:57:02 +0200
Source: hardlink
Binary: hardlink
Architecture: source amd64
Version: 0.2.1
Distribution: unstable
Urgency: low
Maintainer: Julian Andres Klode <jak@debian.org>
Changed-By: Aptly Tester (don't use it) <test@aptly.info>
Description:
hardlink - Hardlinks multiple copies of the same file
Changes:
hardlink (0.2.1) unstable; urgency=low
.
* Update just to try it out :)
Checksums-Sha1:
d20d6820bfccf5e3a5b120eedabba96e71da60ff 703 hardlink_0.2.1.dsc
6e95b8cba450343ab4dc01902e521f29fbd87ac2 12516 hardlink_0.2.1.tar.gz
1ac0e962854dff46f14fa7943746660d3cad1679 12468 hardlink_0.2.1_amd64.deb
Checksums-Sha256:
19d08cfadd58aee05fd06aca261a873bafeb55cac58bf4916cc070f5821803e7 703 hardlink_0.2.1.dsc
4df0adce005526a1f0e1b38171ddb1f017faae9205f5b1c6dfb0fb4207767271 12516 hardlink_0.2.1.tar.gz
668399580590bf1ffcd9eb161b6e574751e15f71820c6e08245dac7c5111a0ee 12468 hardlink_0.2.1_amd64.deb
Files:
b75fe0616f24deb28a3017c1dbae219a 703 utils optional hardlink_0.2.1.dsc
8e2caa4d82f228bac08dc9a38bc6edb3 12516 utils optional hardlink_0.2.1.tar.gz
2081e20b36c47f82811c25841cc0e41b 12468 utils optional hardlink_0.2.1_amd64.deb
Binary file added deb/testdata/changes/hardlink_0.2.1_amd64.deb
Binary file not shown.

0 comments on commit b61d48c

Please sign in to comment.