Skip to content

Commit

Permalink
fix(cmd): stats command works with an FSI directory
Browse files Browse the repository at this point in the history
closes #1186
  • Loading branch information
b5 committed Apr 7, 2020
1 parent 9e840bf commit f6696c1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
6 changes: 0 additions & 6 deletions cmd/stats.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cmd

import (
"fmt"

"github.com/qri-io/ioes"
"github.com/qri-io/qri/lib"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -53,10 +51,6 @@ func (o *StatsOptions) Complete(f Factory, args []string) (err error) {
return
}

if len(args) < 1 {
return fmt.Errorf("need a dataset reference, eg: me/dataset_name")
}

o.Refs, err = GetCurrentRefSelect(f, args, 1, nil)
if err != nil {
return err
Expand Down
28 changes: 27 additions & 1 deletion cmd/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cmd

import (
"testing"

"github.com/google/go-cmp/cmp"
)

func TestStatsComplete(t *testing.T) {
Expand All @@ -19,7 +21,7 @@ func TestStatsComplete(t *testing.T) {
args []string
err string
}{
{"no args", []string{}, "need a dataset reference, eg: me/dataset_name"},
{"no args", []string{}, "repo: empty dataset reference"},
}

for i, c := range badCases {
Expand Down Expand Up @@ -135,3 +137,27 @@ func TestStatsRun(t *testing.T) {
}
}
}

func TestStatsFSI(t *testing.T) {
run := NewFSITestRunner(t, "qri_test_stats_fsi")
defer run.Delete()

run.CreateAndChdirToWorkDir("stats_fsi")

// Init as a linked directory.
run.MustExec(t, "qri init --name move_dir --format csv")
// Save the new dataset.
run.MustExec(t, "qri save")

output := run.MustExecCombinedOutErr(t, "qri stats")

expect := `for linked dataset [test_peer/move_dir]
[{"count":2,"maxLength":4,"minLength":3,"type":"string","unique":2},{"count":2,"maxLength":4,"minLength":3,"type":"string","unique":2},{"count":2,"histogram":{"bins":[3,3.4,3.8,4.2,4.6,5,5.4,5.800000000000001,6.2,6.6,7],"frequencies":[1,0,0,0,0,0,0,1,0,0]},"max":6,"mean":4.5,"median":4.5,"min":3,"type":"numeric"}]
`

if diff := cmp.Diff(expect, output); diff != "" {
t.Errorf("output mismatch (-want +got):\n%s", diff)
}
}

0 comments on commit f6696c1

Please sign in to comment.