vendor in latest github.com/varlink/go

Fixes: #888
Signed-off-by: Valentin Rothberg <vrothberg@suse.com>

Closes: #890
Approved by: rhatdan
This commit is contained in:
Valentin Rothberg 2018-06-04 14:47:20 +02:00 committed by Atomic Bot
parent 41a3f48f6d
commit 2ec1a645fa
7 changed files with 130 additions and 28 deletions

1
vendor/github.com/varlink/go/.gitignore generated vendored Normal file
View file

@ -0,0 +1 @@
/cmd/varlink-go-certification/orgvarlinkcertification/orgvarlinkcertification.go

23
vendor/github.com/varlink/go/.travis.yml generated vendored Normal file
View file

@ -0,0 +1,23 @@
language: go
sudo: false
go:
- '1.9'
- 1.10.x
install:
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
script:
- go generate ./...
- '"$HOME/gopath/bin/goveralls" -v -show -service=travis-ci -repotoken "$COVERALLS_TOKEN"'
env:
global:
- secure: bjxOSgBfB+YooxNTkIDHAD+/X6g56qBWoYpB1JinuS5kmt3vSjfRSuXui71sGuha7jO2FOJja8HcpjOv3UP+qmmej9276o5VWrjS1AwnI95hSQQ4JHm293Z1QeojjRaxmoKrgn7i82Hn4qNdVLQA142s+SIdqOxtN6LDs7i0Yb4IuXoiMQHbd6kAAL95o9IUFPpYAdsXoQ6xnx+TXNiSwPPeh4m5CNKuTtmGTuMGaj8tXxttFKJhZcRzvOpDuh7luc9PSVnQgYmKE/3S9ehzGV8Lk4T8eC7587DY1GdYQKt1egJSE72L+PVnmoalWROaAGHZvYWsSAeNi1UIvcFwGbXBRpq7kz3DVfIULM8V67UAaF3dGYDN3Ae825mDjN5JDfml17AoEjMjI0LlBImZLX2EWIEN225JIREHdpG9seJkaN1ClcpvEIeYuThF2MiivP1EE8/w8S80yoO5nW76Py/th16OuaEiP9LdLsbXimObUPsS9Sr8qquf/PiVqRMMpVW88oOEG5HVn4Ra5B/xVC6nPEF88tE6p9+7RSz4rOWih8QmW+6SX6eo0BI9di4L779f/WfUrddN0JLIvEnRFZZ+pVF/oo+N2INNeIMsZBvG3FVo+Zxzo6SExXnSSpuf1bp140ZdinUMACq6BqK+9gj1C9vNRmqQJaEefrqutws=
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/8cfd8d5fa3c31aa3d0c3
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: never # options: [always|never|change] default: always

7
vendor/github.com/varlink/go/Makefile generated vendored Normal file
View file

@ -0,0 +1,7 @@
all: cmd/varlink-go-certification/orgvarlinkcertification/orgvarlinkcertification.go
go test ./...
cmd/varlink-go-certification/orgvarlinkcertification/orgvarlinkcertification.go: cmd/varlink-go-certification/orgvarlinkcertification/org.varlink.certification.varlink
go generate cmd/varlink-go-certification/orgvarlinkcertification/generate.go
.PHONY: all

View file

