From f6696c13fa8e57945e32d2e40e11e2bcb35b74ca Mon Sep 17 00:00:00 2001 From: b5 Date: Mon, 6 Apr 2020 22:24:05 -0400 Subject: [PATCH] fix(cmd): stats command works with an FSI directory closes #1186 --- cmd/stats.go | 6 ------ cmd/stats_test.go | 28 +++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/cmd/stats.go b/cmd/stats.go index e341bbfee..197c75ac9 100644 --- a/cmd/stats.go +++ b/cmd/stats.go @@ -1,8 +1,6 @@ package cmd import ( - "fmt" - "github.com/qri-io/ioes" "github.com/qri-io/qri/lib" "github.com/spf13/cobra" @@ -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 diff --git a/cmd/stats_test.go b/cmd/stats_test.go index b3d26da0f..4b999b6c2 100644 --- a/cmd/stats_test.go +++ b/cmd/stats_test.go @@ -2,6 +2,8 @@ package cmd import ( "testing" + + "github.com/google/go-cmp/cmp" ) func TestStatsComplete(t *testing.T) { @@ -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 { @@ -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) + } +}