Skip to content

Commit

Permalink
Sharness: Add tests for ipfs repo stat --size-only
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
  • Loading branch information
hsanjuan committed May 9, 2018
1 parent 31ebc6a commit 6a47abb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Version string The repo version.
statF = corerepo.RepoSize
}

stat, err := statF(n, req.Context)
stat, err := statF(req.Context, n)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
Expand Down
9 changes: 6 additions & 3 deletions core/corerepo/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
)

// Stat wraps information about the objects stored on disk.
type Stat struct {
RepoSize uint64 // size in bytes
StorageMax uint64 // size in bytes
Expand All @@ -23,8 +24,9 @@ type Stat struct {
// NoLimit represents the value for unlimited storage
const NoLimit uint64 = math.MaxUint64

func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
sizeStat, err := RepoSize(n, ctx)
// RepoStat returns a *Stat object with all the fields set.
func RepoStat(ctx context.Context, n *core.IpfsNode) (*Stat, error) {
sizeStat, err := RepoSize(ctx, n)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -53,7 +55,8 @@ func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
}, nil
}

func RepoSize(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
// RepoSize returns a *Stat object with the RepoSize and StorageMax fields set.
func RepoSize(ctx context.Context, n *core.IpfsNode) (*Stat, error) {
r := n.Repo

cfg, err := r.Config()
Expand Down
12 changes: 12 additions & 0 deletions test/sharness/t0080-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@ test_expect_success "repo stats are updated correctly" '
test $(get_field_num "RepoSize" repo-stats-2) -ge $(get_field_num "RepoSize" repo-stats)
'

test_expect_success "'ipfs repo stat --size-only' succeeds" '
ipfs repo stat --size-only > repo-stats-size-only
'

test_expect_success "repo stats came out correct for --size-only" '
grep "RepoSize" repo-stats-size-only &&
grep "StorageMax" repo-stats-size-only &&
grep -v "RepoPath" repo-stats-size-only &&
grep -v "NumObjects" repo-stats-size-only &&
grep -v "Version" repo-stats-size-only &&
'

test_expect_success "'ipfs repo version' succeeds" '
ipfs repo version > repo-version
'
Expand Down

0 comments on commit 6a47abb

Please sign in to comment.