forked from Jonathan-Rosenberg/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-new-request-non-path-parameter_test.go
49 lines (40 loc) · 1.67 KB
/
check-new-request-non-path-parameter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package checker_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/treeverse/oasdiff/checker"
"github.com/treeverse/oasdiff/diff"
)
// CL: new header, query and cookie request params
func TestNewRequestNonPathParameter_DetectsNewPathsAndNewOperations(t *testing.T) {
s1, err := open("../data/request_params/base.yaml")
require.NoError(t, err)
s2, err := open("../data/request_params/optional-request-params.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(&diff.Config{}, s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.NewRequestNonPathParameterCheck), d, osm, checker.INFO)
require.NotEmpty(t, errs)
require.Len(t, errs, 3)
require.IsType(t, checker.ApiChange{}, errs[0])
e0 := errs[0].(checker.ApiChange)
require.Equal(t, "new-optional-request-parameter", e0.Id)
require.Equal(t, "GET", e0.Operation)
require.Equal(t, "/api/test1", e0.Path)
require.Equal(t, checker.INFO, e0.Level)
require.Contains(t, e0.Text, "X-NewRequestHeaderParam")
require.IsType(t, checker.ApiChange{}, errs[1])
e1 := errs[1].(checker.ApiChange)
require.Equal(t, "new-optional-request-parameter", e1.Id)
require.Equal(t, "GET", e1.Operation)
require.Equal(t, "/api/test2", e1.Path)
require.Equal(t, checker.INFO, e1.Level)
require.Contains(t, e1.Text, "newQueryParam")
require.IsType(t, checker.ApiChange{}, errs[2])
e2 := errs[2].(checker.ApiChange)
require.Equal(t, "new-optional-request-parameter", e2.Id)
require.Equal(t, "GET", e2.Operation)
require.Equal(t, "/api/test3", e2.Path)
require.Equal(t, checker.INFO, e2.Level)
require.Contains(t, e2.Text, "csrf-token")
}