-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure deprecated flags are correctly hidden (#1974)
* ensure flags are correctly hidden * rename file * fix lint * oops * more generic * fix linting errors * print out error * Update go.mod * have dev flags shown * fix typo
- Loading branch information
Showing
6 changed files
with
187 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright © 2024 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 cli | ||
|
||
import ( | ||
"bytes" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/conduitio/conduit/pkg/conduit" | ||
) | ||
|
||
func TestBuildRootCmd_HelpOutput(t *testing.T) { | ||
cmd := buildRootCmd() | ||
|
||
var buf bytes.Buffer | ||
cmd.SetOut(&buf) | ||
cmd.SetArgs([]string{"--help"}) | ||
|
||
err := cmd.Execute() | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
|
||
output := buf.String() | ||
|
||
expectedFlags := []string{ | ||
"db.type", | ||
"db.badger.path", | ||
"db.postgres.connection-string", | ||
"db.postgres.table", | ||
"db.sqlite.path", | ||
"db.sqlite.table", | ||
"dev.blockprofileblockprofile", | ||
"dev.cpuprofile", | ||
"dev.memprofile", | ||
"api.enabled", | ||
"http.address", | ||
"grpc.address", | ||
"log.level", | ||
"log.format", | ||
"connectors.path", | ||
"processors.path", | ||
"pipelines.path", | ||
"pipelines.exit-on-degraded", | ||
"pipelines.error-recovery.min-delay", | ||
"pipelines.error-recovery.max-delay", | ||
"pipelines.error-recovery.backoff-factor", | ||
"pipelines.error-recovery.max-retries", | ||
"pipelines.error-recovery.max-retries-window", | ||
"schema-registry.type", | ||
"schema-registry.confluent.connection-string", | ||
"preview.pipeline-arch-v2", | ||
} | ||
|
||
unexpectedFlags := []string{ | ||
conduit.FlagPipelinesExitOnError, //nolint:staticcheck // this will be completely removed before Conduit 1.0 | ||
} | ||
|
||
for _, flag := range expectedFlags { | ||
if !strings.Contains(output, flag) { | ||
t.Errorf("expected flag %q not found in help output", flag) | ||
} | ||
} | ||
|
||
for _, flag := range unexpectedFlags { | ||
if strings.Contains(output, flag) { | ||
t.Errorf("unexpected flag %q found in help output", flag) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright © 2024 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 conduit | ||
|
||
import ( | ||
"bytes" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestFlags_HelpOutput(t *testing.T) { | ||
var buf bytes.Buffer | ||
|
||
flags := Flags(&Config{}) | ||
flags.SetOutput(&buf) | ||
|
||
flags.Usage() | ||
output := buf.String() | ||
|
||
expectedFlags := []string{ | ||
"db.type", | ||
"db.badger.path", | ||
"db.postgres.connection-string", | ||
"db.postgres.table", | ||
"db.sqlite.path", | ||
"db.sqlite.table", | ||
"dev.blockprofileblockprofile", | ||
"dev.cpuprofile", | ||
"dev.memprofile", | ||
"api.enabled", | ||
"http.address", | ||
"grpc.address", | ||
"log.level", | ||
"log.format", | ||
"connectors.path", | ||
"processors.path", | ||
"pipelines.path", | ||
"pipelines.exit-on-degraded", | ||
"pipelines.error-recovery.min-delay", | ||
"pipelines.error-recovery.max-delay", | ||
"pipelines.error-recovery.backoff-factor", | ||
"pipelines.error-recovery.max-retries", | ||
"pipelines.error-recovery.max-retries-window", | ||
"schema-registry.type", | ||
"schema-registry.confluent.connection-string", | ||
"preview.pipeline-arch-v2", | ||
} | ||
|
||
unexpectedFlags := []string{ | ||
FlagPipelinesExitOnError, | ||
} | ||
|
||
for _, flag := range expectedFlags { | ||
if !strings.Contains(output, flag) { | ||
t.Errorf("expected flag %q not found in help output", flag) | ||
} | ||
} | ||
|
||
for _, flag := range unexpectedFlags { | ||
if strings.Contains(output, flag) { | ||
t.Errorf("unexpected flag %q found in help output", flag) | ||
} | ||
} | ||
} |