Esempio n. 1
0
func TestMatchQueryToNamespaces(t *testing.T) {
	Convey("RPC client errors", t, func() {
		input := core.NewNamespace("testing", "this")

		proxy := ControlProxy{Client: mockClient{RpcErr: true}}
		ns, err := proxy.ExpandWildcards(input)

		Convey("So the error should be passed through", func() {
			So(err.Error(), ShouldResemble, rpcErr.Error())
		})
		Convey("So The namespace ShouldBeNil", func() {
			So(ns, ShouldBeNil)
		})
	})

	Convey("call to Control.MatchQueryToNamespaces returns error", t, func() {
		input := core.NewNamespace("testing", "this")
		reply := &rpc.ExpandWildcardsReply{
			Error: &common.SnapError{
				ErrorFields: map[string]string{},
				ErrorString: "Error from control",
			},
		}

		proxy := ControlProxy{Client: mockClient{MatchReply: reply}}
		ns, err := proxy.MatchQueryToNamespaces(input)

		Convey("So the err should be: "+reply.Error.ErrorString, func() {
			So(err.Error(), ShouldResemble, common.ToSnapError(reply.Error).Error())
		})
		Convey("So Namespaces should be nil", func() {
			So(ns, ShouldBeNil)
		})
	})

	Convey("Control.MatchQueryToNamespaces returns successfully", t, func() {
		input := core.NewNamespace("testing", "this")
		a := core.NewNamespace("testing", "this")
		b := core.NewNamespace("stuff", "more")
		proto_a := &rpc.ArrString{S: common.ToNamespace(a)}
		proto_b := &rpc.ArrString{S: common.ToNamespace(b)}
		reply := &rpc.ExpandWildcardsReply{
			Error: nil,
			NSS:   []*rpc.ArrString{proto_a, proto_b},
		}

		proxy := ControlProxy{Client: mockClient{MatchReply: reply}}
		ns, err := proxy.MatchQueryToNamespaces(input)

		Convey("so the err Should be nil", func() {
			So(err, ShouldBeNil)
		})
		Convey("So namespaces should resemble:"+a.String()+","+b.String(), func() {
			So(ns, ShouldResemble, []core.Namespace{a, b})
		})

	})

}
Esempio n. 2
0
func (c ControlProxy) ExpandWildcards(namespace core.Namespace) ([]core.Namespace, serror.SnapError) {
	req := &rpc.ExpandWildcardsRequest{
		Namespace: common.ToNamespace(namespace),
	}
	reply, err := c.Client.ExpandWildcards(getContext(), req)
	if err != nil {
		return nil, serror.New(err)
	}
	if reply.Error != nil {
		return nil, common.ToSnapError(reply.Error)
	}
	nss := toNSS(reply.NSS)
	return nss, nil
}