From bb58af48f66910c161cb58a4b89cb39dfc350cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Barroso?= Date: Thu, 23 Jan 2025 12:17:49 +0100 Subject: [PATCH 1/3] feat: show type on processors ls --- cmd/conduit/internal/print_utils.go | 14 +++++++ cmd/conduit/internal/print_utils_test.go | 53 ++++++++++++++++++++++++ cmd/conduit/root/processors/describe.go | 12 +----- cmd/conduit/root/processors/list.go | 18 ++------ 4 files changed, 71 insertions(+), 26 deletions(-) create mode 100644 cmd/conduit/internal/print_utils_test.go diff --git a/cmd/conduit/internal/print_utils.go b/cmd/conduit/internal/print_utils.go index 539a8e665..c35e30e95 100644 --- a/cmd/conduit/internal/print_utils.go +++ b/cmd/conduit/internal/print_utils.go @@ -195,3 +195,17 @@ func formatValidations(v []*configv1.Validation) string { } return result.String() } + +// ProcessorTypeToString returns a human-readable string from a processor parent type +func ProcessorTypeToString(processorParentType apiv1.Processor_Parent_Type) string { + switch processorParentType { + case apiv1.Processor_Parent_TYPE_CONNECTOR: + return "connector" + case apiv1.Processor_Parent_TYPE_PIPELINE: + return "pipeline" + case apiv1.Processor_Parent_TYPE_UNSPECIFIED: + return "unspecified" + default: + return "unknown" + } +} diff --git a/cmd/conduit/internal/print_utils_test.go b/cmd/conduit/internal/print_utils_test.go new file mode 100644 index 000000000..49828a148 --- /dev/null +++ b/cmd/conduit/internal/print_utils_test.go @@ -0,0 +1,53 @@ +// Copyright © 2025 Meroxa, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package internal + +import ( + "testing" + + apiv1 "github.com/conduitio/conduit/proto/api/v1" + "github.com/matryer/is" +) + +func TestProcessorTypeToString(t *testing.T) { + is := is.New(t) + + tests := []struct { + name string + processorParentType apiv1.Processor_Parent_Type + want string + }{ + { + name: "Connector", + processorParentType: apiv1.Processor_Parent_TYPE_CONNECTOR, + want: "connector", + }, + { + name: "Pipeline", + processorParentType: apiv1.Processor_Parent_TYPE_PIPELINE, + want: "pipeline", + }, + { + name: "Unspecified", + processorParentType: apiv1.Processor_Parent_TYPE_UNSPECIFIED, + want: "unspecified", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + is.Equal(ProcessorTypeToString(tt.processorParentType), tt.want) + }) + } +} diff --git a/cmd/conduit/root/processors/describe.go b/cmd/conduit/root/processors/describe.go index 2e4e2189f..e7326b428 100644 --- a/cmd/conduit/root/processors/describe.go +++ b/cmd/conduit/root/processors/describe.go @@ -84,17 +84,7 @@ func displayProcessor(p *apiv1.Processor) { fmt.Printf("ID: %s\n", p.Id) fmt.Printf("Plugin: %s\n", p.Plugin) - processorType := "Processor " - switch p.Parent.Type.String() { - case "TYPE_PIPELINE": - processorType += "for Pipeline" - case "TYPE_CONNECTOR": - processorType += "for Connector" - default: - processorType += "associated to" - } - - fmt.Printf("%s: %s\n", processorType, p.Parent.Id) + fmt.Printf("Type: %s (%s)\n", internal.ProcessorTypeToString(p.Parent.Type), p.Parent.Id) if !internal.IsEmpty(p.Condition) { fmt.Printf("Condition: %s\n", p.Condition) diff --git a/cmd/conduit/root/processors/list.go b/cmd/conduit/root/processors/list.go index b43f2f673..c52c018ba 100644 --- a/cmd/conduit/root/processors/list.go +++ b/cmd/conduit/root/processors/list.go @@ -74,32 +74,20 @@ func displayProcessors(processors []*apiv1.Processor) { Cells: []*simpletable.Cell{ {Align: simpletable.AlignCenter, Text: "ID"}, {Align: simpletable.AlignCenter, Text: "PLUGIN"}, - {Align: simpletable.AlignCenter, Text: "CONDITION"}, {Align: simpletable.AlignCenter, Text: "TYPE"}, + {Align: simpletable.AlignCenter, Text: "CONDITION"}, {Align: simpletable.AlignCenter, Text: "CREATED"}, {Align: simpletable.AlignCenter, Text: "LAST_UPDATED"}, }, } for _, p := range processors { - var processorType string - - switch p.Parent.Type.String() { - case "TYPE_PIPELINE": - processorType = "Pipeline" - case "TYPE_CONNECTOR": - processorType = "Connector" - default: - processorType = "Unknown" - } - - processorType = fmt.Sprintf("%s (%s)", processorType, p.Parent.Id) - + processorType := fmt.Sprintf("%s (%s)", internal.ProcessorTypeToString(p.Parent.Type), p.Parent.Id) r := []*simpletable.Cell{ {Align: simpletable.AlignLeft, Text: p.Id}, {Align: simpletable.AlignLeft, Text: p.Plugin}, - {Align: simpletable.AlignLeft, Text: p.Condition}, {Align: simpletable.AlignLeft, Text: processorType}, + {Align: simpletable.AlignLeft, Text: p.Condition}, {Align: simpletable.AlignLeft, Text: internal.PrintTime(p.CreatedAt)}, {Align: simpletable.AlignLeft, Text: internal.PrintTime(p.UpdatedAt)}, } From 1d381aee2095cdca234e1275ef4d3acf4e6cd62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Barroso?= Date: Thu, 23 Jan 2025 17:37:13 +0100 Subject: [PATCH 2/3] use parent instead --- cmd/conduit/internal/print_utils.go | 4 ++-- cmd/conduit/internal/print_utils_test.go | 4 ++-- cmd/conduit/root/processors/describe.go | 2 +- cmd/conduit/root/processors/list.go | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/conduit/internal/print_utils.go b/cmd/conduit/internal/print_utils.go index c35e30e95..bf1e8fa33 100644 --- a/cmd/conduit/internal/print_utils.go +++ b/cmd/conduit/internal/print_utils.go @@ -196,8 +196,8 @@ func formatValidations(v []*configv1.Validation) string { return result.String() } -// ProcessorTypeToString returns a human-readable string from a processor parent type -func ProcessorTypeToString(processorParentType apiv1.Processor_Parent_Type) string { +// ProcessorParentToString returns a human-readable string from a processor parent type +func ProcessorParentToString(processorParentType apiv1.Processor_Parent_Type) string { switch processorParentType { case apiv1.Processor_Parent_TYPE_CONNECTOR: return "connector" diff --git a/cmd/conduit/internal/print_utils_test.go b/cmd/conduit/internal/print_utils_test.go index 49828a148..bd49987ba 100644 --- a/cmd/conduit/internal/print_utils_test.go +++ b/cmd/conduit/internal/print_utils_test.go @@ -21,7 +21,7 @@ import ( "github.com/matryer/is" ) -func TestProcessorTypeToString(t *testing.T) { +func TestProcessorParentTypeToString(t *testing.T) { is := is.New(t) tests := []struct { @@ -47,7 +47,7 @@ func TestProcessorTypeToString(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - is.Equal(ProcessorTypeToString(tt.processorParentType), tt.want) + is.Equal(ProcessorParentToString(tt.processorParentType), tt.want) }) } } diff --git a/cmd/conduit/root/processors/describe.go b/cmd/conduit/root/processors/describe.go index e7326b428..ca82ba19e 100644 --- a/cmd/conduit/root/processors/describe.go +++ b/cmd/conduit/root/processors/describe.go @@ -84,7 +84,7 @@ func displayProcessor(p *apiv1.Processor) { fmt.Printf("ID: %s\n", p.Id) fmt.Printf("Plugin: %s\n", p.Plugin) - fmt.Printf("Type: %s (%s)\n", internal.ProcessorTypeToString(p.Parent.Type), p.Parent.Id) + fmt.Printf("Parent: %s (%s)\n", internal.ProcessorParentToString(p.Parent.Type), p.Parent.Id) if !internal.IsEmpty(p.Condition) { fmt.Printf("Condition: %s\n", p.Condition) diff --git a/cmd/conduit/root/processors/list.go b/cmd/conduit/root/processors/list.go index c52c018ba..294f7206b 100644 --- a/cmd/conduit/root/processors/list.go +++ b/cmd/conduit/root/processors/list.go @@ -74,7 +74,7 @@ func displayProcessors(processors []*apiv1.Processor) { Cells: []*simpletable.Cell{ {Align: simpletable.AlignCenter, Text: "ID"}, {Align: simpletable.AlignCenter, Text: "PLUGIN"}, - {Align: simpletable.AlignCenter, Text: "TYPE"}, + {Align: simpletable.AlignCenter, Text: "PARENT"}, {Align: simpletable.AlignCenter, Text: "CONDITION"}, {Align: simpletable.AlignCenter, Text: "CREATED"}, {Align: simpletable.AlignCenter, Text: "LAST_UPDATED"}, @@ -82,11 +82,11 @@ func displayProcessors(processors []*apiv1.Processor) { } for _, p := range processors { - processorType := fmt.Sprintf("%s (%s)", internal.ProcessorTypeToString(p.Parent.Type), p.Parent.Id) + processorParent := fmt.Sprintf("%s (%s)", internal.ProcessorParentToString(p.Parent.Type), p.Parent.Id) r := []*simpletable.Cell{ {Align: simpletable.AlignLeft, Text: p.Id}, {Align: simpletable.AlignLeft, Text: p.Plugin}, - {Align: simpletable.AlignLeft, Text: processorType}, + {Align: simpletable.AlignLeft, Text: processorParent}, {Align: simpletable.AlignLeft, Text: p.Condition}, {Align: simpletable.AlignLeft, Text: internal.PrintTime(p.CreatedAt)}, {Align: simpletable.AlignLeft, Text: internal.PrintTime(p.UpdatedAt)}, From 2cca418fb14e19caf23b7ce7089583604dff2639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Barroso?= Date: Thu, 23 Jan 2025 17:46:15 +0100 Subject: [PATCH 3/3] fix --- cmd/conduit/internal/print_utils.go | 1 - cmd/conduit/internal/print_utils_test.go | 1 - 2 files changed, 2 deletions(-) diff --git a/cmd/conduit/internal/print_utils.go b/cmd/conduit/internal/print_utils.go index 8e71539be..a4f5ce4be 100644 --- a/cmd/conduit/internal/print_utils.go +++ b/cmd/conduit/internal/print_utils.go @@ -223,4 +223,3 @@ func ConnectorTypeToString(connectorType apiv1.Connector_Type) string { return "unknown" } } - diff --git a/cmd/conduit/internal/print_utils_test.go b/cmd/conduit/internal/print_utils_test.go index f3569f1c0..f8cc1081b 100644 --- a/cmd/conduit/internal/print_utils_test.go +++ b/cmd/conduit/internal/print_utils_test.go @@ -82,4 +82,3 @@ func TestProcessorParentTypeToString(t *testing.T) { }) } } -