Beispiel #1
0
func TestMatch(t *testing.T) {
	sb := NewSrvSessionBuilder("", "/", "rtest", 2000, 500)
	mux := NewSessionMux("", sb)
	mux.HandleFuncM("^/a1.*$", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("OK\n"))
	}, "POST", true)
	mux.HandleFuncM("^/a2.*$", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("OK\n"))
	}, "*", true)
	mux.HandlerM("^/a3.*$", &rhtp{}, "*", true)
	mux.HFilterFuncM("^/a4.*$", func(hs *HTTPSession) HResult {
		return HRES_RETURN
	}, "POST")
	mux.HFilterFuncM("^/a5.*$", func(hs *HTTPSession) HResult { //test check m
		hs.Mux.check_continue(regexp.MustCompile(".*"))
		hs.Mux.check_m(regexp.MustCompile(".*"), "*")
		return HRES_RETURN
	}, "*")
	ts := httptest.NewServer(mux)
	util.HGet("%v/a1", ts.URL)
	util.HGet("%v/a2", ts.URL)
	util.HGet("%v/a3", ts.URL)
	util.HGet("%v/a4", ts.URL)
	util.HGet("%v/a5", ts.URL)
}
Beispiel #2
0
func TestSessionMux2(t *testing.T) {
	sb := NewSrvSessionBuilder("", "/", "rtest2", 2000, 500)
	sb.ShowLog = true
	mux := NewSessionMux("/t", sb)
	mux.ShowLog = true
	mux.HFunc("^/a$", func(hs *HTTPSession) HResult {
		return hs.MsgRes("aaaa")
	})
	mux.HFunc("^/b$", func(hs *HTTPSession) HResult {
		return hs.MsgRes2(200, "bbbb")
	})
	mux.HFunc("^/c$", func(hs *HTTPSession) HResult {
		return hs.MsgResE(1, "cccc")
	})
	mux.HFunc("^/c2$", func(hs *HTTPSession) HResult {
		fmt.Println("------->")
		err := hs.JsonRes(func() {})
		if err == nil {
			t.Error("not error")
		}
		return HRES_RETURN
	})
	mux.HFunc("^/c3$", func(hs *HTTPSession) HResult {
		return hs.MsgResE(1, "cccc")
	})
	mux.HFunc("^/c4$", func(hs *HTTPSession) HResult {
		return hs.MsgResErr2(1, "cccc", errors.New("text"))
	})
	mux.HFunc("^/c5$", func(hs *HTTPSession) HResult {
		return hs.MsgResE2(1, "cccc", "text")
	})
	mux.HFunc("^/c6$", func(hs *HTTPSession) HResult {
		return hs.MsgResErr(1, "cccc", errors.New("text"))
	})
	mux.HFunc("^/c7$", func(hs *HTTPSession) HResult {
		return hs.MsgResE3(1, "cccc", "text")
	})
	mux.HFunc("^/d$", func(hs *HTTPSession) HResult {
		hs.SendT("abc", "text/plain;charset=utf-8")
		return HRES_RETURN
	})
	ts := httptest.NewServer(mux)
	fmt.Println(util.HGet("%s/t/a", ts.URL))
	fmt.Println(util.HGet("%s/t/b", ts.URL))
	fmt.Println(util.HGet("%s/t/c", ts.URL))
	fmt.Println(util.HGet("%s/t/c2", ts.URL))
	fmt.Println(util.HGet("%s/t/c3", ts.URL))
	fmt.Println(util.HGet("%s/t/c4", ts.URL))
	fmt.Println(util.HGet("%s/t/c5", ts.URL))
	fmt.Println(util.HGet("%s/t/c6", ts.URL))
	fmt.Println(util.HGet("%s/t/c7", ts.URL))
	fmt.Println(util.HGet("%s/t/d", ts.URL))
}
Beispiel #3
0
func TestSendFErr(t *testing.T) {
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		SendF(w, r, "kkk", "/tmp", "", false)
		sendf(w, nil, "", "", false)
		fmt.Println("SendF")
	}))
	util.HGet("%v?", ts.URL)
}
Beispiel #4
0
func TestNoCache(t *testing.T) {
	mux := routing.NewSessionMux2("")
	mux.HFilterFunc("^.*$", NoCacheFilter)
	mux.HFunc("^.*$", func(hs *routing.HTTPSession) routing.HResult {
		return routing.HRES_RETURN
	})
	ts := httptest.NewServer(mux)
	util.HGet("%v", ts.URL)
}
Beispiel #5
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))
}
Beispiel #6
0
func TestMain2(t *testing.T) {
	os.Mkdir("out", os.ModePerm)
	os.Args = []string{"jcr", "start", "-p", ":8798", "-n", "jjj"}
	go Run()
	time.Sleep(200)
	StopSrv()
	time.Sleep(100)
	//
	os.Args = []string{
		"jcr", "start",
		"-f", "jcr.json",
	}
	go Run()
	url := "http://localhost:8799"
	fmt.Println(util.HGet("%s/jcr/conf", url))
	fmt.Println(util.HGet("%s/jcr/jcr.js", url))
	fmt.Println(util.HGet("%s/jcr/store", url))
	fmt.Println(util.HGet("%s/jcr/store?cover=%s", url, "sssssss"))
	StopSrv()
}
Beispiel #7
0
func TestJcr(t *testing.T) {
	// StartSrv("abcc")
	StartSrv("coverage_jcr", "out", "jsss")
	go RunSrv("coverage_jcr", "out", ":8799")
	url := "http://localhost:8799"
	fmt.Println(util.HGet("%s/jcr/conf", url))
	fmt.Println(util.HGet("%s/jcr/jcr.js", url))
	fmt.Println(util.HGet("%s/jcr/store", url))
	fmt.Println(util.HGet("%s/jcr/store?cover=%s", url, "sssssss"))
	_conf_.Dir = "/tjjks"
	fmt.Println(util.HGet("%s/jcr/store?cover=%s", url, "sssssss"))
	_conf_.Dir = "out"
	fmt.Println(util.HGet("%s/jcr/exit", url))
	StopSrv()
	os.Remove("JCR_000.json")
}
Beispiel #8
0
func Tnh2(h http.Handler, f string, args ...interface{}) (string, error) {
	ts := httptest.NewServer(h)
	return util.HGet(fmt.Sprintf("%v%v", ts.URL, f), args...)
}
Beispiel #9
0
func (s *Server) G(f string, args ...interface{}) (string, error) {
	return util.HGet(fmt.Sprintf("%v%v", s.URL, f), args...)
}