From a006518963fbea42fed92d742a76d85678e68c32 Mon Sep 17 00:00:00 2001 From: Reuven Harrison Date: Mon, 25 Mar 2024 22:31:28 +0200 Subject: [PATCH] add `fail-on INFO` for changelog (#510) Co-authored-by: Reuven --- internal/changelog.go | 1 + internal/run_test.go | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/changelog.go b/internal/changelog.go index 4d5f3a61..cfdab4ee 100644 --- a/internal/changelog.go +++ b/internal/changelog.go @@ -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 } diff --git a/internal/run_test.go b/internal/run_test.go index 59a4a3c9..17a90607 100644 --- a/internal/run_test.go +++ b/internal/run_test.go @@ -149,7 +149,7 @@ 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)) } @@ -157,6 +157,14 @@ 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))