This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- allow colorized diffs, use `COLOR_DIFF=true` to force on - clarify what is unexpected or missing - reference specific expected field and index when appropriate - hide "for config X" for the default config, continue to show for extra configs Signed-off-by: Scott Andrews <[email protected]>
- Loading branch information
Showing
9 changed files
with
117 additions
and
56 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
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,41 @@ | ||
/* | ||
Copyright 2023 VMware, Inc. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package testing | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
|
||
"github.com/fatih/color" | ||
) | ||
|
||
func init() { | ||
if _, ok := os.LookupEnv("COLOR_DIFF"); ok { | ||
DiffAddedColor.EnableColor() | ||
DiffRemovedColor.EnableColor() | ||
} | ||
} | ||
|
||
var ( | ||
DiffAddedColor = color.New(color.FgGreen) | ||
DiffRemovedColor = color.New(color.FgRed) | ||
) | ||
|
||
func ColorizeDiff(diff string) string { | ||
var b strings.Builder | ||
for _, line := range strings.Split(diff, "\n") { | ||
switch { | ||
case strings.HasPrefix(line, "+"): | ||
b.WriteString(DiffAddedColor.Sprint(line)) | ||
case strings.HasPrefix(line, "-"): | ||
b.WriteString(DiffRemovedColor.Sprint(line)) | ||
default: | ||
b.WriteString(line) | ||
} | ||
b.WriteString("\n") | ||
} | ||
return b.String() | ||
} |
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
Oops, something went wrong.