From 73e63eccfb6b2c7ec05953f6084451ab90e8344a Mon Sep 17 00:00:00 2001 From: raulb Date: Wed, 10 Feb 2021 16:55:46 +0100 Subject: [PATCH 1/3] Fix fmt --- cmd/completion.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/completion.go b/cmd/completion.go index 8b88b413b..08ae1e410 100644 --- a/cmd/completion.go +++ b/cmd/completion.go @@ -1,8 +1,8 @@ package cmd import ( - "os" "github.com/spf13/cobra" + "os" ) // completionCmd represents the completion command From 46367c38c90e9738c6a7ab6ebf534c5ec37a08a1 Mon Sep 17 00:00:00 2001 From: raulb Date: Wed, 10 Feb 2021 16:55:57 +0100 Subject: [PATCH 2/3] Add `make test` --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 5c7904a4a..fc0ba142f 100644 --- a/Makefile +++ b/Makefile @@ -12,3 +12,7 @@ PRIVATE_REPOS = github.com/meroxa/meroxa-go .PHONY: gomod gomod: GOPRIVATE=$(PRIVATE_REPOS) go mod tidy && go mod vendor + +.PHONY: test +test: + go test -v ${GO_TEST_FLAGS} -count=1 ./... \ No newline at end of file From f888a8e125c93e0bf64097cd5287f75f11c8fd9d Mon Sep 17 00:00:00 2001 From: raulb Date: Wed, 10 Feb 2021 16:56:26 +0100 Subject: [PATCH 3/3] =?UTF-8?q?feat(cli):=20Don=E2=80=99t=20show=20headers?= =?UTF-8?q?=20when=20output=20is=20empty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/display.go | 150 +++++++++++++++++++++----------------------- cmd/display_test.go | 30 ++++++++- 2 files changed, 102 insertions(+), 78 deletions(-) diff --git a/cmd/display.go b/cmd/display.go index 1ee661944..b47f31ae4 100644 --- a/cmd/display.go +++ b/cmd/display.go @@ -32,84 +32,78 @@ func prettyPrint(section string, data interface{}) { } func printResourcesTable(resources []*meroxa.Resource) { - table := simpletable.New() + if len(resources) != 0 { + table := simpletable.New() + table.Header = &simpletable.Header{ + Cells: []*simpletable.Cell{ + {Align: simpletable.AlignCenter, Text: "ID"}, + {Align: simpletable.AlignCenter, Text: "TYPE"}, + {Align: simpletable.AlignCenter, Text: "NAME"}, + {Align: simpletable.AlignCenter, Text: "URL"}, + }, + } - table.Header = &simpletable.Header{ - Cells: []*simpletable.Cell{ - {Align: simpletable.AlignCenter, Text: "ID"}, - {Align: simpletable.AlignCenter, Text: "TYPE"}, - {Align: simpletable.AlignCenter, Text: "NAME"}, - {Align: simpletable.AlignCenter, Text: "URL"}, - }, - } + for _, res := range resources { + r := []*simpletable.Cell{ + {Align: simpletable.AlignRight, Text: fmt.Sprintf("%d", res.ID)}, + {Text: res.Kind}, + {Text: res.Name}, + {Text: res.URL}, + } - for _, res := range resources { - r := []*simpletable.Cell{ - {Align: simpletable.AlignRight, Text: fmt.Sprintf("%d", res.ID)}, - {Text: res.Kind}, - {Text: res.Name}, - {Text: res.URL}, + table.Body.Cells = append(table.Body.Cells, r) } - - table.Body.Cells = append(table.Body.Cells, r) + table.SetStyle(simpletable.StyleCompact) + fmt.Println(table.String()) } - table.SetStyle(simpletable.StyleCompact) - fmt.Println(table.String()) -} - -func appendCell(cells []*simpletable.Cell, text string) []*simpletable.Cell { - cells = append(cells, &simpletable.Cell{ - Align: simpletable.AlignCenter, - Text: text, - }) - return cells } func printConnectorsTable(connectors []*meroxa.Connector) { - table := simpletable.New() - - table.Header = &simpletable.Header{ - Cells: []*simpletable.Cell{ - {Align: simpletable.AlignCenter, Text: "ID"}, - {Align: simpletable.AlignCenter, Text: "TYPE"}, - {Align: simpletable.AlignCenter, Text: "NAME"}, - {Align: simpletable.AlignCenter, Text: "STREAMS"}, - {Align: simpletable.AlignCenter, Text: "STATE"}, - }, - } + if len(connectors) != 0 { + table := simpletable.New() + table.Header = &simpletable.Header{ + Cells: []*simpletable.Cell{ + {Align: simpletable.AlignCenter, Text: "ID"}, + {Align: simpletable.AlignCenter, Text: "TYPE"}, + {Align: simpletable.AlignCenter, Text: "NAME"}, + {Align: simpletable.AlignCenter, Text: "STREAMS"}, + {Align: simpletable.AlignCenter, Text: "STATE"}, + }, + } - for _, conn := range connectors { - var streamStr string + for _, conn := range connectors { + var streamStr string - if streamInput, ok := conn.Streams["input"]; ok { - streamStr += "input:\n" + if streamInput, ok := conn.Streams["input"]; ok { + streamStr += "input:\n" - streamInterface := streamInput.([]interface{}) - for _, v := range streamInterface { - streamStr += fmt.Sprintf("%v\n", v) + streamInterface := streamInput.([]interface{}) + for _, v := range streamInterface { + streamStr += fmt.Sprintf("%v\n", v) + } } - } - if streamOutput, ok := conn.Streams["output"]; ok { - streamStr += "output:\n" + if streamOutput, ok := conn.Streams["output"]; ok { + streamStr += "output:\n" - streamInterface := streamOutput.([]interface{}) - for _, v := range streamInterface { - streamStr += fmt.Sprintf("%v\n", v) + streamInterface := streamOutput.([]interface{}) + for _, v := range streamInterface { + streamStr += fmt.Sprintf("%v\n", v) + } + } + r := []*simpletable.Cell{ + {Align: simpletable.AlignRight, Text: fmt.Sprintf("%d", conn.ID)}, + {Text: conn.Kind}, + {Text: conn.Name}, + {Text: streamStr}, + {Text: conn.State}, } - } - r := []*simpletable.Cell{ - {Align: simpletable.AlignRight, Text: fmt.Sprintf("%d", conn.ID)}, - {Text: conn.Kind}, - {Text: conn.Name}, - {Text: streamStr}, - {Text: conn.State}, - } - table.Body.Cells = append(table.Body.Cells, r) + table.Body.Cells = append(table.Body.Cells, r) + } + table.SetStyle(simpletable.StyleCompact) + fmt.Println(table.String()) } - table.SetStyle(simpletable.StyleCompact) - fmt.Println(table.String()) } func printResourceTypesTable(types []string) { @@ -133,23 +127,25 @@ func printResourceTypesTable(types []string) { } func printPipelinesTable(pipelines []*meroxa.Pipeline) { - table := simpletable.New() + if len(pipelines) != 0 { + table := simpletable.New() + + table.Header = &simpletable.Header{ + Cells: []*simpletable.Cell{ + {Align: simpletable.AlignCenter, Text: "ID"}, + {Align: simpletable.AlignCenter, Text: "Name"}, + }, + } - table.Header = &simpletable.Header{ - Cells: []*simpletable.Cell{ - {Align: simpletable.AlignCenter, Text: "ID"}, - {Align: simpletable.AlignCenter, Text: "Name"}, - }, - } + for _, p := range pipelines { + r := []*simpletable.Cell{ + {Align: simpletable.AlignRight, Text: strconv.Itoa(p.ID)}, + {Align: simpletable.AlignCenter, Text: p.Name}, + } - for _, p := range pipelines { - r := []*simpletable.Cell{ - {Align: simpletable.AlignRight, Text: strconv.Itoa(p.ID)}, - {Align: simpletable.AlignCenter, Text: p.Name}, + table.Body.Cells = append(table.Body.Cells, r) } - - table.Body.Cells = append(table.Body.Cells, r) + table.SetStyle(simpletable.StyleCompact) + fmt.Println(table.String()) } - table.SetStyle(simpletable.StyleCompact) - fmt.Println(table.String()) } diff --git a/cmd/display_test.go b/cmd/display_test.go index 28440f719..ce3394c29 100644 --- a/cmd/display_test.go +++ b/cmd/display_test.go @@ -59,11 +59,39 @@ func TestResourcesTable(t *testing.T) { } } fmt.Println(out) - }) } } +func TestEmptyTables(t *testing.T) { + emptyResourcesList := []*meroxa.Resource{} + out := captureOutput(func() { + printResourcesTable(emptyResourcesList) + }) + + if out != "" { + t.Errorf("Output for resources should be blank") + } + + emptyConnectorsList := []*meroxa.Connector{} + out = captureOutput(func() { + printConnectorsTable(emptyConnectorsList) + }) + + if out != "" { + t.Errorf("Output for connectors should be blank") + } + + emptyPipelinesList := []*meroxa.Pipeline{} + + out = captureOutput(func() { + printPipelinesTable(emptyPipelinesList) + }) + + if out != "" { + t.Errorf("Output for pipelines should be blank") + } +} func TestResourceTypesTable(t *testing.T) { types := []string{"postgres", "s3", "redshift", "mysql", "jdbc", "url", "mongodb"} printResourceTypesTable(types)