File: cache_test.go

package info (click to toggle)
golang-github-go-openapi-spec 1%3A0.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,748 kB
  • sloc: makefile: 5
file content (31 lines) | stat: -rw-r--r-- 676 bytes parent folder | download | duplicates (3)
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
package spec

import (
	"testing"

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

func TestDefaultResolutionCache(t *testing.T) {
	jsonSchema := MustLoadJSONSchemaDraft04()
	swaggerSchema := MustLoadSwagger20Schema()

	cache := defaultResolutionCache()

	sch, ok := cache.Get("not there")
	assert.False(t, ok)
	assert.Nil(t, sch)

	sch, ok = cache.Get("http://swagger.io/v2/schema.json")
	assert.True(t, ok)
	assert.Equal(t, swaggerSchema, sch)

	sch, ok = cache.Get("http://json-schema.org/draft-04/schema")
	assert.True(t, ok)
	assert.Equal(t, jsonSchema, sch)

	cache.Set("something", "here")
	sch, ok = cache.Get("something")
	assert.True(t, ok)
	assert.Equal(t, "here", sch)
}