Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
neolynx committed Jun 17, 2024
1 parent c58a634 commit 7e8f254
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions deb/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func (repo *LocalRepo) String() string {

// NumPackages return number of packages in local repo
func (repo *LocalRepo) NumPackages() int {
if repo.packageRefs == nil {
return 0
}
return repo.packageRefs.Len()
}

Expand Down
3 changes: 3 additions & 0 deletions deb/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ func (repo *RemoteRepo) IsFlat() bool {

// NumPackages return number of packages retrieved from remote repo
func (repo *RemoteRepo) NumPackages() int {
if repo.packageRefs == nil {
return 0
}
return repo.packageRefs.Len()
}

Expand Down
2 changes: 1 addition & 1 deletion deb/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Snapshot struct {

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

Expand Down
4 changes: 2 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (

// DirIsAccessible verifies that directory exists and is accessible
func DirIsAccessible(filename string) error {
_, err := os.Stat(filename)
fileStat, err := os.Stat(filename)
if err != nil {
if !os.IsNotExist(err) {
return fmt.Errorf("error checking directory '%s': %s", filename, err)
}
} else {
if unix.Access(filename, unix.W_OK) != nil {
if fileStat.Mode().Perm() == 0000 || unix.Access(filename, unix.W_OK) != nil {
return fmt.Errorf("'%s' is inaccessible, check access rights", filename)
}
}
Expand Down
6 changes: 5 additions & 1 deletion utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ func (s *UtilsSuite) TestDirIsAccessibleNotExist(c *C) {
}

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

0 comments on commit 7e8f254

Please sign in to comment.