File: operation_test.go

package info (click to toggle)
golang-github-getkin-kin-openapi 0.1.0%2Bgit20181119.fa639d0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 480 kB
  • sloc: makefile: 2
file content (32 lines) | stat: -rw-r--r-- 908 bytes parent folder | download
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
package openapi3

import (
	"testing"

	"github.com/stretchr/testify/require"
)

var operation *Operation

func initOperation() {
	operation = NewOperation()
	operation.Description = "Some description"
	operation.Summary = "Some summary"
	operation.Tags = []string{"tag1", "tag2"}
}

func TestAddParameter(t *testing.T) {
	initOperation()
	operation.AddParameter(NewQueryParameter("param1"))
	operation.AddParameter(NewCookieParameter("param2"))
	require.Equal(t, "param1", operation.Parameters.GetByInAndName("query", "param1").Name)
	require.Equal(t, "param2", operation.Parameters.GetByInAndName("cookie", "param2").Name)
}

func TestAddResponse(t *testing.T) {
	initOperation()
	operation.AddResponse(200, NewResponse())
	operation.AddResponse(400, NewResponse())
	require.NotNil(t, "status 200", operation.Responses.Get(200).Value)
	require.NotNil(t, "status 400", operation.Responses.Get(400).Value)
}