Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update type on processors ls #2097

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmd/conduit/internal/print_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
raulb marked this conversation as resolved.
Show resolved Hide resolved
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"
}
}
53 changes: 53 additions & 0 deletions cmd/conduit/internal/print_utils_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}
12 changes: 1 addition & 11 deletions cmd/conduit/root/processors/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 3 additions & 15 deletions cmd/conduit/root/processors/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
}
Expand Down
Loading