File: yaml_test.go

package info (click to toggle)
golang-github-go-openapi-swag 1%3A0.25.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,200 kB
  • sloc: sh: 30; makefile: 3
file content (40 lines) | stat: -rw-r--r-- 967 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
33
34
35
36
37
38
39
40
package loading

import (
	"net/http"
	"net/http/httptest"
	"testing"

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

func TestYAMLMatcher(t *testing.T) {
	t.Run("should recognize a yaml file", func(t *testing.T) {
		assert.True(t, YAMLMatcher("local.yml"))
		assert.True(t, YAMLMatcher("local.yaml"))
		assert.False(t, YAMLMatcher("local.json"))
	})
}

func TestYAMLDoc(t *testing.T) {
	t.Run("should retrieve pet store API as YAML", func(t *testing.T) {
		serv := httptest.NewServer(http.HandlerFunc(serveYAMLPestore))
		defer serv.Close()

		s, err := YAMLDoc(serv.URL)
		require.NoError(t, err)
		require.NotNil(t, s)
	})

	t.Run("should not retrieve any doc", func(t *testing.T) {
		ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
			rw.WriteHeader(http.StatusNotFound)
			_, _ = rw.Write([]byte("\n"))
		}))
		defer ts.Close()

		_, err := YAMLDoc(ts.URL)
		require.Error(t, err)
	})
}