...
1 package operations
2
3 import (
4 "testing"
5
6 _ "github.com/go-openapi/analysis/internal/antest"
7 "github.com/go-openapi/spec"
8 "github.com/stretchr/testify/require"
9 )
10
11 var _ Provider = mockOperationsProvider{}
12
13 type mockOperationsProvider struct {
14 give map[string]map[string]*spec.Operation
15 }
16
17 func (m mockOperationsProvider) Operations() map[string]map[string]*spec.Operation {
18 return m.give
19 }
20
21 func TestGatherOperations(t *testing.T) {
22 t.Run("should handle empty operation IDs", func(_ *testing.T) {
23 m := mockOperationsProvider{
24 give: map[string]map[string]*spec.Operation{
25 "get": {
26 "/pth1": {
27 OperationProps: spec.OperationProps{
28 ID: "",
29 Description: "ok",
30 },
31 },
32 },
33 },
34 }
35
36 res := GatherOperations(m, nil)
37 require.Contains(t, res, "GetPth1")
38 })
39
40 t.Run("should handle duplicate operation IDs (when spec validation is skipped)", func(_ *testing.T) {
41 m := mockOperationsProvider{
42 give: map[string]map[string]*spec.Operation{
43 "get": {
44 "/pth1": {
45 OperationProps: spec.OperationProps{
46 ID: "id1",
47 Description: "ok",
48 },
49 },
50 },
51 "post": {
52 "/pth2": {
53 OperationProps: spec.OperationProps{
54 ID: "id1",
55 Description: "ok",
56 },
57 },
58 },
59 },
60 }
61
62 res := GatherOperations(m, nil)
63 require.Contains(t, res, "id1")
64 require.NotContains(t, res, "GetPth1")
65 require.Contains(t, res, "PostPth2")
66 })
67 }
68
View as plain text