Skip to content

Commit

Permalink
add fail-on INFO for changelog (#510)
Browse files Browse the repository at this point in the history
Co-authored-by: Reuven <[email protected]>
  • Loading branch information
reuvenharrison and Reuven authored Mar 25, 2024
1 parent 8031b1c commit a006518
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func getChangelogCmd() *cobra.Command {
addCommonDiffFlags(&cmd, &flags)
addCommonBreakingFlags(&cmd, &flags)
enumWithOptions(&cmd, newEnumValue(formatters.SupportedFormatsByContentType(formatters.OutputChangelog), string(formatters.FormatText), &flags.format), "format", "f", "output format")
enumWithOptions(&cmd, newEnumValue([]string{LevelErr, LevelWarn, LevelInfo}, "", &flags.failOn), "fail-on", "o", "exit with return code 1 when output includes errors with this level or higher")

return &cmd
}
Expand Down
10 changes: 9 additions & 1 deletion internal/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,22 @@ func Test_BreakingChangesFailOnWarnsErrsOnly(t *testing.T) {
require.Equal(t, 1, internal.Run(cmdToArgs("oasdiff breaking ../data/openapi-test2.yaml ../data/openapi-test4.yaml --fail-on WARN"), io.Discard, io.Discard))
}

func Test_BreakingChangesFailOnDiffNoDiff(t *testing.T) {
func Test_BreakingChangesFailOnErrNoDiff(t *testing.T) {
require.Zero(t, internal.Run(cmdToArgs("oasdiff breaking ../data/openapi-test1.yaml ../data/openapi-test1.yaml --fail-on ERR"), io.Discard, io.Discard))
}

func Test_BreakingChangesFailOnWarnsNoDiff(t *testing.T) {
require.Zero(t, internal.Run(cmdToArgs("oasdiff breaking ../data/openapi-test1.yaml ../data/openapi-test1.yaml --fail-on WARN"), io.Discard, io.Discard))
}

func Test_ChangelogFailOnInfo(t *testing.T) {
require.Equal(t, 1, internal.Run(cmdToArgs("oasdiff changelog ../data/simple3.yaml ../data/simple4.yaml --fail-on INFO"), io.Discard, io.Discard))
}

func Test_ChangelogFailOnWarnInfosOnly(t *testing.T) {
require.Zero(t, internal.Run(cmdToArgs("oasdiff changelog ../data/simple3.yaml ../data/simple4.yaml --fail-on WARN"), io.Discard, io.Discard))
}

func Test_BreakingChangesIgnoreErrs(t *testing.T) {
var stdout bytes.Buffer
require.Zero(t, internal.Run(cmdToArgs("oasdiff breaking ../data/openapi-test1.yaml ../data/openapi-test3.yaml --err-ignore ../data/ignore-err-example.txt --format json"), &stdout, io.Discard))
Expand Down

0 comments on commit a006518

Please sign in to comment.