-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathinfo_test.go
More file actions
64 lines (56 loc) · 1.89 KB
/
info_test.go
File metadata and controls
64 lines (56 loc) · 1.89 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0
package spec
import (
"encoding/json"
"testing"
"github.com/go-openapi/testify/v2/assert"
"github.com/go-openapi/testify/v2/require"
)
const infoJSON = `{
"description": "A sample API that uses a petstore as an example to demonstrate features in ` +
`the swagger-2.0 specification",
"title": "Swagger Sample API",
"termsOfService": "http://helloreverb.com/terms/",
"contact": {
"name": "wordnik api team",
"url": "http://developer.wordnik.com"
},
"license": {
"name": "Creative Commons 4.0 International",
"url": "http://creativecommons.org/licenses/by/4.0/"
},
"version": "1.0.9-abcd",
"x-framework": "go-swagger"
}`
var testInfo = Info{ //nolint:gochecknoglobals // test fixture
InfoProps: InfoProps{
Version: "1.0.9-abcd",
Title: "Swagger Sample API",
Description: "A sample API that uses a petstore as an example to demonstrate features in " +
"the swagger-2.0 specification",
TermsOfService: "http://helloreverb.com/terms/",
Contact: &ContactInfo{ContactInfoProps: ContactInfoProps{Name: "wordnik api team", URL: "http://developer.wordnik.com"}},
License: &License{
LicenseProps: LicenseProps{
Name: "Creative Commons 4.0 International",
URL: "http://creativecommons.org/licenses/by/4.0/",
},
},
},
VendorExtensible: VendorExtensible{Extensions: map[string]any{"x-framework": "go-swagger"}},
}
func TestInfo(t *testing.T) {
t.Run("should marshal Info", func(t *testing.T) {
assert.JSONMarshalAsT(t, infoJSON, testInfo)
})
t.Run("should unmarshal Info", func(t *testing.T) {
assert.JSONUnmarshalAsT(t, testInfo, infoJSON)
})
t.Run("should GobEncode Info", func(t *testing.T) {
var src, dst Info
require.NoError(t, json.Unmarshal([]byte(infoJSON), &src))
assert.Equal(t, src, testInfo)
doTestAnyGobEncoding(t, &src, &dst)
})
}