@ -73,6 +73,16 @@ func writeType(b *bytes.Buffer, t *idl.Type, json bool, ident int) {
}
}
func writeDocString(b *bytes.Buffer, s string) {
if s == "" {
return
}
// Quote multi-line docstrings
b.WriteString("// " + strings.Replace(s, "\n", "\n// ", -1))
b.WriteString("\n")
}
func generateTemplate(description string) (string, []byte, error) {
description = strings.TrimRight(description, "\n")
@ -84,19 +94,25 @@ func generateTemplate(description string) (string, []byte, error) {
pkgname := strings.Replace(midl.Name, ".", "", -1)
var b bytes.Buffer
b.WriteString("// Generated with github.com/varlink/go/cmd/varlink-go-interface-generator\n")
b.WriteString("// Generated with github.com/varlink/go/cmd/varlink-go-interface-generator\n\n")
writeDocString(&b, midl.Doc)
b.WriteString("package " + pkgname + "\n\n")
b.WriteString("@IMPORTS@\n\n")
b.WriteString("// Type declarations\n")
b.WriteString("// Generated type declarations\n\n")
for _, a := range midl.Aliases {
writeDocString(&b, a.Doc)
b.WriteString("type " + a.Name + " ")
writeType(&b, a.Type, true, 0)
b.WriteString("\n\n")
}
b.WriteString("// Client method calls\n")
b.WriteString("// Generated client method calls\n\n")
for _, m := range midl.Methods {
writeDocString(&b, m.Doc)
b.WriteString("type " + m.Name + "_methods struct{}\n")
b.WriteString("func " + m.Name + "() " + m.Name + "_methods { return " + m.Name + "_methods{} }\n\n")
@ -196,7 +212,8 @@ func generateTemplate(description string) (string, []byte, error) {
b.WriteString("}\n\n")
}
b.WriteString("// Service interface with all methods\n")
b.WriteString("// Generated service interface with all methods\n\n")
b.WriteString("type " + pkgname + "Interface interface {\n")
for _, m := range midl.Methods {
b.WriteString("\t" + m.Name + "(c VarlinkCall")
@ -208,11 +225,14 @@ func generateTemplate(description string) (string, []byte, error) {
}
b.WriteString("}\n\n")
b.WriteString("// Service object with all methods\n")
b.WriteString("// Generated service object with all methods\n\n")
b.WriteString("type VarlinkCall struct{ varlink.Call }\n\n")
b.WriteString("// Reply methods for all varlink errors\n")
b.WriteString("// Generated reply methods for all varlink errors\n\n")
for _, e := range midl.Errors {
writeDocString(&b, e.Doc)
b.WriteString("func (c *VarlinkCall) Reply" + e.Name + "(")
for i, field := range e.Type.Fields {
if i > 0 {
@ -244,7 +264,8 @@ func generateTemplate(description string) (string, []byte, error) {
b.WriteString("}\n\n")
}
b.WriteString("// Reply methods for all varlink methods\n")
b.WriteString("// Generated reply methods for all varlink methods\n\n")
for _, m := range midl.Methods {
b.WriteString("func (c *VarlinkCall) Reply" + m.Name + "(")
for i, field := range m.Out.Fields {
@ -277,8 +298,10 @@ func generateTemplate(description string) (string, []byte, error) {
b.WriteString("}\n\n")
}
b.WriteString("// Dummy implementations for all varlink methods\n")
b.WriteString("// Generated dummy implementations for all varlink methods\n\n")
for _, m := range midl.Methods {
writeDocString(&b, m.Doc)
b.WriteString("func (s *VarlinkInterface) " + m.Name + "(c VarlinkCall")
for _, field := range m.In.Fields {
b.WriteString(", " + field.Name + "_ ")
@ -289,7 +312,8 @@ func generateTemplate(description string) (string, []byte, error) {
"}\n\n")
}
b.WriteString("// Method call dispatcher\n")
b.WriteString("// Generated method call dispatcher\n\n")
b.WriteString("func (s *VarlinkInterface) VarlinkDispatch(call varlink.Call, methodname string) error {\n" +
"\tswitch methodname {\n")
for _, m := range midl.Methods {
@ -327,15 +351,19 @@ func generateTemplate(description string) (string, []byte, error) {
"\t}\n" +
"}\n\n")
b.WriteString("// Varlink interface name\n")
b.WriteString("// Generated varlink interface name\n\n")
b.WriteString("func (s *VarlinkInterface) VarlinkGetName() string {\n" +
"\treturn `" + midl.Name + "`\n" + "}\n\n")
b.WriteString("// Varlink interface description\n")
b.WriteString("func (s *VarlinkInterface) VarlinkGetDescription() string {\n" +
"\treturn `" + midl.Description + "\n`\n}\n\n")
b.WriteString("// Generated varlink interface description\n\n")
// Special-quote backtick, it cannot be part of a backtick-quoted string
b.WriteString("func (s *VarlinkInterface) VarlinkGetDescription() string {\n" +
"\treturn `" + strings.Replace(midl.Description, "`", "` + \"`\" + `", -1) + "\n`\n}\n\n")
b.WriteString("// Generated service interface\n\n")
b.WriteString("// Service interface\n")
b.WriteString("type VarlinkInterface struct {\n" +
"\t" + pkgname + "Interface\n" +
"}\n\n")

View file

@ -110,6 +110,36 @@ func TestUnix(t *testing.T) {
}
}
func TestInvalidAddress(t *testing.T) {
newTestInterface := new(VarlinkInterface)
service, err := varlink.NewService(
"Varlink",
"Varlink Test",
"1",
"https://github.com/varlink/go/varlink",
)
if err != nil {
t.Fatalf("NewService(): %v", err)
}
if err = service.RegisterInterface(newTestInterface); err != nil {
t.Fatalf("RegisterInterface(): %v", err)
}
if err = service.Listen("foo", 0); err == nil {
t.Fatalf("service.Listen() should error")
}
if err = service.Listen("", 0); err == nil {
t.Fatalf("service.Listen() should error")
}
if err = service.Listen("unix", 0); err == nil {
t.Fatalf("service.Listen() should error")
}
}
func TestAnonUnix(t *testing.T) {
if runtime.GOOS != "linux" {
return

View file

@ -69,9 +69,9 @@ type IDL struct {
Doc string
Description string
Members []interface{}
Aliases map[string]*Alias
Methods map[string]*Method
Errors map[string]*Error
Aliases []*Alias
Methods []*Method
Errors []*Error
}
type parser struct {
@ -413,9 +413,9 @@ func (p *parser) readIDL() (*IDL, error) {
idl := &IDL{
Members: make([]interface{}, 0),
Aliases: make(map[string]*Alias),
Methods: make(map[string]*Method),
Errors: make(map[string]*Error),
Aliases: make([]*Alias, 0),
Methods: make([]*Method, 0),
Errors: make([]*Error, 0),
}
p.advance()
@ -425,6 +425,9 @@ func (p *parser) readIDL() (*IDL, error) {
return nil, fmt.Errorf("interface name")
}
// Check for duplicates
members := make(map[string]struct{}, 0)
for {
if !p.advance() {
break
@ -436,30 +439,36 @@ func (p *parser) readIDL() (*IDL, error) {
if err != nil {
return nil, err
}
if _, ok := members[a.Name]; ok {
return nil, fmt.Errorf("type `%s` already defined", a.Name)
}
members[a.Name] = struct{}{}
idl.Aliases = append(idl.Aliases, a)
idl.Members = append(idl.Members, a)
idl.Aliases[a.Name] = a
case "method":
m, err := p.readMethod(idl)
if err != nil {
return nil, err
}
idl.Members = append(idl.Members, m)
if _, ok := idl.Methods[m.Name]; ok {
if _, ok := members[m.Name]; ok {
return nil, fmt.Errorf("method `%s` already defined", m.Name)
}
idl.Methods[m.Name] = m
members[m.Name] = struct{}{}
idl.Methods = append(idl.Methods, m)
idl.Members = append(idl.Members, m)
case "error":
e, err := p.readError(idl)
if err != nil {
return nil, err
}
if _, ok := members[e.Name]; ok {
return nil, fmt.Errorf("error `%s` already defined", e.Name)
}
members[e.Name] = struct{}{}
idl.Errors = append(idl.Errors, e)
idl.Members = append(idl.Members, e)
idl.Errors[e.Name] = e
default:
return nil, fmt.Errorf("unknown keyword '%s'", keyword)

View file

@ -198,6 +198,10 @@ func (s *Service) teardown() {
func (s *Service) parseAddress(address string) error {
words := strings.SplitN(address, ":", 2)
if len(words) != 2 {
return fmt.Errorf("Unknown protocol")
}
s.protocol = words[0]
s.address = words[1]