From 7be1fb69c3503bb3960aee5396f32d7c82f15d55 Mon Sep 17 00:00:00 2001 From: Reuven Date: Sun, 4 Feb 2024 10:57:03 +0200 Subject: [PATCH] emphasize common-params != path-params --- .../no_params.yaml | 0 .../params_in_op.yaml | 0 .../params_in_path.yaml | 0 diff/diff_common_params_test.go | 18 +++++++++--------- internal/run_test.go | 14 +++++++++++--- 5 files changed, 20 insertions(+), 12 deletions(-) rename data/{path-params => common-params}/no_params.yaml (100%) rename data/{path-params => common-params}/params_in_op.yaml (100%) rename data/{path-params => common-params}/params_in_path.yaml (100%) diff --git a/data/path-params/no_params.yaml b/data/common-params/no_params.yaml similarity index 100% rename from data/path-params/no_params.yaml rename to data/common-params/no_params.yaml diff --git a/data/path-params/params_in_op.yaml b/data/common-params/params_in_op.yaml similarity index 100% rename from data/path-params/params_in_op.yaml rename to data/common-params/params_in_op.yaml diff --git a/data/path-params/params_in_path.yaml b/data/common-params/params_in_path.yaml similarity index 100% rename from data/path-params/params_in_path.yaml rename to data/common-params/params_in_path.yaml diff --git a/diff/diff_common_params_test.go b/diff/diff_common_params_test.go index f8e391bd..3b304144 100644 --- a/diff/diff_common_params_test.go +++ b/diff/diff_common_params_test.go @@ -9,13 +9,13 @@ import ( "github.com/tufin/oasdiff/load" ) -func TestDiff_PathParamsDeleted(t *testing.T) { +func TestDiff_CommonParamsDeleted(t *testing.T) { loader := openapi3.NewLoader() - s1, err := load.NewSpecInfo(loader, load.NewSource("../data/path-params/params_in_path.yaml"), load.WithFlattenParams()) + s1, err := load.NewSpecInfo(loader, load.NewSource("../data/common-params/params_in_path.yaml"), load.WithFlattenParams()) require.NoError(t, err) - s2, err := load.NewSpecInfo(loader, load.NewSource("../data/path-params/no_params.yaml"), load.WithFlattenParams()) + s2, err := load.NewSpecInfo(loader, load.NewSource("../data/common-params/no_params.yaml"), load.WithFlattenParams()) require.NoError(t, err) d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) @@ -23,13 +23,13 @@ func TestDiff_PathParamsDeleted(t *testing.T) { require.NotEmpty(t, d.EndpointsDiff.Modified[diff.Endpoint{Method: "GET", Path: "/admin/v0/abc/{id}"}].ParametersDiff.Deleted) } -func TestDiff_PathParamsMoved(t *testing.T) { +func TestDiff_CommonParamsMoved(t *testing.T) { loader := openapi3.NewLoader() - s1, err := load.NewSpecInfo(loader, load.NewSource("../data/path-params/params_in_path.yaml"), load.WithFlattenParams()) + s1, err := load.NewSpecInfo(loader, load.NewSource("../data/common-params/params_in_path.yaml"), load.WithFlattenParams()) require.NoError(t, err) - s2, err := load.NewSpecInfo(loader, load.NewSource("../data/path-params/params_in_op.yaml"), load.WithFlattenParams()) + s2, err := load.NewSpecInfo(loader, load.NewSource("../data/common-params/params_in_op.yaml"), load.WithFlattenParams()) require.NoError(t, err) d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) @@ -37,13 +37,13 @@ func TestDiff_PathParamsMoved(t *testing.T) { require.Empty(t, d) } -func TestDiff_PathParamsAdded(t *testing.T) { +func TestDiff_CommonParamsAdded(t *testing.T) { loader := openapi3.NewLoader() - s1, err := load.NewSpecInfo(loader, load.NewSource("../data/path-params/no_params.yaml"), load.WithFlattenParams()) + s1, err := load.NewSpecInfo(loader, load.NewSource("../data/common-params/no_params.yaml"), load.WithFlattenParams()) require.NoError(t, err) - s2, err := load.NewSpecInfo(loader, load.NewSource("../data/path-params/params_in_path.yaml"), load.WithFlattenParams()) + s2, err := load.NewSpecInfo(loader, load.NewSource("../data/common-params/params_in_path.yaml"), load.WithFlattenParams()) require.NoError(t, err) d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) diff --git a/internal/run_test.go b/internal/run_test.go index 81cf0010..c165ee26 100644 --- a/internal/run_test.go +++ b/internal/run_test.go @@ -262,15 +262,23 @@ func Test_BreakingChangesChangelogOptionalCheckersAreErrorLevelWhenSpecified(t * } } -func Test_BreakingChangesFlatten(t *testing.T) { +func Test_BreakingChangesFlattenDeprecated(t *testing.T) { + require.Zero(t, internal.Run(cmdToArgs("oasdiff breaking ../data/allof/simple.yaml ../data/allof/revision.yaml --flatten --fail-on ERR"), io.Discard, io.Discard)) +} + +func Test_BreakingChangesFlattenAllOf(t *testing.T) { require.Zero(t, internal.Run(cmdToArgs("oasdiff breaking ../data/allof/simple.yaml ../data/allof/revision.yaml --flatten-allof --fail-on ERR"), io.Discard, io.Discard)) } -func Test_FlattenOK(t *testing.T) { +func Test_BreakingChangesFlattenCommonParams(t *testing.T) { + require.Zero(t, internal.Run(cmdToArgs("oasdiff breaking ../data/common-params/params_in_path.yaml ../data/common-params/params_in_op.yaml --flatten-params --fail-on ERR"), io.Discard, io.Discard)) +} + +func Test_FlattenCmdOK(t *testing.T) { require.Zero(t, internal.Run(cmdToArgs("oasdiff flatten ../data/allof/simple.yaml"), io.Discard, io.Discard)) } -func Test_FlattenInvalid(t *testing.T) { +func Test_FlattenCmdInvalid(t *testing.T) { var stderr bytes.Buffer require.Equal(t, 102, internal.Run(cmdToArgs("oasdiff flatten ../data/allof/invalid.yaml"), io.Discard, &stderr)) require.Equal(t, `Error: failed to load original spec from "../data/allof/invalid.yaml" with unable to resolve Type conflict: all Type values must be identical