Skip to content

Commit

Permalink
fix bug in operations diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven committed Dec 31, 2021
1 parent b634953 commit 60b383c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
10 changes: 10 additions & 0 deletions data/simple1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
info:
title: Tufin
version: 1.0.0
openapi: 3.0.3
paths:
/api/test:
get:
responses:
200:
description: OK
10 changes: 10 additions & 0 deletions data/simple2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
info:
title: Tufin
version: 1.0.0
openapi: 3.0.3
paths:
/api/test:
post:
responses:
200:
description: OK
20 changes: 20 additions & 0 deletions diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ func TestDiff_DeletedOperation(t *testing.T) {
"POST")
}

func TestDiff_ModifiedOperation(t *testing.T) {
loader := openapi3.NewLoader()

s1, err := loader.LoadFromFile("../data/simple1.yaml")
require.NoError(t, err)

s2, err := loader.LoadFromFile("../data/simple2.yaml")
require.NoError(t, err)

d, err := diff.Get(diff.NewConfig(), s2, s1)
require.NoError(t, err)

require.Equal(t, &diff.OperationsDiff{
Added: diff.StringList{"GET"},
Deleted: diff.StringList{"POST"},
Modified: diff.ModifiedOperations{},
},
d.PathsDiff.Modified["/api/test"].OperationsDiff)
}

func TestAddedExtension(t *testing.T) {
config := diff.Config{
IncludeExtensions: diff.StringSet{"x-extension-test": struct{}{}},
Expand Down
2 changes: 1 addition & 1 deletion diff/operations_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (operationsDiff *OperationsDiff) diffOperation(config *Config, operation1,
}

if operation1 != nil && operation2 == nil {
operationsDiff.Deleted = append(operationsDiff.Added, method)
operationsDiff.Deleted = append(operationsDiff.Deleted, method)
return nil
}

Expand Down

0 comments on commit 60b383c

Please sign in to comment.