Exemple #1
0
func parTestGobler(t *testing.T, l *glick.Library, api, act, cmdPath string, useJSON bool, tisOut func() interface{}) {
	gobbler := fmt.Sprintf("%v", !useJSON)
	if err := l.Configure([]byte(`[
{"Plugin":"pie1","API":"` + api + `","Actions":["intStr1"],"Type":"PIE","Cmd":["` + cmdPath + `"],"Method":"CI.CopyIntX","Gob":` + gobbler + `}
		]`)); err != nil {
		t.Error(err)
	}
	par := test.IntStr{I: 42}
	if _, err := l.Run(nil, api, "intStr1", par); err != nil {
		t.Error("unable to run intStr1 for " + api + " err=" + err.Error())
	}
	if err := l.Configure([]byte(`[
{"Plugin":"pie2","API":"` + api + `","Actions":["intStr2"],"Type":"PIE"}
		]`)); err == nil {
		t.Error("unsuited end pie exe not spotted")
	}
	if err := l.Configure([]byte(`[
{"Plugin":"pie3","API":"` + api + `","Actions":["intStr1"],"Type":"PIE","Cmd":["illegal path"]}
		]`)); err == nil {
		t.Error("unsuited pie exe path not spotted")
	}
	if err := l.Configure([]byte(`[
{"Plugin":"pie4","API":"nothing here","Actions":["intStr1"],"Type":"PIE"}
		]`)); err == nil {
		t.Error("unsuited pie api not spotted")
	}
}
Exemple #2
0
// ConfigPIE provides the Configurator for the PIE class of plugin.
func ConfigPIE(lib *glick.Library) error {
	if lib == nil {
		return glick.ErrNilLib
	}
	return lib.AddConfigurator("PIE", func(l *glick.Library, line int, cfg *glick.Config) error {
		ppo, err := l.ProtoPlugOut(cfg.API)
		if err != nil {
			return fmt.Errorf("entry %d PIE register plugin error: %v",
				line, err) // no simple test possible for this path
		}
		pi := PluginPie(!cfg.Gob, cfg.Method, cfg.Cmd, ppo)
		for _, action := range cfg.Actions {
			if err := l.RegPlugin(cfg.API, action, pi, cfg); err != nil {
				return fmt.Errorf("entry %d PIE register plugin error: %v",
					line, err)
			}
		}
		return nil
	})
}
Exemple #3
0
func ConfigGRPChw(lib *glick.Library) error {
	return lib.AddConfigurator("gRPChw", func(l *glick.Library, line int, cfg *glick.Config) error {
		for _, action := range cfg.Actions {
			if err := l.RegPlugin(cfg.API, action,
				func(ctx context.Context, in interface{}) (out interface{}, err error) {
					ins, ok := in.(*pb.HelloRequest)
					if !ok {
						return nil, errors.New("not *pb.HelloRequest")
					}
					out = interface{}(&pb.HelloReply{})
					outsp := out.(*pb.HelloReply)
					dialOpt := []grpc.DialOption{grpc.WithInsecure()}
					if deadline, ok := ctx.Deadline(); ok {
						dialOpt = append(dialOpt,
							grpc.WithTimeout(deadline.Sub(time.Now())))
					}
					conn, err := grpc.Dial(address, dialOpt...)
					if err != nil {
						return nil, err
					}
					defer func() {
						if e := conn.Close(); e != nil {
							panic(e)
						}
					}()
					c := pb.NewGreeterClient(conn)

					r, err := c.SayHello(context.Background(), ins)
					if err != nil {
						return nil, err
					}
					*outsp = *r
					return out, nil
				}, cfg); err != nil {
				return fmt.Errorf("entry %d GRPChw register plugin error: %v",
					line, err)
			}
		}
		return nil
	})
}
Exemple #4
0
func parTest(t *testing.T, l *glick.Library, api, act, cmdPath string, useJSON bool, tisOut func() interface{}) {
	par := test.IntStr{I: 42}
	if ret, err := l.Run(nil, api, act, par); err != nil {
		t.Error("unable to run pie " + err.Error())
	} else {
		if ret.(*test.IntStr).I != 42 {
			t.Error("pie integer copy did not work")
		}
	}
	par.I = 4
	if _, err := l.Run(nil, api, act, par); err == nil {
		t.Error("over-long pie plugin did not timeout")
	}
	if err := l.RegPlugin(api, act+"bad",
		glpie.PluginPie(true, "CI.CopyIntX", []string{"./_test/bad/bad"}, tisOut), nil); err != nil {
		t.Error("unable to create " + err.Error())
	}
	par.I = 0
	if _, err := l.Run(nil, api, act+"bad", par); err == nil {
		t.Error("bad pie plugin did not error")
	}
	if err := l.RegPlugin(api, act+"badder",
		glpie.PluginPie(true, "CI.CopyIntX", []string{"./_test/bad/main.go"}, tisOut), nil); err != nil {
		t.Error("unable to create " + err.Error())
	}
	par.I = 0
	if _, err := l.Run(nil, api, act+"badder", par); err == nil {
		t.Error("non-runnable bad pie plugin did not error")
	}
	parTestGobler(t, l, api, act, cmdPath, useJSON, tisOut)
}