Exemplo n.º 1
0
func TestIgE(t *testing.T) {
	inf := "/tmp/kkk.json"
	outf := "/tmp/aaa.json"
	os.Remove(inf)
	os.Remove(outf)
	b := NewBuilder(inf, outf)
	//
	fmt.Println(b.Exec())
	//
	util.FWrite(inf, "kkk")
	fmt.Println(b.Exec())
	os.Remove(inf)
	//
	//
	util.FWrite(inf, "{\"abc\":111}")
	fmt.Println(b.Exec())
	os.Remove(outf)
	//
	//
	b.Out = "/lkkkk"
	fmt.Println(b.Exec())
	//
	b.In = ""
	b.Dset = nil
	fmt.Println(b.Exec())
}
Exemplo n.º 2
0
func TestHr(t *testing.T) {
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		fmt.Println(r.FormValue("a"))
		fmt.Println(r.FormValue("b"))
		fmt.Println(r.Header.Get("kk"))
		fmt.Println(r.FormFile("file"))
		w.Write([]byte("OKK"))
	}))
	ts2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(
			`
			{"abc":11}
			`))

	}))
	ctx := NewCtx(nil)
	ctx.HG(ts.URL, "a=1", "b=2", "^kk=11", "#code=aa", "#data=bb", "#err=cc")
	ctx.P("$aa", "$bb", "$cc")
	util.FWrite("/tmp/11122.txt", "testing")
	defer os.Remove("/tmp/11122.txt")
	ctx.HP(ts.URL, "a=2", "b=3", "^kk=kkk", "%file=/tmp/11122.txt", "#code=aa", "#data=bb", "#err=cc")
	ctx.P("$aa", "$bb", "$cc")
	ctx.HP("kkk", "a=2", "b=3", "^kk=kkk", "%file=/tmp/11122.txt", "#code=aa", "#data=bb", "#err=cc")
	ctx.HP(ts.URL, "a=2", "b=3", "^kk", "#code=aa", "#data=bb", "#err=cc")
	ctx.HP()
	ctx.HR("MM", "kkkk")
	ctx.HP(ts2.URL, "a=2", "b=3", "^kk", "#code=aa", "#data=bb", "#err=cc")
}
Exemplo n.º 3
0
func main() {
	if len(os.Args) < 2 {
		Usage()
		return
	}
	fs := []string{}
	of := ""
	alen := len(os.Args)
	for i := 1; i < alen; i++ {
		switch os.Args[i] {
		case "-o":
			if i < alen-1 {
				of = os.Args[i+1]
				i++
			} else {
				fmt.Println("not file for -o")
				Usage()
				return
			}
		case "-h":
			Usage()
			return
		default:
			fs = append(fs, os.Args[i])
		}
	}
	if len(of) < 1 {
		fmt.Println("not out file")
		Usage()
		return
	}
	var out coverage_
	for _, f := range fs {
		bys, err := ioutil.ReadFile(f)
		if err != nil {
			fmt.Println(err.Error())
			return
		}
		var in coverage_
		err = xml.Unmarshal(bys, &in)
		if err != nil {
			fmt.Println(err.Error())
			return
		}
		out.Append(in)
	}
	bys, _ := xml.Marshal(out)
	err := util.FWrite(of, string(bys))
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println(fmt.Sprintf("create cobertura file to %s by %d file", of, len(fs)))
}
Exemplo n.º 4
0
func TestRecf(t *testing.T) {
	sb := NewSrvSessionBuilder("", "/", "rtest", 2000, 500)
	mux := NewSessionMux("", sb)
	mux.HFunc("^/t1.*$", RecF)
	mux.HFunc("^/t2.*$", RecF2)
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		mux.ServeHTTP(w, r)
	}))
	defer ts.Close()
	util.FWrite("/tmp/test.txt", "testing")
	fmt.Println(util.HPostF(fmt.Sprintf("%v/t1", ts.URL), nil, "file", "/tmp/test.txt"))
	fmt.Println(util.HPostF(fmt.Sprintf("%v/t1", ts.URL), nil, "file2", "/tmp/test.txt"))
	fmt.Println(util.HPostF(fmt.Sprintf("%v/t2", ts.URL), nil, "file", "/tmp/test.txt"))
	fmt.Println(util.HPostF(fmt.Sprintf("%v/t1", ts.URL), nil, "file", "/tmp/test.txt2"))
}
Exemplo n.º 5
0
Arquivo: jcr.go Projeto: Centny/Cny4go
func JcrStore(hs *routing.HTTPSession) routing.HResult {
	var cover string
	err := hs.ValidRVal(`
		cover,R|S,L:0
		`, &cover)
	if err != nil {
		return hs.MsgResE(1, err.Error())
	}
	spath := _conf_.SavePath()
	log.D("saving coverage report to %s", spath)
	err = util.FWrite(spath, cover)
	if err != nil {
		log.E("saving coverage report to %s error:%s", spath, err.Error())
		return hs.MsgResE(1, err.Error())
	} else {
		return hs.MsgRes("SUCCESS")
	}
}
Exemplo n.º 6
0
func TestSendF(t *testing.T) {
	sb := NewSrvSessionBuilder("", "/", "rtest", 2000, 500)
	mux := NewSessionMux("", sb)
	mux.HFunc("^/t1.*$", SendF1)
	mux.HFunc("^/t2.*$", SendF2)
	mux.HFunc("^/t3.*$", SendF3)
	mux.HFunc("^/t4.*$", SendF4)
	mux.HFunc("^/t5.*$", SendF5)
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		mux.ServeHTTP(w, r)
	}))
	defer ts.Close()
	util.FWrite("/tmp/test.txt", "testing")
	fmt.Println(util.HGet("%s/t1", ts.URL))
	fmt.Println(util.HGet("%s/t2", ts.URL))
	fmt.Println(util.HGet("%s/t3", ts.URL))
	fmt.Println(util.HGet("%s/t4", ts.URL))
	fmt.Println(util.HGet("%s/t5", ts.URL))
}