...

Source file src/github.com/go-openapi/spec/info_test.go

Documentation: github.com/go-openapi/spec

     1  // Copyright 2015 go-swagger maintainers
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    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