...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package spec
16
17 import (
18 "encoding/json"
19 "testing"
20
21 "github.com/stretchr/testify/assert"
22 "github.com/stretchr/testify/require"
23 )
24
25 const infoJSON = `{
26 "description": "A sample API that uses a petstore as an example to demonstrate features in ` +
27 `the swagger-2.0 specification",
28 "title": "Swagger Sample API",
29 "termsOfService": "http://helloreverb.com/terms/",
30 "contact": {
31 "name": "wordnik api team",
32 "url": "http://developer.wordnik.com"
33 },
34 "license": {
35 "name": "Creative Commons 4.0 International",
36 "url": "http://creativecommons.org/licenses/by/4.0/"
37 },
38 "version": "1.0.9-abcd",
39 "x-framework": "go-swagger"
40 }`
41
42 var info = Info{
43 InfoProps: InfoProps{
44 Version: "1.0.9-abcd",
45 Title: "Swagger Sample API",
46 Description: "A sample API that uses a petstore as an example to demonstrate features in " +
47 "the swagger-2.0 specification",
48 TermsOfService: "http://helloreverb.com/terms/",
49 Contact: &ContactInfo{ContactInfoProps: ContactInfoProps{Name: "wordnik api team", URL: "http://developer.wordnik.com"}},
50 License: &License{LicenseProps: LicenseProps{
51 Name: "Creative Commons 4.0 International",
52 URL: "http://creativecommons.org/licenses/by/4.0/",
53 },
54 },
55 },
56 VendorExtensible: VendorExtensible{Extensions: map[string]interface{}{"x-framework": "go-swagger"}},
57 }
58
59 func TestIntegrationInfo_Serialize(t *testing.T) {
60 b, err := json.MarshalIndent(info, "", "\t")
61 require.NoError(t, err)
62 assert.Equal(t, infoJSON, string(b))
63 }
64
65 func TestIntegrationInfo_Deserialize(t *testing.T) {
66 actual := Info{}
67 require.NoError(t, json.Unmarshal([]byte(infoJSON), &actual))
68 assert.EqualValues(t, info, actual)
69 }
70
71 func TestInfoGobEncoding(t *testing.T) {
72 var src, dst Info
73 require.NoError(t, json.Unmarshal([]byte(infoJSON), &src))
74 assert.EqualValues(t, src, info)
75 doTestAnyGobEncoding(t, &src, &dst)
76 }
77
View as plain text