-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver_test.go
36 lines (32 loc) · 942 Bytes
/
server_test.go
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
package openapi_test
import (
"reflect"
"testing"
openapi "github.com/nasa9084/go-openapi"
yaml "gopkg.in/yaml.v2"
)
func TestServer_Validate(t *testing.T) {
candidates := []candidate{
{"empty", openapi.Server{}, openapi.ErrRequired{Target: "server.url"}},
{"invalidURL", openapi.Server{URL: "foobar%"}, openapi.ErrFormatInvalid{Target: "server.url", Format: "URL"}},
{"withURL", openapi.Server{URL: exampleCom}, nil},
}
testValidater(t, candidates)
}
func TestServerByExample(t *testing.T) {
spec := `url: https://development.gigantic-server.com/v1
description: Development server`
var server openapi.Server
if err := yaml.Unmarshal([]byte(spec), &server); err != nil {
t.Error(err)
return
}
expect := openapi.Server{
URL: "https://development.gigantic-server.com/v1",
Description: "Development server",
}
if !reflect.DeepEqual(server, expect) {
t.Errorf("%+v != %+v", server, expect)
return
}
}