Skip to content

Commit 6867edd

Browse files
committed
fix: Fixed failing test case with valid filter name
- Fixed test cases with valid filter path - Moved formatting strings to constants
1 parent 20e1aa7 commit 6867edd

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

cmd/diff_utils.go

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,29 @@ const (
3939
minBoxWidth = 50
4040
)
4141

42+
// Display constants.
43+
const (
44+
// Configuration headers.
45+
removedConfigHeader = "REMOVED CONFIGURATIONS"
46+
newConfigHeader = "NEW CONFIGURATIONS"
47+
modifiedConfigHeader = "MODIFIED CONFIGURATIONS"
48+
49+
// Icons and prefixes.
50+
iconRemoval = "❌"
51+
iconAddition = "✅"
52+
iconModification = "🔄"
53+
removalPrefix = "-"
54+
additionPrefix = "+"
55+
modificationPrefix = "~"
56+
57+
// Business logic constants.
58+
defaultSectionName = "general"
59+
enterpriseOnlyText = "Enterprise Edition Only"
60+
allowedValuesText = "Allowed values"
61+
booleanYesText = "Yes"
62+
booleanNoText = "No"
63+
)
64+
4265
// SchemaChange represents a single schema change.
4366
type SchemaChange struct {
4467
Path string
@@ -237,7 +260,7 @@ func extractSection(path string, validSections map[string]bool) string {
237260
}
238261

239262
// If we didn't find a valid section, return "general"
240-
return "general"
263+
return defaultSectionName
241264
}
242265

243266
// Output formatting
@@ -307,9 +330,9 @@ func printAllChanges(changes SectionChanges, options DiffOptions) {
307330
icon string
308331
prefix string
309332
}{
310-
{changes.Removals, "REMOVED CONFIGURATIONS", "❌", "-"},
311-
{changes.Additions, "NEW CONFIGURATIONS", "✅", "+"},
312-
{changes.Modifications, "MODIFIED CONFIGURATIONS", "🔄", "~"},
333+
{changes.Removals, removedConfigHeader, iconRemoval, removalPrefix},
334+
{changes.Additions, newConfigHeader, iconAddition, additionPrefix},
335+
{changes.Modifications, modifiedConfigHeader, iconModification, modificationPrefix},
313336
}
314337

315338
// Process each change type
@@ -326,7 +349,7 @@ func printAllChanges(changes SectionChanges, options DiffOptions) {
326349
}
327350

328351
// Handle modifications with array processing
329-
if config.header == "MODIFIED CONFIGURATIONS" {
352+
if config.header == modifiedConfigHeader {
330353
printModifications(config.changes, options, config.icon, config.prefix)
331354
continue
332355
}
@@ -373,7 +396,7 @@ func printArrayChangeVerbose(change SchemaChange, path, header, icon string, opt
373396
}
374397

375398
// Print additional details for additions (only for simple objects)
376-
if header == "NEW CONFIGURATIONS" && !isComplexProperty(change.Value) {
399+
if header == newConfigHeader && !isComplexProperty(change.Value) {
377400
printValueProperties(change.Value, options)
378401
}
379402
}
@@ -392,7 +415,7 @@ func printNormalChange(change SchemaChange, path, header, icon, prefix string, o
392415
if options.Verbose {
393416
fmt.Fprintf(os.Stdout, " %s %s\n", icon, path)
394417
// Print additional details for additions
395-
if header == "NEW CONFIGURATIONS" {
418+
if header == newConfigHeader {
396419
printValueProperties(change.Value, options)
397420
}
398421
} else {
@@ -647,9 +670,9 @@ func formatKeyName(key string) string {
647670
// Handle common special cases
648671
switch key {
649672
case "enterpriseOnly":
650-
return "Enterprise Edition Only"
673+
return enterpriseOnlyText
651674
case "enum":
652-
return "Allowed values"
675+
return allowedValuesText
653676
default:
654677
// Simple camelCase to Title Case conversion
655678
if len(key) == 0 {
@@ -668,9 +691,9 @@ func formatValue(value any) string {
668691
switch v := value.(type) {
669692
case bool:
670693
if v {
671-
return "Yes"
694+
return booleanYesText
672695
}
673-
return "No"
696+
return booleanNoText
674697
case string:
675698
if v == "" {
676699
return ""

cmd/diff_versions_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func TestVersionsDiffCLIIntegration(t *testing.T) {
321321
},
322322
{
323323
name: "valid versions diff with filter",
324-
args: []string{"diff", "versions", firstVersion, secondVersion, "--filter-path", "service"},
324+
args: []string{"diff", "versions", firstVersion, secondVersion, "--filter-path", "security"},
325325
expectError: false,
326326
},
327327
{
@@ -672,7 +672,7 @@ func TestVersionsDiffOutputConsistency(t *testing.T) {
672672
}{
673673
{"verbose_mode", firstVersion, secondVersion, []string{}},
674674
{"compact_mode", firstVersion, secondVersion, []string{"--compact"}},
675-
{"filtered_mode", firstVersion, secondVersion, []string{"--filter-path", "service"}},
675+
{"filtered_mode", firstVersion, secondVersion, []string{"--filter-path", "security"}},
676676
}
677677

678678
for _, tc := range testCases {

0 commit comments

Comments
 (0)