proxy_test: Add a helper method to call without fd

To verify in one place.

Signed-off-by: Colin Walters <walters@verbum.org>
This commit is contained in:
Colin Walters 2021-11-08 09:34:49 -05:00
parent 644074cbb4
commit f90725d80c

View File

@ -118,6 +118,19 @@ func (self *proxy) call(method string, args []interface{}) (rval interface{}, fd
return
}
func (self *proxy) callNoFd(method string, args []interface{}) (rval interface{}, err error) {
var fd *pipefd
rval, fd, err = self.call(method, args)
if err != nil {
return
}
if fd != nil {
err = fmt.Errorf("Unexpected fd from method %s", method)
return
}
return rval, nil
}
func newProxy() (*proxy, error) {
fds, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_SEQPACKET, 0)
if err != nil {
@ -149,13 +162,10 @@ func newProxy() (*proxy, error) {
c: mysock.(*net.UnixConn),
}
v, fd, err := p.call("Initialize", nil)
v, err := p.callNoFd("Initialize", nil)
if err != nil {
return nil, err
}
if fd != nil {
return nil, fmt.Errorf("proxy Initialize: Unexpected fd")
}
semver, ok := v.(string)
if !ok {
return nil, fmt.Errorf("proxy Initialize: Unexpected value %T", v)
@ -179,33 +189,16 @@ func (s *ProxySuite) SetUpSuite(c *check.C) {
func (s *ProxySuite) TearDownSuite(c *check.C) {
}
func initOci(p string) error {
err := ioutil.WriteFile(filepath.Join(p, "oci-layout"), []byte("{\"imageLayoutVersion\":\"1.0.0\"}"), 0644)
if err != nil {
return err
}
blobdir := filepath.Join(p, "blobs/sha256")
err = os.MkdirAll(blobdir, 0755)
if err != nil {
return err
}
return nil
}
type byteFetch struct {
content []byte
err error
}
func runTestGetManifest(p *proxy, img string) error {
v, fd, err := p.call("OpenImage", []interface{}{knownNotManifestListedImage_x8664})
v, err := p.callNoFd("OpenImage", []interface{}{knownNotManifestListedImage_x8664})
if err != nil {
return err
}
if fd != nil {
return fmt.Errorf("Unexpected fd")
}
imgidv, ok := v.(float64)
if !ok {
@ -213,7 +206,7 @@ func runTestGetManifest(p *proxy, img string) error {
}
imgid := uint32(imgidv)
v, fd, err = p.call("GetManifest", []interface{}{imgid})
v, fd, err := p.call("GetManifest", []interface{}{imgid})
if err != nil {
return err
}