Skip to content

Commit

Permalink
Remove unused FSStats code
Browse files Browse the repository at this point in the history
  • Loading branch information
arunvelsriram committed May 15, 2021
1 parent 91a5370 commit bfda18c
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 97 deletions.
14 changes: 0 additions & 14 deletions pkg/internal/mocks/sftp_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions pkg/model/model.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package model

type FSStat struct {
Path string
FreeSpace float64
TotalSpace float64
}

type FSStats []FSStat

type ObjectStat struct {
Path string
ObjectCount float64
Expand Down
23 changes: 0 additions & 23 deletions pkg/service/sftp_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

type (
SFTPService interface {
FSStats() model.FSStats
ObjectStats() model.ObjectStats
}

Expand All @@ -19,28 +18,6 @@ type (
}
)

func (s sftpService) FSStats() model.FSStats {
paths := s.config.GetSFTPPaths()
fsStats := make([]model.FSStat, 0)
for _, path := range paths {
statVFS, err := s.sftpClient.StatVFS(path)
if err != nil {
log.WithFields(log.Fields{
"event": "collecting object stats",
"path": path,
}).Error(err)
continue
}
fsStat := model.FSStat{
Path: path,
TotalSpace: float64(statVFS.TotalSpace()),
FreeSpace: float64(statVFS.FreeSpace()),
}
fsStats = append(fsStats, fsStat)
}
return fsStats
}

func (s sftpService) ObjectStats() model.ObjectStats {
paths := s.config.GetSFTPPaths()
objectStats := make([]model.ObjectStat, 0)
Expand Down
52 changes: 0 additions & 52 deletions pkg/service/sftp_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/arunvelsriram/sftp-exporter/pkg/service"
"github.com/golang/mock/gomock"
"github.com/kr/fs"
"github.com/pkg/sftp"
"github.com/spf13/afero"
"github.com/stretchr/testify/suite"
)
Expand Down Expand Up @@ -60,57 +59,6 @@ func (s *SFTPServiceSuite) TearDownTest() {
s.ctrl.Finish()
}

func (s *SFTPServiceSuite) TestSFTPServiceFSStats() {
s.config.EXPECT().GetSFTPPaths().Return([]string{"/path0", "/path1"})
s.sftpClient.EXPECT().StatVFS("/path0").Return(&sftp.StatVFS{
Frsize: 2,
Blocks: 100,
Bfree: 50,
}, nil)
s.sftpClient.EXPECT().StatVFS("/path1").Return(&sftp.StatVFS{
Frsize: 5,
Blocks: 1000,
Bfree: 100,
}, nil)

fsStats := s.service.FSStats()

expected := model.FSStats([]model.FSStat{
{
Path: "/path0",
TotalSpace: 200.00,
FreeSpace: 100.00,
},
{
Path: "/path1",
TotalSpace: 5000.00,
FreeSpace: 500.00,
},
})
s.Equal(expected, fsStats)
}

func (s *SFTPServiceSuite) TestSFTPServiceFSStatsShouldSkipAndContinueInCaseOfError() {
s.config.EXPECT().GetSFTPPaths().Return([]string{"/path0", "/path1"})
s.sftpClient.EXPECT().StatVFS("/path0").Return(&sftp.StatVFS{
Frsize: 2,
Blocks: 100,
Bfree: 50,
}, nil)
s.sftpClient.EXPECT().StatVFS("/path1").Return(nil, fmt.Errorf("failed to get FS stats"))

fsStats := s.service.FSStats()

expected := model.FSStats([]model.FSStat{
{
Path: "/path0",
TotalSpace: 200.00,
FreeSpace: 100.00,
},
})
s.Equal(expected, fsStats)
}

func (s *SFTPServiceSuite) TestSFTPServiceObjectStats() {
memFs := afero.NewMemMapFs()
_ = memFs.MkdirAll("/path0/1", 0755)
Expand Down

0 comments on commit bfda18c

Please sign in to comment.