示例#1
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)
}
示例#2
0
func client(t *testing.T, useJSON bool, tisOut func() interface{}, endPt string) {

	l, nerr := glick.New(nil)
	if nerr != nil {
		t.Error(nerr)
	}

	api := "ab"
	act := "cdef"
	if err := l.RegAPI(api, test.IntStr{}, tisOut, 2*time.Second); err != nil {
		t.Error(err)
		return
	}

	if err := l.RegPlugin(api, act,
		glick.PluginRPC(useJSON, "CI.CopyIntX", endPt, tisOut), nil); err != nil {
		t.Error("unable to create JsonRPC " + err.Error())
		return
	}

	par := test.IntStr{I: 42}
	if ret, err := l.Run(nil, api, act, par); err != nil {
		t.Error("unable to run plugin " + err.Error())
	} else {
		if ret.(*test.IntStr).I != 42 {
			t.Error("RPC integer copy did not work")
		}
	}
	par.I = 4
	if _, err := l.Run(nil, api, act, par); err == nil {
		t.Error("over-long plugin did not timeout")
	}

	if err := l.RegPlugin(api, "bep",
		glick.PluginRPC(useJSON, "", "localhost:8080", tisOut), nil); err == nil {
		t.Error("able to create empty end-point method")
		return
	}

	if err := l.RegPlugin(api, "bep",
		glick.PluginRPC(useJSON, "CI.CopyIntX", "", tisOut), nil); err == nil {
		t.Error("able to create empty endpoint")
		return
	}
}