summaryrefslogtreecommitdiff
path: root/vendor/github.com/varlink
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2019-02-05 11:51:41 +0100
committerValentin Rothberg <rothberg@redhat.com>2019-02-06 11:14:06 +0100
commit9ac0ebb0791851aea81ecc847802db5a39bfb6e7 (patch)
tree30ad98bcc2c2dd1136f46a48cbc44d422adfa184 /vendor/github.com/varlink
parent51714d5da7aaa19014fd67b48b79dfbd5f69c1f0 (diff)
downloadpodman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.tar.gz
podman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.tar.bz2
podman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.zip
Cirrus: add vendor_check_task
* Make sure that all vendored dependencies are in sync with the code and the vendor.conf by running `make vendor` with a follow-up status check of the git tree. * Vendor ginkgo and gomega to include the test dependencies. Signed-off-by: Chris Evic <cevich@redhat.com> Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/github.com/varlink')
-rw-r--r--vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/main.go45
-rw-r--r--vendor/github.com/varlink/go/cmd/varlink/main.go28
-rw-r--r--vendor/github.com/varlink/go/varlink/varlink_test.go52
3 files changed, 89 insertions, 36 deletions
diff --git a/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/main.go b/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/main.go
index 6be01f580..98a983c5e 100644
--- a/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/main.go
+++ b/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/main.go
@@ -109,6 +109,36 @@ func generateTemplate(description string) (string, []byte, error) {
b.WriteString("\n\n")
}
+ for _, a := range midl.Errors {
+ writeDocString(&b, a.Doc)
+ b.WriteString("type " + a.Name + " ")
+ writeType(&b, a.Type, true, 0)
+ b.WriteString("\nfunc (e " + a.Name + ") Error() string {\n")
+ b.WriteString("\treturn \"" + midl.Name + "." + a.Name + "\"\n")
+ b.WriteString("}\n\n")
+ }
+
+ b.WriteString("func Dispatch_Error(err error) error {\n")
+ b.WriteString("\tif e, ok := err.(*varlink.Error); ok {\n")
+ b.WriteString("\t\tswitch e.Name {\n")
+ for _, a := range midl.Errors {
+ b.WriteString("\t\tcase \"" + midl.Name + "." + a.Name + "\":\n")
+ b.WriteString("\t\t\terrorRawParameters := e.Parameters.(*json.RawMessage)\n")
+ b.WriteString("\t\t\tif errorRawParameters == nil {\n")
+ b.WriteString("\t\t\t\treturn e\n")
+ b.WriteString("\t\t\t}\n")
+ b.WriteString("\t\t\tvar param " + a.Name + "\n")
+ b.WriteString("\t\t\terr := json.Unmarshal(*errorRawParameters, &param)\n")
+ b.WriteString("\t\t\tif err != nil {\n")
+ b.WriteString("\t\t\t\treturn e\n")
+ b.WriteString("\t\t\t}\n")
+ b.WriteString("\t\t\treturn &param\n")
+ }
+ b.WriteString("\t\t}\n")
+ b.WriteString("\t}\n")
+ b.WriteString("\treturn err\n")
+ b.WriteString("}\n\n")
+
b.WriteString("// Generated client method calls\n\n")
for _, m := range midl.Methods {
@@ -175,9 +205,9 @@ func generateTemplate(description string) (string, []byte, error) {
} else {
b.WriteString("\treceive, err := c.Send(\"" + midl.Name + "." + m.Name + "\", nil, flags)\n")
}
- b.WriteString("if err != nil {\n" +
- "\treturn nil, err\n" +
- "}\n")
+ b.WriteString("\tif err != nil {\n" +
+ "\t\treturn nil, err\n" +
+ "\t}\n")
b.WriteString("\treturn func() (")
for _, field := range m.Out.Fields {
b.WriteString(field.Name + "_out_ ")
@@ -194,6 +224,7 @@ func generateTemplate(description string) (string, []byte, error) {
b.WriteString("\t\tflags, err = receive(nil)\n")
}
b.WriteString("\t\tif err != nil {\n" +
+ "\t\t\terr = Dispatch_Error(err)\n" +
"\t\t\treturn\n" +
"\t\t}\n")
for _, field := range m.Out.Fields {
@@ -242,10 +273,8 @@ func generateTemplate(description string) (string, []byte, error) {
writeType(&b, field.Type, false, 1)
}
b.WriteString(") error {\n")
+ b.WriteString("\tvar out " + e.Name + "\n")
if len(e.Type.Fields) > 0 {
- b.WriteString("\tvar out ")
- writeType(&b, e.Type, true, 1)
- b.WriteString("\n")
for _, field := range e.Type.Fields {
switch field.Type.Kind {
case idl.TypeStruct, idl.TypeArray, idl.TypeMap:
@@ -257,10 +286,8 @@ func generateTemplate(description string) (string, []byte, error) {
b.WriteString("\tout." + strings.Title(field.Name) + " = " + field.Name + "_\n")
}
}
- b.WriteString("\treturn c.ReplyError(\"" + midl.Name + "." + e.Name + "\", &out)\n")
- } else {
- b.WriteString("\treturn c.ReplyError(\"" + midl.Name + "." + e.Name + "\", nil)\n")
}
+ b.WriteString("\treturn c.ReplyError(\"" + midl.Name + "." + e.Name + "\", &out)\n")
b.WriteString("}\n\n")
}
diff --git a/vendor/github.com/varlink/go/cmd/varlink/main.go b/vendor/github.com/varlink/go/cmd/varlink/main.go
index 1de4e1a45..6781dd956 100644
--- a/vendor/github.com/varlink/go/cmd/varlink/main.go
+++ b/vendor/github.com/varlink/go/cmd/varlink/main.go
@@ -12,7 +12,7 @@ import (
)
var bold = color.New(color.Bold)
-var errorBoldRed = bold.Sprint(color.New(color.FgRed).Sprint("Error:"))
+var errorBoldRed string
var bridge string
func ErrPrintf(format string, a ...interface{}) {
@@ -71,7 +71,7 @@ func varlink_call(args []string) {
os.Exit(2)
}
address = "bridge:" + bridge
- methodName = callFlags.Arg(0)
+ methodName = callFlags.Arg(0)
} else {
uri := callFlags.Arg(0)
if uri == "" {
@@ -126,20 +126,18 @@ func varlink_call(args []string) {
f.NullColor = color.New(color.FgMagenta)
if err != nil {
- ErrPrintf("Error calling '%s': %v\n", methodName, err)
- switch e := err.(type) {
- case *varlink.Error:
- println(e.Name)
+ if e, ok := err.(*varlink.Error); ok {
+ ErrPrintf("Call failed with error: %v\n", color.New(color.FgRed).Sprint(e.Name))
errorRawParameters := e.Parameters.(*json.RawMessage)
-
- if errorRawParameters == nil {
- break
+ if errorRawParameters != nil {
+ var param map[string]interface{}
+ _ = json.Unmarshal(*errorRawParameters, &param)
+ c, _ := f.Marshal(param)
+ fmt.Fprintf(os.Stderr, "%v\n", string(c))
}
- var param map[string]interface{}
- _ = json.Unmarshal(*errorRawParameters, &param)
- c, _ := f.Marshal(param)
- ErrPrintf("%v\n", string(c))
+ os.Exit(2)
}
+ ErrPrintf("Error calling '%s': %v\n", methodName, err)
os.Exit(2)
}
c, _ := f.Marshal(retval)
@@ -173,7 +171,7 @@ func varlink_help(args []string) {
os.Exit(2)
}
address = "bridge:" + bridge
- interfaceName = helpFlags.Arg(0)
+ interfaceName = helpFlags.Arg(0)
} else {
uri := helpFlags.Arg(0)
if uri == "" && bridge == "" {
@@ -282,6 +280,8 @@ func main() {
color.NoColor = true // disables colorized output
}
+ errorBoldRed = bold.Sprint(color.New(color.FgRed).Sprint("Error:"))
+
switch flag.Arg(0) {
case "info":
varlink_info(flag.Args()[1:])
diff --git a/vendor/github.com/varlink/go/varlink/varlink_test.go b/vendor/github.com/varlink/go/varlink/varlink_test.go
index eb28c7e45..9dd4ddc63 100644
--- a/vendor/github.com/varlink/go/varlink/varlink_test.go
+++ b/vendor/github.com/varlink/go/varlink/varlink_test.go
@@ -27,27 +27,33 @@ func TestService(t *testing.T) {
)
t.Run("ZeroMessage", func(t *testing.T) {
+ var br bytes.Buffer
+ r := bufio.NewReader(&br)
var b bytes.Buffer
w := bufio.NewWriter(&b)
- if err := service.handleMessage(w, []byte{0}); err == nil {
+ if err := service.handleMessage(r, w, []byte{0}); err == nil {
t.Fatal("HandleMessage returned non-error")
}
})
t.Run("InvalidJson", func(t *testing.T) {
+ var br bytes.Buffer
+ r := bufio.NewReader(&br)
var b bytes.Buffer
w := bufio.NewWriter(&b)
msg := []byte(`{"method":"foo.GetInterfaceDescription" fdgdfg}`)
- if err := service.handleMessage(w, msg); err == nil {
+ if err := service.handleMessage(r, w, msg); err == nil {
t.Fatal("HandleMessage returned no error on invalid json")
}
})
t.Run("WrongInterface", func(t *testing.T) {
+ var br bytes.Buffer
+ r := bufio.NewReader(&br)
var b bytes.Buffer
w := bufio.NewWriter(&b)
msg := []byte(`{"method":"foo.GetInterfaceDescription"}`)
- if err := service.handleMessage(w, msg); err != nil {
+ if err := service.handleMessage(r, w, msg); err != nil {
t.Fatal("HandleMessage returned error on wrong interface")
}
expect(t, `{"parameters":{"interface":"foo"},"error":"org.varlink.service.InterfaceNotFound"}`+"\000",
@@ -55,10 +61,12 @@ func TestService(t *testing.T) {
})
t.Run("InvalidMethod", func(t *testing.T) {
+ var br bytes.Buffer
+ r := bufio.NewReader(&br)
var b bytes.Buffer
w := bufio.NewWriter(&b)
msg := []byte(`{"method":"InvalidMethod"}`)
- if err := service.handleMessage(w, msg); err != nil {
+ if err := service.handleMessage(r, w, msg); err != nil {
t.Fatal("HandleMessage returned error on invalid method")
}
expect(t, `{"parameters":{"parameter":"method"},"error":"org.varlink.service.InvalidParameter"}`+"\000",
@@ -66,10 +74,12 @@ func TestService(t *testing.T) {
})
t.Run("WrongMethod", func(t *testing.T) {
+ var br bytes.Buffer
+ r := bufio.NewReader(&br)
var b bytes.Buffer
w := bufio.NewWriter(&b)
msg := []byte(`{"method":"org.varlink.service.WrongMethod"}`)
- if err := service.handleMessage(w, msg); err != nil {
+ if err := service.handleMessage(r, w, msg); err != nil {
t.Fatal("HandleMessage returned error on wrong method")
}
expect(t, `{"parameters":{"method":"WrongMethod"},"error":"org.varlink.service.MethodNotFound"}`+"\000",
@@ -77,10 +87,12 @@ func TestService(t *testing.T) {
})
t.Run("GetInterfaceDescriptionNullParameters", func(t *testing.T) {
+ var br bytes.Buffer
+ r := bufio.NewReader(&br)
var b bytes.Buffer
w := bufio.NewWriter(&b)
msg := []byte(`{"method":"org.varlink.service.GetInterfaceDescription","parameters": null}`)
- if err := service.handleMessage(w, msg); err != nil {
+ if err := service.handleMessage(r, w, msg); err != nil {
t.Fatalf("HandleMessage returned error: %v", err)
}
expect(t, `{"parameters":{"parameter":"parameters"},"error":"org.varlink.service.InvalidParameter"}`+"\000",
@@ -88,10 +100,12 @@ func TestService(t *testing.T) {
})
t.Run("GetInterfaceDescriptionNoInterface", func(t *testing.T) {
+ var br bytes.Buffer
+ r := bufio.NewReader(&br)
var b bytes.Buffer
w := bufio.NewWriter(&b)
msg := []byte(`{"method":"org.varlink.service.GetInterfaceDescription","parameters":{}}`)
- if err := service.handleMessage(w, msg); err != nil {
+ if err := service.handleMessage(r, w, msg); err != nil {
t.Fatalf("HandleMessage returned error: %v", err)
}
expect(t, `{"parameters":{"parameter":"interface"},"error":"org.varlink.service.InvalidParameter"}`+"\000",
@@ -99,10 +113,12 @@ func TestService(t *testing.T) {
})
t.Run("GetInterfaceDescriptionWrongInterface", func(t *testing.T) {
+ var br bytes.Buffer
+ r := bufio.NewReader(&br)
var b bytes.Buffer
w := bufio.NewWriter(&b)
msg := []byte(`{"method":"org.varlink.service.GetInterfaceDescription","parameters":{"interface":"foo"}}`)
- if err := service.handleMessage(w, msg); err != nil {
+ if err := service.handleMessage(r, w, msg); err != nil {
t.Fatalf("HandleMessage returned error: %v", err)
}
expect(t, `{"parameters":{"parameter":"interface"},"error":"org.varlink.service.InvalidParameter"}`+"\000",
@@ -110,10 +126,12 @@ func TestService(t *testing.T) {
})
t.Run("GetInterfaceDescription", func(t *testing.T) {
+ var br bytes.Buffer
+ r := bufio.NewReader(&br)
var b bytes.Buffer
w := bufio.NewWriter(&b)
msg := []byte(`{"method":"org.varlink.service.GetInterfaceDescription","parameters":{"interface":"org.varlink.service"}}`)
- if err := service.handleMessage(w, msg); err != nil {
+ if err := service.handleMessage(r, w, msg); err != nil {
t.Fatalf("HandleMessage returned error: %v", err)
}
expect(t, `{"parameters":{"description":"# The Varlink Service Interface is provided by every varlink service. It\n# describes the service and the interfaces it implements.\ninterface org.varlink.service\n\n# Get a list of all the interfaces a service provides and information\n# about the implementation.\nmethod GetInfo() -\u003e (\n vendor: string,\n product: string,\n version: string,\n url: string,\n interfaces: []string\n)\n\n# Get the description of an interface that is implemented by this service.\nmethod GetInterfaceDescription(interface: string) -\u003e (description: string)\n\n# The requested interface was not found.\nerror InterfaceNotFound (interface: string)\n\n# The requested method was not found\nerror MethodNotFound (method: string)\n\n# The interface defines the requested method, but the service does not\n# implement it.\nerror MethodNotImplemented (method: string)\n\n# One of the passed parameters is invalid.\nerror InvalidParameter (parameter: string)"}}`+"\000",
@@ -121,10 +139,12 @@ func TestService(t *testing.T) {
})
t.Run("GetInfo", func(t *testing.T) {
+ var br bytes.Buffer
+ r := bufio.NewReader(&br)
var b bytes.Buffer
w := bufio.NewWriter(&b)
msg := []byte(`{"method":"org.varlink.service.GetInfo"}`)
- if err := service.handleMessage(w, msg); err != nil {
+ if err := service.handleMessage(r, w, msg); err != nil {
t.Fatalf("HandleMessage returned error: %v", err)
}
expect(t, `{"parameters":{"vendor":"Varlink","product":"Varlink Test","version":"1","url":"https://github.com/varlink/go/varlink","interfaces":["org.varlink.service"]}}`+"\000",
@@ -199,10 +219,12 @@ func TestMoreService(t *testing.T) {
}
t.Run("MethodNotImplemented", func(t *testing.T) {
+ var br bytes.Buffer
+ r := bufio.NewReader(&br)
var b bytes.Buffer
w := bufio.NewWriter(&b)
msg := []byte(`{"method":"org.example.test.Pingf"}`)
- if err := service.handleMessage(w, msg); err != nil {
+ if err := service.handleMessage(r, w, msg); err != nil {
t.Fatalf("HandleMessage returned error: %v", err)
}
expect(t, `{"parameters":{"method":"Pingf"},"error":"org.varlink.service.MethodNotImplemented"}`+"\000",
@@ -210,20 +232,24 @@ func TestMoreService(t *testing.T) {
})
t.Run("PingError", func(t *testing.T) {
+ var br bytes.Buffer
+ r := bufio.NewReader(&br)
var b bytes.Buffer
w := bufio.NewWriter(&b)
msg := []byte(`{"method":"org.example.test.PingError", "more" : true}`)
- if err := service.handleMessage(w, msg); err != nil {
+ if err := service.handleMessage(r, w, msg); err != nil {
t.Fatalf("HandleMessage returned error: %v", err)
}
expect(t, `{"error":"org.example.test.PingError"}`+"\000",
b.String())
})
t.Run("MoreTest", func(t *testing.T) {
+ var br bytes.Buffer
+ r := bufio.NewReader(&br)
var b bytes.Buffer
w := bufio.NewWriter(&b)
msg := []byte(`{"method":"org.example.test.Ping", "more" : true}`)
- if err := service.handleMessage(w, msg); err != nil {
+ if err := service.handleMessage(r, w, msg); err != nil {
t.Fatalf("HandleMessage returned error: %v", err)
}
expect(t, `{"continues":true}`+"\000"+`{"continues":true}`+"\000"+`{}`+"\000",