Skip to content

Commit

Permalink
emphasize common-params != path-params
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven committed Feb 4, 2024
1 parent 77637b1 commit 7be1fb6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 9 additions & 9 deletions diff/diff_common_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,41 @@ 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)
require.NoError(t, err)
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)
require.NoError(t, err)
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)
Expand Down
14 changes: 11 additions & 3 deletions internal/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7be1fb6

Please sign in to comment.