Skip to content

Commit 7e8f254

Browse files
committed
fix unit tests
1 parent c58a634 commit 7e8f254

5 files changed

Lines changed: 14 additions & 4 deletions

File tree

deb/local.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ func (repo *LocalRepo) String() string {
4848

4949
// NumPackages return number of packages in local repo
5050
func (repo *LocalRepo) NumPackages() int {
51+
if repo.packageRefs == nil {
52+
return 0
53+
}
5154
return repo.packageRefs.Len()
5255
}
5356

deb/remote.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ func (repo *RemoteRepo) IsFlat() bool {
164164

165165
// NumPackages return number of packages retrieved from remote repo
166166
func (repo *RemoteRepo) NumPackages() int {
167+
if repo.packageRefs == nil {
168+
return 0
169+
}
167170
return repo.packageRefs.Len()
168171
}
169172

deb/snapshot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type Snapshot struct {
4545

4646
// NewSnapshotFromRepository creates snapshot from current state of repository
4747
func NewSnapshotFromRepository(name string, repo *RemoteRepo) (*Snapshot, error) {
48-
if repo.packageRefs.Len() == 0 {
48+
if repo.packageRefs == nil || repo.packageRefs.Len() == 0 {
4949
return nil, errors.New("mirror not updated")
5050
}
5151

utils/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import (
1010

1111
// DirIsAccessible verifies that directory exists and is accessible
1212
func DirIsAccessible(filename string) error {
13-
_, err := os.Stat(filename)
13+
fileStat, err := os.Stat(filename)
1414
if err != nil {
1515
if !os.IsNotExist(err) {
1616
return fmt.Errorf("error checking directory '%s': %s", filename, err)
1717
}
1818
} else {
19-
if unix.Access(filename, unix.W_OK) != nil {
19+
if fileStat.Mode().Perm() == 0000 || unix.Access(filename, unix.W_OK) != nil {
2020
return fmt.Errorf("'%s' is inaccessible, check access rights", filename)
2121
}
2222
}

utils/utils_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@ func (s *UtilsSuite) TestDirIsAccessibleNotExist(c *C) {
3232
}
3333

3434
func (s *UtilsSuite) TestDirIsAccessibleNotAccessible(c *C) {
35-
c.Check(DirIsAccessible(s.tempfile.Name()).Error(), Equals, fmt.Errorf("'%s' is inaccessible, check access rights", s.tempfile.Name()).Error())
35+
accessible := DirIsAccessible(s.tempfile.Name())
36+
if accessible == nil {
37+
c.Fatalf("Test dir should not be accessible: %s", s.tempfile.Name())
38+
}
39+
c.Check(accessible.Error(), Equals, fmt.Errorf("'%s' is inaccessible, check access rights", s.tempfile.Name()).Error())
3640
}

0 commit comments

Comments
 (0)