diff --git a/cmd/topicctl/subcmd/tester.go b/cmd/topicctl/subcmd/tester.go index 4c75a9de..03bd18eb 100644 --- a/cmd/topicctl/subcmd/tester.go +++ b/cmd/topicctl/subcmd/tester.go @@ -10,7 +10,7 @@ import ( "time" "github.com/segmentio/kafka-go" - "github.com/segmentio/topicctl/pkg/apply" + "github.com/segmentio/topicctl/pkg/util" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -104,7 +104,7 @@ func runTestReader(ctx context.Context) error { testerConfig.readConsumer, ) - ok, _ := apply.Confirm("OK to continue?", false) + ok, _ := util.Confirm("OK to continue?", false) if !ok { return errors.New("Stopping because of user response") } @@ -153,7 +153,7 @@ func runTestWriter(ctx context.Context) error { testerConfig.writeRate, ) - ok, _ := apply.Confirm("OK to continue?", false) + ok, _ := util.Confirm("OK to continue?", false) if !ok { return errors.New("Stopping because of user response") } diff --git a/pkg/apply/apply.go b/pkg/apply/apply.go index 76e54f0f..25b0084b 100644 --- a/pkg/apply/apply.go +++ b/pkg/apply/apply.go @@ -163,7 +163,7 @@ func (t *TopicApplier) applyNewTopic(ctx context.Context) error { FormatNewTopicConfig(newTopicConfig), ) - ok, _ := Confirm("OK to continue?", t.config.SkipConfirm) + ok, _ := util.Confirm("OK to continue?", t.config.SkipConfirm) if !ok { return errors.New("Stopping because of user response") } @@ -283,7 +283,7 @@ func (t *TopicApplier) checkExistingState( if t.config.DryRun { log.Infof("Skipping update because dryRun is set to true") } else { - ok, err := Confirm("OK to remove these?", t.config.SkipConfirm) + ok, err := util.Confirm("OK to remove these?", t.config.SkipConfirm) if err != nil { return err } else if !ok { @@ -326,7 +326,7 @@ func (t *TopicApplier) checkExistingState( if t.config.DryRun { log.Infof("Skipping update because dryRun is set to true") } else { - ok, err := Confirm("OK to remove broker throttles?", t.config.SkipConfirm) + ok, err := util.Confirm("OK to remove broker throttles?", t.config.SkipConfirm) if err != nil { return err } else if !ok { @@ -413,7 +413,7 @@ func (t *TopicApplier) updateSettings( return nil } - ok, _ := Confirm( + ok, _ := util.Confirm( "OK to update to the new values in the topic config?", t.config.SkipConfirm, ) @@ -576,7 +576,7 @@ func (t *TopicApplier) updatePartitionsHelper( return nil } - ok, _ := Confirm("OK to apply?", t.config.SkipConfirm) + ok, _ := util.Confirm("OK to apply?", t.config.SkipConfirm) if !ok { return errors.New("Stopping because of user response") } @@ -678,7 +678,7 @@ func (t *TopicApplier) updatePlacement( desiredPlacement, ) - ok, _ := Confirm( + ok, _ := util.Confirm( fmt.Sprintf("OK to apply %s despite having unbalanced leaders?", desiredPlacement), t.config.SkipConfirm || t.config.DryRun, ) @@ -841,7 +841,7 @@ func (t *TopicApplier) updatePlacementRunner( log.Warnf("Autocontinue flag detected, user will not be prompted each round") } - ok, _ := Confirm("OK to apply?", t.config.SkipConfirm) + ok, _ := util.Confirm("OK to apply?", t.config.SkipConfirm) if !ok { return errors.New("Stopping because of user response") } @@ -917,7 +917,7 @@ func (t *TopicApplier) updatePlacementRunner( if t.config.AutoContinueRebalance { log.Infof("Autocontinuing to next round") } else { - ok, _ := Confirm("OK to continue?", t.config.SkipConfirm) + ok, _ := util.Confirm("OK to continue?", t.config.SkipConfirm) if !ok { return errors.New("Stopping because of user response") } @@ -1249,7 +1249,7 @@ func (t *TopicApplier) updateLeaders( batchSize = len(wrongLeaders) } - ok, _ := Confirm( + ok, _ := util.Confirm( fmt.Sprintf( "OK to run leader elections (in batches of %d partitions each) ?", batchSize, diff --git a/pkg/config/load_test.go b/pkg/config/load_test.go index 1a0ce76c..66bc36d3 100644 --- a/pkg/config/load_test.go +++ b/pkg/config/load_test.go @@ -105,7 +105,6 @@ func TestLoadTopicsFile(t *testing.T) { assert.Equal(t, "topic-test2", topicConfigs[1].Meta.Name) } -// TODO: write this test func TestLoadACLsFile(t *testing.T) { aclConfigs, err := LoadACLsFile("testdata/test-cluster/acls/acl-test.yaml") require.NoError(t, err) @@ -159,7 +158,6 @@ func TestLoadACLsFile(t *testing.T) { invalidAclConfigs, err := LoadACLsFile("testdata/test-cluster/acls/acl-test-invalid.yaml") assert.Equal(t, 0, len(invalidAclConfigs)) - // TODO: improve this error checking and make sure the error is informative enough require.Error(t, err) multiAclConfigs, err := LoadACLsFile("testdata/test-cluster/acls/acl-test-multi.yaml") diff --git a/pkg/create/acl.go b/pkg/create/acl.go index 673e7621..425d8b5d 100644 --- a/pkg/create/acl.go +++ b/pkg/create/acl.go @@ -8,8 +8,8 @@ import ( "github.com/segmentio/kafka-go" "github.com/segmentio/topicctl/pkg/admin" - "github.com/segmentio/topicctl/pkg/apply" "github.com/segmentio/topicctl/pkg/config" + "github.com/segmentio/topicctl/pkg/util" log "github.com/sirupsen/logrus" ) @@ -105,8 +105,7 @@ func (a *ACLCreator) Create(ctx context.Context) error { formatNewACLsConfig(newACLs), ) - // TODO: move confirm away from apply package - ok, _ := apply.Confirm("OK to continue?", a.config.SkipConfirm) + ok, _ := util.Confirm("OK to continue?", a.config.SkipConfirm) if !ok { return errors.New("Stopping because of user response") } diff --git a/pkg/apply/confirm.go b/pkg/util/confirm.go similarity index 98% rename from pkg/apply/confirm.go rename to pkg/util/confirm.go index 62e54787..101d5435 100644 --- a/pkg/apply/confirm.go +++ b/pkg/util/confirm.go @@ -1,4 +1,4 @@ -package apply +package util import ( "fmt"